[
https://issues.apache.org/jira/browse/PDFBOX-3382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15335696#comment-15335696
]
kazu commented on PDFBOX-3382:
------------------------------
Unfortunately i can only provide approximate code-snippets as the mentioned
PDF-document is created using XML templates. However, the following
code-snipped leads to a similar situation within the profiler and spends 50-60%
of its time calling TrueTypeFont.hasGlyph() and 10% on PDFont.encode():
{code}
final PDDocument pdf = new PDDocument();
// create several pages
for (int p = 0; p < 8; ++p) {
final PDPage page = new PDPage(PDRectangle.A4);
pdf.addPage(page);
final boolean compress = true;
PDPageContentStream stream = new PDPageContentStream(pdf, page,
PDPageContentStream.AppendMode.OVERWRITE, compress);
stream.setFont(PDType1Font.HELVETICA, 12);
// create several text-lines per page
for (int i = 0; i < 64; ++i) {
stream.beginText();
stream.newLineAtOffset(20, i*10+20);
stream.showText("the quick brown fox jumps over the lazy dog");
stream.endText();
}
stream.close();
}
pdf.close();
{code}
the corresponding code for PDFBox 1.8.2:
{code}
final PDDocument pdf = new PDDocument();
// create several pages
for (int p = 0; p < 8; ++p) {
PDPage page = new PDPage(PDPage.PAGE_SIZE_A4);
pdf.addPage(page);
final boolean compress = true;
final boolean append = false;
PDPageContentStream stream = new PDPageContentStream(pdf, page, append,
compress);
stream.setFont(PDType1Font.HELVETICA, 12);
// create several text-lines per page
for (int i = 0; i < 64; ++i) {
stream.beginText();
stream.moveTextPositionByAmount(20, i*10+20);
stream.drawString("the quick brown fox jumps over the lazy
dog");
stream.endText();
}
stream.close();
}
pdf.close();
{code}
For those snippets, the performance difference is "only" about 1:3 [measured
the time needed to generate 10.000 documents]. The original document also uses
methods like font.getStringWidth(). When adding those to the snippet as well,
the performance difference increases to about 1:5.
> pdf creation very slow
> ----------------------
>
> Key: PDFBOX-3382
> URL: https://issues.apache.org/jira/browse/PDFBOX-3382
> Project: PDFBox
> Issue Type: Improvement
> Components: FontBox, Writing
> Affects Versions: 2.0.2
> Reporter: kazu
> Priority: Minor
> Labels: performance
>
> compared to older 1.8.x versions, the new 2.0.x branch is awesomely slow.
> benchmarks using a multipage document with few images and many text-lines
> indiciate a performance penalty of about 1:20 compared with the old 1.8.x
> branch.
> profiling via VisualVM indicates that the new font handling causes this
> performance drawback:
> TrueTypeFont.nameToGid() [31%]
> TrueTypeFont.hasGlyph() [23%]
> PDFont.getWidth() [16%]
> PDType1Font.encode() [9%]
> is there any workaround for this? the current setup only creates about 10
> PDFs/second compared to over 200/second for the 1.8.x branch...
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]