如何使用 PDF::API2::Lite 添加带有图像的页眉、页脚?
是否可以添加带有图像的页眉(带有文本和一张图像)和页脚(带有页码)。我编写了下面的代码来创建一个显示 png 图像的 PDF 文档。
如果可以使用任何其他模块轻松完成此操作,请提出建议。非常感谢示例代码的回复。
use strict;
use PDF::API2::Lite;
use Getopt::Long;
my $outfile;
my $path;
my $options = GetOptions( "outfile=s" => \$outfile,
"images=s" => \$path,);
my @images = sort glob("$path") or die "No Files\n";
my $pdf = PDF::API2::Lite->new();
for my $png ( sort @images ) {
my $image = $pdf->image_png( "$png" );
$pdf->page(1150,450);
$pdf->image($image, 10, 10);
}
$pdf->saveas( $outfile );
Is it possible to add header(with text and one image) and footer (with page number) with images. I wrote below code to create a PDF document which shows png images.
If this can be done easily with any other module, please suggest.Really appreciate response with sample code.
use strict;
use PDF::API2::Lite;
use Getopt::Long;
my $outfile;
my $path;
my $options = GetOptions( "outfile=s" => \$outfile,
"images=s" => \$path,);
my @images = sort glob("$path") or die "No Files\n";
my $pdf = PDF::API2::Lite->new();
for my $png ( sort @images ) {
my $image = $pdf->image_png( "$png" );
$pdf->page(1150,450);
$pdf->image($image, 10, 10);
}
$pdf->saveas( $outfile );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 SO 上等待一天可以节省您 10 分钟阅读模块文档的时间。这并不难,太空。
Waiting one day on SO saved you 10 minutes reading the module documentation. It's not difficult, Space.
PDF::API2 是我处理此类事情的主力。
当我需要对现有 PDF 文档进行任何布局或重新处理时,我几乎总是会使用
importPageIntoForm
方法。作为一般解决方案,我逐页创建一个新的 PDF,导入我想要放置的元素,然后添加其他文本或图形。
PDF::API2 is my workhorse for this sort of thing.
And I'll almost always use the
importPageIntoForm
method, as soon as I need to do any layup or reprocessing of an existing PDF document.As a general solution, I create a new PDF, page by page, import the elements that I want to lay up, then add additional text or graphics.
看看
PDF::API2::Simple
< /a> 相反。此 CPAN 模块围绕PDF::API2
< /a> 包括页眉和页脚。这是一个简单的工作页眉/页脚示例:
/I3az/
Have a look at
PDF::API2::Simple
instead. This CPAN modules provides some handy helper methods aroundPDF::API2
including headers and footers.Here is a simple working header/footer example:
/I3az/