Hmm, there are lies, damn lies and statistics. While I don't dispute the 30% 
let's see the probable causes for this:

- iText tries to do things correctly avoiding to cut corners that will come and 
bite your later. Metadata writing, appearance generation and so on.

- iText is a generic PDF library. It reads, writes and modifies PDFs. Any 
library designed with a narrower purpose can optimize the interested areas to 
perform better.

- iText comes with source and can be extended, modified, altered. This implies 
that a sensible and probably heavier structure must be in place to allow that. 
If you have a closed source library with just a single purpose things can be 
done faster as that's all it's going to do.

- com.itextpdf.text.pdf.PdfStamperImpl.close() is where everything is written 
to file, if you avoid calling this nothing will come out.

- There are some speed and memory improvements in the pipeline but I don't know 
how much % improvement will result or in what areas.

Paulo

________________________________
From: Azùa Giovanni (KSXD 32) [[email protected]]
Sent: Tuesday, April 20, 2010 1:12 PM
To: Post all your questions about iText here
Subject: [iText-questions] performance question


Hello,

For a specific Letter generation use-case I prepared a test of statistical 
significance using a paired t-test for comparing the performance [1] of iText 
vs a commercial PDF framework. The experiment shows that for our relevant 
use-case iText underperforms by 30% with 95% confidence.

I did some further investigation of the iText code for this specific use-case 
and found the following call to be among the top most expensive calls:

com.itextpdf.text.pdf.PdfStamperImpl.close (line 189) taking up to 195 
milliseconds

The code that invokes such method is the following:

private static void appendFooter(PdfWriter writer) throws Exception {
    Map<String, String> replacements = new HashMap<String, String>();
    replacements.put("ph0001", "XXXXX XXXXX");
    replacements.put("ph0002", "Head of Customer Acquisition");
    replacements.put("ph0003", "XXXXXX XXXXXXX");
    replacements.put("ph0004", "Head of Customer Satisfaction");

    PdfReader footerReader = new PdfReader(FOOTER_PATH);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PdfStamper stamper = new PdfStamper(footerReader, outputStream);
    AcroFields form = stamper.getAcroFields();
    for (Map.Entry<String, String> entry : replacements.entrySet()) {
        form.setField(entry.getKey(), entry.getValue());
    }
    stamper.setFormFlattening(true);
    stamper.close();

    int pageOne = 1;
    int xOffset = 5;
    int yOffset = -560;
    PdfReader memoryReader = new PdfReader(outputStream.toByteArray());
    PdfImportedPage importedPage = writer.getImportedPage(memoryReader, 
pageOne);
    PdfContentByte content = writer.getDirectContent();
    content.addTemplate(importedPage, xOffset, yOffset);
}

Are there any possible rewrites to avoid the expensive call?

Thanks in advance,
Best regards,
Giovanni

[1] The Art of Computer Systems Performance Analysis: Techniques for 
Experimental Design, Measurement, Simulation, and Modeling 
http://www.amazon.com/Art-Computer-Systems-Performance-Analysis/dp/0471503363/ref=cm_cr-mr-title

==============================================================================
Please access the attached hyperlink for an important electronic communications 
disclaimer:

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================


Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter 
informação confidencial ou legalmente protegida. A incorrecta transmissão desta 
mensagem não significa a perca de confidencialidade. Se esta mensagem for 
recebida por engano, por favor envie-a de volta para o remetente e apague-a do 
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de 
usar, revelar ou distribuir qualquer parte desta mensagem. 

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain 
confidential or legally protected information. The incorrect transmission of 
this message does not mean the loss of its confidentiality. If this message is 
received by mistake, please send it back to the sender and delete it from your 
system immediately. It is forbidden to any person who is not the intended 
receiver to use, distribute or copy any part of this message.

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to