使用perl生成pdf

Sui*_*uic 1 pdf security perl

我想使用perl + PDF :: API2在我的网站上生成一些pdf文档.

1)阅读pdf模板
2)向模板添加一些数据
3)将文件保存到硬盘
4)读取新文件
5)将其打印到用户的浏览器

#!/usr/bin/perl

use strict;
use PDF::API2;

my $p = PDF::API2->open('/way/to/input/pdf.pdf');
my $font = $p->ttfont('/way/to/font.ttf', -encode => 'utf8');
my $page = $p->openpage(1);
my $text = $page->text();
$text->font($font,12);
$text->translate(150,150);
$text->text('Hello world!');
$p->saveas('/way/to/out/pdf.pdf'); #ex: '/usr/local/www/apache22/data/docs'

my $fileContent;
open(my $file, '<', '/way/to/out/pdf.pdf') or die $!;
binmode($file);
{
    local $/;
    $fileContent = <$file>;
}
close($file);

binmode STDOUT;
print "Content-type: application/pdf\n\n";
print $fileContent;
exit;
Run Code Online (Sandbox Code Playgroud)

如何在不将临时PDF存储在/ way/to/out /文件夹(r/w可访问)的情况下执行此操作?

Que*_*tin 8

请参阅PDF :: API2的文档 ; 在它描述saveas您正在使用的方法之后,它会立即显示如何使用该stringify方法,它可以执行您想要的操作.

$text->text('Hello world!');
binmode STDOUT;
print "Content-type: application/pdf\n\n";
print $p->stringify();
exit;
Run Code Online (Sandbox Code Playgroud)