2009-08-18 48 views
1

我从图像文件列表中创建PDF,我想知道是否有可能创建我的PDF的每个页面的大小,无论我现在添加的图像的大小 - 所以他们都适合,没有一个较大的得到裁剪或其他任何东西。如何根据PDF :: API2中的图像大小创建页面?

目前我创建的网页是这样的:my $page = $pdf->page();

我有具体形象的一个目的也是如此。如果有人可以将其标记为PDF :: API2,那会很棒。

回答

2

我想你想看看$pdf->mediabox(),$pdf->cropbox(),$pdf->bleedbox()$pdf->trimbox()

虽然你可能想找到PDF规范来确定它们是如何工作的。

2

您是否认为这纯粹是为了在屏幕上观看?如果打印大小并不重要,你可以做这样的事情:

use PDF::API2; 
my $pdf = PDF::API2->new(); 

foreach my $filename (@list_of_jpeg_locations) { 
    my $image = $pdf->image_jpeg($filename); 

    my $width = $image->width(); 
    my $height = $image->height(); 

    # Set the page size to equal the image size 
    my $page = $pdf->page(); 
    $page->mediabox($width, $height); 

    # Place the image in the bottom corner of the page 
    my $gfx = $page->gfx(); 
    $gfx->image($image, 0, 0); 
} 

$pdf->saveas('/path/to/file.pdf'); 

你可以调整这个代码来缩放图像,以适应特定的打印的页面大小,如果需要的话。

相关问题