2014-10-04 88 views
2

我使用perl模块PDF::API2::Annotation为我的pdf文件添加注释。使用perl添加注释到pdf

有支持决定使用rect创建注释的位置。这样的事情:

$annot->text($text, -rect => [ 10, 10, 10, 10 ]); 

它工作正常,但我有问题要准确的把我的注释。

我知道pdf的左下角是(0,0)。假设我想在页面中间准确地添加一个注释,任何想法如何实现?根据这个https://www.leadtools.com/help/leadtools/v18/dh/to/leadtools.topics.pdf~pdf.topics.pdfcoordinatesystem.html pdf分为点,每个点是1/72英寸。和一个pdf大小是这样的中间应该是 (306,396)

但是,这甚至不接近中间。

回答

0

你可以在页面媒体盒的大小,然后计算该中间:

# 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; 
} 

这些通常都是一样的,除非文档已被设置为一个溢出区域专业印刷等

+0

在这种情况下,你可以使用其中的任何计算x和y页面的中点。 – 2014-10-05 08:13:41

+0

你刚刚得到了几秒钟后我批评了评论。多谢 – 2014-10-05 08:18:45