开发者

How to update PDF metadata with CAM::PDF

开发者 https://www.devze.com 2023-04-10 22:07 出处:网络
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

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

精彩评论

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

关注公众号