Re: PdfWriter: Close() and memory problems

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: PdfWriter: Close() and memory problems

Paulo Soares
Try:

while(...)
{
  PdfReader reader = new PdfReader(inFileName);
  for(int i=1; i<=reader.NumberOfPages; i++)
  {
    outPdf.NewPage();
    PdfImportedPage page = writer.GetImportedPage(reader, i);
    cb.AddTemplate(page, ....)
  }
  writer.FreeReader(reader);
}


Note that you may want to use PdfCopy instead.

----- Original Message -----
From: "Fabrizio Accatino" <[hidden email]>
To: <[hidden email]>
Sent: Friday, September 16, 2005 1:14 PM
Subject: [itextsharp-questions] PdfWriter: Close() and memory problems


Hello,
I'm testing iTextSharp. I need to merge many pdf files (3000 or more)
into one pdf.

I've noticed a strange behaviour: the pages are added very fast but
when I call the outPdf.Close() the application works for many minutes.
In this period the CPU is 100% and the output pdf file is slowly
incremented. Is that normal?

And another question: I noticed an high memory usage, 300 or more
MByte allocated by the process. The memory increases during import and
remain the same during the Close call.
Is that normal?



    Thank you


Fabrizio


Some code fragments:
.....
Document outPdf = new Document(new Rectangle(595,841));
FileStream outPdfStream = new FileStream(outPdfFileName,
FileMode.Create, FileAccess.Write);
PdfWriter writer = PdfWriter.GetInstance(outPdf, outPdfStream);
....
while(...)
{
  PdfReader reader = new PdfReader(inFileName);
  for(int i=1; i<=reader.NumberOfPages; i++)
  {
    outPdf.NewPage();
    PdfImportedPage page = writer.GetImportedPage(reader, i);
    cb.AddTemplate(page, ....)
  }
  reader.Close();
}
outPdf.Close();      <----- VERY VERY LONG !!!!!!
....


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server.
Download it for free - -and be entered to win a 42" plasma tv or your very
own Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
itextsharp-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server.
Download it for free - -and be entered to win a 42" plasma tv or your very
own Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
itextsharp-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
Reply | Threaded
Open this post in threaded view
|

Re: PdfWriter: Close() and memory problems

Fabrizio Accatino
Hi Paulo,

you suggestion is good. Now memory remains low.

But I continue to notice a strange degradation of performance during
merge loop: the first documents are imported at a very high rate: 100
doc/s or more. After 1000 doc the performance is 10 doc/s. And it
continues to decrease.

Using Windows Task Manager, I've also noticed an high rate of I/O
reads (many Gigabytes...) but the total size of my 2000 pdf is 75
MByte. I don't understand why iText (if is iText....) reads so many
datas.

To avoid this behaviour I tried to load the byte stream in a temp vect:
    FileStream rdr = new FileStream(inFileName, FileMode.Open, FileAccess.Read);
    byte[] tempVect = new byte[rdr.Length];
    rdr.Read(tempVect, 0 , (int)rdr.Length);
    rdr.Close();
    reader =  new PdfReader(tempVect);

Now the total I/O is correct: more or less 100 Mbyte.
But the performance remains the same. In particular import rate
continue to decrease during import loop.

Suggestions?


Thank you


   Fabrizio


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server.
Download it for free - -and be entered to win a 42" plasma tv or your very
own Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
itextsharp-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
Reply | Threaded
Open this post in threaded view
|

RE: PdfWriter: Close() and memory problems

Paulo Soares
In reply to this post by Paulo Soares
 

> -----Original Message-----
> From: Fabrizio Accatino [mailto:[hidden email]]
> Sent: Monday, September 19, 2005 10:04 AM
> To: Paulo Soares
> Cc: [hidden email]
> Subject: Re: [itextsharp-questions] PdfWriter: Close() and
> memory problems
>
> Hi Paulo,
>
> you suggestion is good. Now memory remains low.
>
> But I continue to notice a strange degradation of performance during
> merge loop: the first documents are imported at a very high rate: 100
> doc/s or more. After 1000 doc the performance is 10 doc/s. And it
> continues to decrease.
>

That's possible. The xref uses a tree to keep the addresses and that's
ineficient for docs that are not used in append mode (most of the
cases). That's hight in my to-do list but it's not done yet.

> Using Windows Task Manager, I've also noticed an high rate of I/O
> reads (many Gigabytes...) but the total size of my 2000 pdf is 75
> MByte. I don't understand why iText (if is iText....) reads so many
> datas.
>

That depends on how the measurement is done. iText does a lot of small
reads but if to read 100 bytes a 32k page is read and accounted for it's
easy to reach high memory IO.

> To avoid this behaviour I tried to load the byte stream in a
> temp vect:
>     FileStream rdr = new FileStream(inFileName,
> FileMode.Open, FileAccess.Read);
>     byte[] tempVect = new byte[rdr.Length];
>     rdr.Read(tempVect, 0 , (int)rdr.Length);
>     rdr.Close();
>     reader =  new PdfReader(tempVect);
>
> Now the total I/O is correct: more or less 100 Mbyte.
> But the performance remains the same. In particular import rate
> continue to decrease during import loop.
>
> Suggestions?
>
>
> Thank you
>
>
>    Fabrizio
>


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server.
Download it for free - -and be entered to win a 42" plasma tv or your very
own Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
itextsharp-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions