Hi
I have a problem with pdf::api2
I need to edit an existing pdf and put in some images. The problem is that for inserting 4 images it takes around 20 seconds per image. So the whole process goes up to minute and a half. Is there some magic i can do to speed up the process?
The images are 1920 × 1080 and need to stay that size, because i need quality pdf-s... So without further ado, here is the code:
#!/usr/bin/perl
use PDF::API2;
print "start ".(localtime)."\n";
$pdf = PDF::API2->open("sample.pdf");
$page = $pdf->openpage(1);
$page->mediabox(840,600)
$gfx=$page->gfx;
print "first image ".(localtime)."\n";
$first=$pdf->image_png("first.png");
print "inserting first image ".(localtime)."\n";
$gfx->image($first,134,106,510,281);
print "saving ".(localtime)." \n";
$pdf->saveas('new_file.pdf');
print "done ".(localtime)." \n";
The output i get:
start Mon Jun 3 10:46:31 2013
first image Mon Jun 3 10:46:31 2013
inserting first image Mon Jun 3 10:46:53 2013
saving Mon Jun 3 10:46:53 2013
done Mon Jun 3 10:46:57 2013
So the most time consuming process is image_png which takes 22 seconds in this example... Any help would be appreciated.
Thanks
Update: if i use the same image converted to JPEG, it works flawlessly, under a second. The problem is i need the transparency of the PNG files
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.