如何使用CAM::PDF
添加/覆盖PDF的标题和作者元数据?
答案 0 :(得分:4)
我是CAM :: PDF的作者。该库不支持这种编辑,但您可以通过深入研究这样的内部结构来实现:
#!perl -w
use strict;
use CAM::PDF;
my $infile = shift || die 'syntax...';
my $outfile = shift || die 'syntax...';
my $pdf = CAM::PDF->new($infile) || die;
my $info = $pdf->getValue($pdf->{trailer}->{Info});
if ($info) {
#use Data::Dumper; print Dumper($info);
my $title = $info->{Title};
if ($title) {
$title->{value} = 'Foo';
# for a proper implementation, we should mark the holder of $info as dirty...
# But cleanoutput ignores dirty flags anyway and writes the whole doc
$pdf->cleanoutput($outfile);
}
}