Perl 如何使用CAM::PDF更新PDF元数据

Perl 如何使用CAM::PDF更新PDF元数据,perl,pdf,cam-pdf,Perl,Pdf,Cam Pdf,如何使用添加/覆盖PDF的标题和作者元数据?我是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->getVa

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

我是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);
    }
}