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

时间:2011-10-03 13:59:09

标签: perl pdf cam-pdf

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

1 个答案:

答案 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);
    }
}