gpt4 book ai didi

perl - 使用 perl 向 pdf 添加注释

转载 作者:行者123 更新时间:2023-12-04 18:06:07 25 4
gpt4 key购买 nike

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

支持使用矩形决定在何处创建注释。像这样:

$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.htmlpdf被分成点,每个点是1/72英寸。 pdf 大小所以中间应该是(306,396)

但那还差得远呢。

最佳答案

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

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

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

关于perl - 使用 perl 向 pdf 添加注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26197618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com