4

如何使用添加/覆盖 PDF 的标题和作者元数据CAM::PDF

4

1 回答 1

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);
    }
}
于 2012-05-07T15:10:33.700 回答