开发者

How to update PDF metadata with CAM::PDF

How can I add/overwrite开发者_开发知识库 the title and author metadata of a PDF using CAM::PDF?


I'm the author of CAM::PDF. The library doesn't support this sort of edit, but you can do it by digging into the internals like this:

#!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);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜