RE: Do you see a better way of doing this with PDF::API2?
"Tim Turner" <[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.pdfapi2 |
|---|---|
| Message-ID | <20070815140505.SFHF11388.ibm68aec.bellsouth.net@SONYXP2003> |
Good point. I usually create the fonts I use in a script one time near the top and then use them as needed in the code. That prevents most accidental coding of such allocations inside loops. Example: Do this once at top. Set it and forget it. $headerfont = $pdf->corefont( "Helvetica-Bold", -encode=>"latin1"); $font = $pdf->corefont( "Helvetica", -encode=>"latin1"); $italicfont = $pdf->corefont( "Helvetica-Oblique", -encode=>"latin1"); Then use those fonts as needed in the rest of the script. -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Mark Fowle Sent: Wednesday, August 15, 2007 9:44 AM To: [email protected] Subject: RE: [perl-text-pdf-modules] Do you see a better way of doing this with PDF::API2? The below is from a script, hopefully you can make sense of it. If you assume the font face size and color could change with each loop the savings can be enormous. I'll keep your email around and see if I can write a better response when I have time. Mark For text: OK: Foreach text item $txt->translate($x_left + 1/8 * INCH,$y_curr + .2 * $font_size{'med'} ); $font = $pdf->corefont('Helvetica-bold',1); $txt->font($font,$font_size{'med'}); $txt->fillcolor($colors{'white'}); $txt->text_right("$text"); Better: My %fonts $fonts{hb} = $pdf->corefont('Helvetica-bold',1); Foreach text item $txt->translate($x_left + 1/8 * INCH,$y_curr + .2 * $font_size{'med'} ); $font = $fonts{hb} $txt->font($font,$font_size{'med'}); $txt->fillcolor($colors{'white'}); $txt->text_right("$text"); ________________________________ From: [email protected] [mailto:[email protected]] On Behalf Of Tim Turner Sent: Wednesday, August 15, 2007 9:06 AM To: [email protected] Subject: RE: [perl-text-pdf-modules] Do you see a better way of doing this with PDF::API2? Mark [or anyone else] Do you have any basic or advanced suggestions for reducing process size? Although I have done a lot of programming over the years in many languages that is something I don't know much about. I'm guessing Bill H and others might also could benefit from a few tips in this area. -Tim -----Original Message----- From: [email protected] <mailto:perl-text-pdf-modules%40yahoogroups.com> [mailto:[email protected] <mailto:perl-text-pdf-modules%40yahoogroups.com> ] On Behalf Of Mark Fowle Sent: Wednesday, August 15, 2007 9:01 AM To: [email protected] <mailto:perl-text-pdf-modules%40yahoogroups.com> Subject: RE: [perl-text-pdf-modules] Do you see a better way of doing this with PDF::API2? Also watch the process size from a consol while the process is running. I've made some PDF creation scripts that loop and open another handle for each bit of text, process size can bloom causing the script to be an order of magnitude slower than needed. ________________________________ From: [email protected] <mailto:perl-text-pdf-modules%40yahoogroups.com> [mailto:[email protected] <mailto:perl-text-pdf-modules%40yahoogroups.com> ] On Behalf Of Tim Turner Sent: Tuesday, August 14, 2007 10:18 PM To: [email protected] <mailto:perl-text-pdf-modules%40yahoogroups.com> Subject: RE: [perl-text-pdf-modules] Do you see a better way of doing this with PDF::API2? Hello, I can tell you from experience the server is a big deal. We had a PDF that took 40 to 50 sec to generate that now takes only 5 seconds to APPEAR inside acrobat on a newer better server. Loading even static PDFs often takes a few seconds to APPEAR in acrobat. So anyway, you should still pursue code improvements but don't underestimate the effect of a better server if you can afford whatever cost is associated with that improvement. Regards, -Tim -----Original Message----- From: [email protected] <mailto:perl-text-pdf-modules%40yahoogroups.com> <mailto:perl-text-pdf-modules%40yahoogroups.com> [mailto:[email protected] <mailto:perl-text-pdf-modules%40yahoogroups.com> <mailto:perl-text-pdf-modules%40yahoogroups.com> ] On Behalf Of spinningwebz2002 Sent: Tuesday, August 14, 2007 8:10 PM To: [email protected] <mailto:perl-text-pdf-modules%40yahoogroups.com> <mailto:perl-text-pdf-modules%40yahoogroups.com> Subject: [perl-text-pdf-modules] Do you see a better way of doing this with PDF::API2? 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