Re: Do you see a better way of doing this with PDF::API2?
"spinningwebz2002" <spinningwebz2002-/[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.pdfapi2 |
|---|---|
| Message-ID | <[email protected]> |
--- In [email protected], "spinningwebz2002" <spinningwebz2002@...> wrote: > > First off, let me preface this by saying Thank You to all of you who > have helped me understand how PDF::API2 works (and a BIG thanks to > the author!), without it I would not even be 10% of the way through > this project. > > Now here is the next question I hope you can help me with. FYI all of > this is working right now. > > 1. I am currently creating a multi-page pdf using text that is input > by the user. > > 2. I then save this pdf into a file. > > 3. I then re-open this pdf and extract out the individual pages into > seperate files (reason for this is they may want to view just that > page and I need the individual pages for step 5). > > 4. I then create a new pdf. > > 5. I then open and insert the individual pages into the new file, > along with any photo pages that were made (these are done in a > seperate section and a single page pdf is made with the photo) using > a page map, as an example, if I have a 7 page pdf (filename-1.pdf > through filename-7.pdf (created in step 3)) and my page map says to > insert photopage-1.pdf before page 3 and photopage-2.pdf before page > 6 I will end up with a 9 page pdf containing: > filename-1.pdf > filename-2.pdf > photopage-1.pdf > filename-3.pdf > filename-4.pdf > filename-5.pdf > photopage-2.pdf > filename-6.pdf > filename-7.pdf > > 6. I then save this new finished pdf > > The above steps are important, because if they make a new photo page > I create the page and then jump to step 4 to make a new finished pdf. > > Now the question is, how can I make this faster program wise (it isnt > THAT slow, on a 10 page pdf it takes 45 seconds or so)? The one thing > I can think of that would work is if I could combine steps 2 & 3, so > that while I am making the multipage pdf I can save the current page > as a new pdf without closing the multipage pdf. Is it possible to > save a page on the fly with a new name and not close the current pdf? > Or, can I copy the current page contents into a new pdf structure and > save that? > > Now I will definatly increase the speed when I add more memory to the > server I am testing on, and the server we will deploy on will be the > fastest one possible with the most memory possible, but if I can > speed it up on my 1.5ghz system with 256mb (I know) then it will THAT > much faster on a 4+ghz with 2gb+ of ram. > > Thanks in advance > > Bill H > To follow up on this. I added some timestamping to the code I wrote to see where it may be slow, and it appears to be very slow in this bit of code, taking about 20 seconds to insert photo pages. Can anyone see any obvious improvements for speed in this snippet (this is where it is slow): Rebuild: if ($PROJECTDETAILS{"CHAP$thischapter"."PHOTOMAP"} eq ""){goto NoRebuild;} if ($timing == 1){print TIMING "Starting photo page insert: ".time."\n";} $pagelist = &makePageList; @dbf = split(/\|/,$pagelist); $pdf = PDF::API2->new; $totalpages = 0; $total_pages = 1; if ($timing == 1){print TIMING "Inserting photo pages: ".time."\n";} for($i = 0;$i < @dbf;$i++) { $totalpages++; $thispage = $PROJECTDETAILS{"CHAP$thischapter"."FILE"}."-$dbf [$i]"; $dospecial = 0; if (index($dbf[$i],"-") != -1) { @rbf = split(/\-/,$dbf[$i]); $thispage = $rbf[1]; $dospecial = 1; } if (-e "../$projectpath/$thisproject/$thisfolder/chapter_pdf/ $thispage".".pdf") { $getpdf = PDF::API2->open("../$projectpath/$thisproject/ $thisfolder/chapter_pdf/$thispage".".pdf"); $page = $pdf->importpage($getpdf,1); # if ($dospecial == 1){&pageSpecial;} } } if (int($totalpages / 2) * 2 != $totalpages) { $thispage = $PROJECTDETAILS{"CHAP$thischapter"."FILE"}."-blank"; $getpdf = PDF::API2->open("../$projectpath/$thisproject/ $thisfolder/chapter_pdf/$thispage".".pdf"); $page = $pdf->importpage($getpdf,1); } if ($timing == 1){print TIMING "Saving regenerated pdf: ".time."\n";} $thispage = $PROJECTDETAILS{"CHAP$thischapter"."FILE"}; $pdf->saveas("../$projectpath/$thisproject/$thisfolder/chapter_pdf/ $thispage".".pdf"); NoRebuild: And to give you an idea on the timing: Start: 1187270469 Loading Text: 1187270469 Loading Title: 1187270469 Loading Intro: 1187270469 Start pdf: 1187270469 Doing title: 1187270469 Doing Chapter Number: 1187270469 Doing Intro: 1187270469 Doing Content: 1187270470 Saving content pdf: 1187270475 Creating individual pages: 1187270475 Starting photo page insert: 1187270480 Inserting photo pages: 1187270480 Saving regenerated pdf: 1187270496 You can see the majority of the time is spent inserting the photo pages