Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - SetPageSize - Why so slow?
  FAQ FAQ  Forum Search   Register Register  Login Login

SetPageSize - Why so slow?

 Post Reply Post Reply
Author
Message
waynefulcher View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Jun 08
Location: United States
Status: Offline
Points: 99
Post Options Post Options   Thanks (0) Thanks(0)   Quote waynefulcher Quote  Post ReplyReply Direct Link To This Post Topic: SetPageSize - Why so slow?
    Posted: 01 Jul 08 at 12:16PM
I have a simple routine which will take a text file and convert it to a PDF.
One of my text files works out to be around 3,500 pages.
My logic was taking about 5 minutes to convert this file. I displayed a pagecount as it was converting and I noticed the more pages that were added the slower the next page would take. So I researched to find out what was slowing down the more pages that were being created. What I found was if I remove a single line of code which was PDF.SetPageSize(ReportPageSize) then it only took about 10 seconds to convert the text file. The actual PageSize needed is passed in as a parameter. Below is a simplified code snipit to get across what I am doing.
 
...
while not end of text file....
  [read a pages worth of data from the text file.]
  PDF.NewPage ;
  PDF.SelectPage(PDF.PageCount) ;
  PDF.SetPageSize(ReportPageSize) ;  <- This line is the problem
  [write the text data to the currently selected page.]
end of while loop
PDF.SaveToFile(SomeFileName) ;
 
My question is: Is there a way to tell the PDF document up front that I want all my pages to be "Some Size" so I do not have to make that call for each page? Or can someone with source code see if they can make that method call more efficent?
 
Thanks in advance.
Wayne
 
 
Back to Top
ukobsa View Drop Down
Senior Member
Senior Member


Joined: 29 May 06
Location: Germany
Status: Offline
Points: 115
Post Options Post Options   Thanks (0) Thanks(0)   Quote ukobsa Quote  Post ReplyReply Direct Link To This Post Posted: 03 Jul 08 at 9:03AM
Wayne,

which version of QuickPDf you are using? The new version 6 have some speed improvements for large files in it.

The problem is that the code for SetPageSize inside QuickPDF is somewhat strange: is loops always over 49 paper size types regardless if it finds the type to be the first. This in combination with accessing the object structure in a linear way in version 5 can slow down the process on documents with a lot of pages. And it will get even slower as more pages are added (new entries are added at the end).

HTH,
Ulrich
Back to Top
waynefulcher View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Jun 08
Location: United States
Status: Offline
Points: 99
Post Options Post Options   Thanks (0) Thanks(0)   Quote waynefulcher Quote  Post ReplyReply Direct Link To This Post Posted: 03 Jul 08 at 9:19AM
I am using version 5.21, which I thought was the latest version. I found if I know that all pages will be the same for the entire document then I only need to call that method once up front and all pages added after that will be the same as the first one. Is there a newer version available? Where can I download it?
 
Thanks
Wayne
 
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 04 Jul 08 at 9:11AM
Hi!
 
So have a try with 6.03 from the source-section.
...Or wait for a week and we will begin with the new compiled versions.
 
Best regards,
Ingo
Back to Top
DaveH View Drop Down
Beginner
Beginner


Joined: 15 Jul 08
Location: Canada
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote DaveH Quote  Post ReplyReply Direct Link To This Post Posted: 15 Jul 08 at 11:10PM
Wayne
 
I'm using an old version (4.26 I think)  and I only call SetPageSize once at the beginning.  Here is my loop structure...
 
    Pdf.Permissions(1,1,0,0,0,1,0,1);
    Pdf.SetPageSize('Letter Landscape');
    Pdf.SetOrigin(1);               //top left
    Pdf.SetMeasurementUnits(2);     //inches
    Pdf.SetTextColor(0, 0, 0);      //black
    Pdf.SetFillColor(0, 0, 0);      //black
    Pdf.SelectFont(Pdf.FontID(1));  //courier new
    Pdf.SetTextAlign(0);            //left align
    Pdf.SetTextSize(FontSize);
...
    while (not Quit) do
      begin
      ...
      if (Pos(#12, S) <> 0) then
        begin
        Pdf.NewPage;  //you have to reset the following 3 items every page
        Pdf.SelectFont(Pdf.FontID(1));  //courier new
        Pdf.SetTextAlign(0);             //left
        Pdf.SetTextSize(FontSize);
        VPos:= TopMargin;
        end;
    ...
    end;  //while 
 
However, I too experience a significant slow down as the PDF document gets larger.
 
I auto convert a bunch of text reports to PDF.  One is 20,000 pages and takes over 5 hours to run.
 
I only have a basic license so no source code to debug but it has to be in the lines above or DrawText because those are the only API calls I make in the loop.  Maybe that will help point to the real problem.
 
I suspect that it is reallocating memory with every new page and copying the entire document to the new memory space.
 
DaveH
 
Back to Top
waynefulcher View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Jun 08
Location: United States
Status: Offline
Points: 99
Post Options Post Options   Thanks (0) Thanks(0)   Quote waynefulcher Quote  Post ReplyReply Direct Link To This Post Posted: 16 Jul 08 at 9:31AM
I actually realized I did not need to call SetPageSize but once also and that alone seemed to fix my problem. But you are correct in it relocating memory everytime you call NewPage. So to help with that I calculated a number based on the size of my text file so for a larger files this number may be somewhere around 500. Then instead of calling NewPage 20,000 times. I will call NewPages(500) and add them in blocks of 500 pages. So I only need to call it about 40 times using your example. I keep up with an actual CurrentPageIndex to select the next actual page needed. Once I have used the next 500 I will add another 500 and so on. Then when I am done I delete the number of unused pages. What would be interesting is if you commented all of your API calls except for NewPage even though you know your output may be wrong, just to see if one of those lines are slowing it down or not. If you happen to do that test let me know your results.
Back to Top
DaveH View Drop Down
Beginner
Beginner


Joined: 15 Jul 08
Location: Canada
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote DaveH Quote  Post ReplyReply Direct Link To This Post Posted: 17 Jul 08 at 7:06AM
Wow!  What a difference.
 
Using your technique, I allocate 100 pages, draw on each keeping track of where I am and allocate another 100 pages when I run out and finally adjust the page count at the end by deleting unused pages.
 
This 154MB PDF with just under 18,000 pages went from 6 hours to 10 minutes to produce.
 
Kind of makes it obvious why the original developer included a "NewPages" method.
 
Thanks
DaveH
 
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store