[
https://issues.apache.org/jira/browse/PDFBOX-6085?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18031994#comment-18031994
]
Constantine Dokolas edited comment on PDFBOX-6085 at 10/22/25 8:32 AM:
-----------------------------------------------------------------------
Here is the sample code:
{code:java}
private static final String PATH_TO_FONT = "NotoSansDevanagari-Regular.ttf";
private static void doSample() throws IOException {
PDDocument doc = new PDDocument();
PDType0Font font = getFont(doc);
PDPage page = new PDPage(new PDRectangle(720, 144));
doc.addPage(page);
// int[] codepoints = "abcdefg".codePoints().toArray();
int[] codepoints = getDevanagariCPs();
try (PDPageContentStream pcs = new PDPageContentStream(doc, page)) {
pcs.beginText();
pcs.newLineAtOffset(72, 72);
pcs.setFont(font, 14);
pcs.showText(new String(codepoints, 0, codepoints.length));
pcs.endText();
}
doc.save("cantwrite.pdf");
}
private static PDType0Font getFont(PDDocument doc) throws IOException {
TTFParser tp = new TTFParser();
try (InputStream is = new FileInputStream(PATH_TO_FONT)) {
TrueTypeFont tff = tp.parseEmbedded(is);
PDType0Font font = PDType0Font.load(doc, tff, true);
return font;
}
}
private static int[] getDevanagariCPs() {
return new int[]{
2305, 2306, 2309, 2310, 2311, 2312, 2313, 2315, 2319, 2324, 2325,
2326, 2327, 2328, 2329, 2330, 2331, 2332,
2333, 2335, 2336, 2337, 2339, 2340, 2341, 2342, 2343, 2344, 2346,
2348, 2349, 2350, 2351, 2352, 2354, 2355,
2357, 2358, 2359, 2360, 2361, 2364, 2366, 2367, 2368, 2369, 2370,
2375, 2376, 2379, 2380, 2381, 2396, 2404,
2406, 2407, 2408, 2409, 2410, 2411, 2414, 8204,
};
}
{code}
Note: This code is not well written (e.g. I've not closed the {{PDDocument}}),
but reproduces the issue.
was (Author: cdokolas):
Here is the sample code:
{code:java}
private static final String PATH_TO_FONT = "NotoSansDevanagari-Regular.ttf";
private static void doSample() throws IOException {
PDDocument doc = new PDDocument();
PDType0Font font = getFont(doc);
PDPage page = new PDPage(new PDRectangle(720, 144));
doc.addPage(page);
// int[] codepoints = "abcdefg".codePoints().toArray();
int[] codepoints = getDevanagariCPs();
try (PDPageContentStream pcs = new PDPageContentStream(doc, page)) {
pcs.beginText();
pcs.newLineAtOffset(72, 72);
pcs.setFont(font, 14);
pcs.showText(new String(codepoints, 0, codepoints.length));
pcs.endText();
}
doc.save("cantwrite.pdf");
}
private static PDType0Font getFont(PDDocument doc) throws IOException {
TTFParser tp = new TTFParser();
try (InputStream is = new FileInputStream(PATH_TO_FONT)) {
TrueTypeFont tff = tp.parseEmbedded(is);
PDType0Font font = PDType0Font.load(doc, tff, true);
return font;
}
}
private static int[] getDevanagariCPs() {
return new int[]{
2305, 2306, 2309, 2310, 2311, 2312, 2313, 2315, 2319, 2324, 2325,
2326, 2327, 2328, 2329, 2330, 2331, 2332,
2333, 2335, 2336, 2337, 2339, 2340, 2341, 2342, 2343, 2344, 2346,
2348, 2349, 2350, 2351, 2352, 2354, 2355,
2357, 2358, 2359, 2360, 2361, 2364, 2366, 2367, 2368, 2369, 2370,
2375, 2376, 2379, 2380, 2381, 2396, 2404,
2406, 2407, 2408, 2409, 2410, 2411, 2414, 8204,
};
}
{code}
> TTFSubsetter.buildGlyfTable() modifies glyphIds while iterating over its
> entries possibly causing ConcurrentModificationException to be thrown
> ----------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: PDFBOX-6085
> URL: https://issues.apache.org/jira/browse/PDFBOX-6085
> Project: PDFBox
> Issue Type: Bug
> Affects Versions: 2.0.35, 3.0.6 PDFBox
> Reporter: Constantine Dokolas
> Priority: Major
>
> Modifying a {{TreeSet}} while iterating over its members is prohibited as it
> may throw a {{ConcurrentModificationException}} if the set is actually
> modified.
> This can be observed during subsetting some fonts, e.g. Devanagari
> (NotoSansDevanagari).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]