使用perl向pdf添加注释

使用perl向pdf添加注释,perl,pdf,Perl,Pdf,我正在使用perl模块向我的pdf文件添加注释 支持使用rect决定在何处创建注释。大概是这样的: $annot->text( $text, -rect => [ 10, 10, 10, 10 ] ); 这很好,但我有一个问题,就是要准确地把我的注释放在哪里 我知道pdf的左下角是(0,0)。假设我想把注释精确地放在页面的中间,你知道我怎样才能做到这一点吗? 据此, pdf分为多个点,每个点为1/72英寸。pdf的大小是,所以中间应该是 (306396) 但这甚至不接近中间。您可以

我正在使用perl模块向我的pdf文件添加注释

支持使用rect决定在何处创建注释。大概是这样的:

$annot->text( $text, -rect => [ 10, 10, 10, 10 ] );
这很好,但我有一个问题,就是要准确地把我的注释放在哪里

我知道pdf的左下角是
(0,0)
。假设我想把注释精确地放在页面的中间,你知道我怎样才能做到这一点吗? 据此, pdf分为多个点,每个点为1/72英寸。pdf的大小是,所以中间应该是
(306396)


但这甚至不接近中间。

您可以获得页面媒体框的大小,然后从中计算中间:

# get the mediabox
my ($llx, $lly, $urx, $ury) = $page->get_mediabox;
# print out the page coordinates
say "page mediabox: " . join ", ", $llx, $lly, $urx, $ury;
# output: 0, 0, 612, 792 for the strangely-shaped page I created

# calculate the midpoints
my $midx = $urx/2;
my $midy = $ury/2;

my $annot = $page->annotation;
# create an annotation 20 pts wide and high around the midpoint of the mediabox 
$annot->text($text, -rect=>[$midx-10,$midy-10,$midx+10,$midy+10]);
除了介质盒,您还可以获得页面裁剪框、修剪框、出血框和艺术框:

for my $box ('mediabox', 'cropbox', 'trimbox', 'artbox', 'bleedbox') {
    my $get = "get_$box";
    say "$box dimensions: " . join ", ", $page->$get;
}

这些通常都是相同的,除非文档已设置为带有出血区域等的专业打印。

在这种情况下,您可以使用其中任何一个来计算页面的x和y中点。yeh在我收到评论后几秒钟才得到这些。大量thx