Dear Benjamin,
I used a profiler to trace the hotspot, and it turned out it's not the
output stream,
it's the PdfReader. PdfReader uses the RandomAccessFileOrArray to access the
file, and
PdfStamper.close method eventually calls PRStream.toPdf, and it calls
PdfReader.getStreamBytesRaw which calls RandomAccessFileOrArray.reOpen which
constructs a new file stream every time. And this acounts for almost all the
time consumed
by PdfStamper.close. My question is, is there a way to not use
RandomAccessFileOrArray and
directly use file stream? Is it possible? I mean, without modifying the source
code of iText.
From: Benjamin Rein
Sent: Tuesday, April 07, 2009 4:00 PM
To: Post all your questions about iText here
Subject: [iText-questions] Antwort: About the performance issue of the iText
Hi,
please don't use FileOutputStream directly as parameter for PDFStamper. I would
first try to use BufferedOutputStream in addition.
If you don't know enough about streams have a look here:
http://java.sun.com/docs/books/tutorial/essential/io/buffers.html
Best regards
Benjamin
Von: "Imgen" <[email protected]>
An: "iText Questions" <[email protected]>
Datum: 07.04.2009 05:11
Betreff: [iText-questions] About the performance issue of the iText
--------------------------------------------------------------------------------
My code is like below
FileInputStream bmReader = new FileInputStream( "c:\\bookmarks.xml");
List bookmarks = SimpleBookmark.importFromXML( bmReader );
bmReader.close();
PdfReader reader = new PdfReader( "c:\\Testify Manual.pdf" );
reader.consolidateNamedDestinations();
PdfStamper stamper = new PdfStamper(reader, new
FileOutputStream("c:\\merged.pdf"));
stamper.setOutlines(bookmarks);
stamper.setViewerPreferences(reader.getSimpleViewerPreferences() |
PdfWriter.PageModeUseOutlines);
stamper.close(); //this is the hot spot, it takes 25s to complete
processing
About my pdf file, its size is about 750k, please see the attachment.
--------------------------------------------------
From: "Alexis Pigeon" <[email protected]>
Sent: Tuesday, April 07, 2009 12:15 AM
To: "Post all your questions about iText here"
<[email protected]>
Subject: Re: [iText-questions] About the performance issue of the iText
> Hi Imgen,
>
> 2009/4/6 Imgen <[email protected]>:
>> I use iText to add bookmarks to an existing pdf file. It's about 750k. But
>> it takes
>> 25s for the PdfStamper.close() to write the file to the disk. My computer's
>> configuration
>> is Intel Core2 Duo T7500 2.2GHZ + 2G Memory + Win7, not very bad. But the
>> close method
>> takes too long to complete the action. Is there a way to improve this or I'm
>> simply doomed.
>
> Please provide a standalone piece of code + existing PDF file so that
> we might have a chance to reproduce, and maybe pinpoint what's wrong.
> If possible, you can also try on your side with another OS, developing
> on an alpha/beta OS sounds to me just like asking for trouble...
>
> Cheers,
> alexis
>
> ------------------------------------------------------------------------------
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> Buy the iText book: http://www.1t3xt.com/docs/book.php
>------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php
____________________________________________________________________
Viessmann IT Service GmbH
Geschäftsführer: Dirk Klöckner, Dr. Harald Dörnbach
Sitz der Gesellschaft: Allendorf (Eder) - Registergericht:
AG Marburg (Lahn) - HRB 5324 - USt-IdNr.: DE258558424
____________________________________________________________________
--------------------------------------------------------------------------------
------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
--------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php