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!
SetPageSize - Why so slow? |
Post Reply |
Author | |
waynefulcher
Senior Member Joined: 23 Jun 08 Location: United States Status: Offline Points: 99 |
Post Options
Thanks(0)
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
|
|
ukobsa
Senior Member Joined: 29 May 06 Location: Germany Status: Offline Points: 115 |
Post Options
Thanks(0)
|
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 |
|
waynefulcher
Senior Member Joined: 23 Jun 08 Location: United States Status: Offline Points: 99 |
Post Options
Thanks(0)
|
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
|
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
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
|
|
DaveH
Beginner Joined: 15 Jul 08 Location: Canada Status: Offline Points: 4 |
Post Options
Thanks(0)
|
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
|
|
waynefulcher
Senior Member Joined: 23 Jun 08 Location: United States Status: Offline Points: 99 |
Post Options
Thanks(0)
|
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.
|
|
DaveH
Beginner Joined: 15 Jul 08 Location: Canada Status: Offline Points: 4 |
Post Options
Thanks(0)
|
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
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store