简体   繁体   中英

PDF::API2 image_png

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

PDF::API2 的文档明确指出对透明 .png 文件的操作很慢,并建议安装 PDF::API2::XS 或 (IIRC) Image::PNG::libpng 以加快速度。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM