我有一个代码,它吐出一堆HTML行,变成PSLines,转而成为PDF行。在PDF行之后,我需要PDF :: Tk来插入背景图像。
下面是我的代码,评论我认为我需要代码的位置。任何人都可以帮我解决这段代码吗?
sub printFilePdf {
my $unique_id = shift;
my ($file) = "$OUTFILES/$id.html";
open(my $htmlFH, '<', $file) or die "Can't open file $file $!\n";
my $processId = open2(\*POUT, \*PIN, qq(html2ps -U -f /home/apache/cgi-bin/test/html2psrc-tst));
my @lines = <$htmlFH>;
print PIN @lines;
close PIN;
my @psLines;
while (<POUT>)
{
chomp;
push(@psLines,$_);
}
waitpid $processId, 0;
$processId = open2(\*POUT, \*PIN, qq(ps2pdf -sPAPERSIZE=letter - -));
print PIN "$_\n" foreach(@psLines);
close PIN;
my @pdfLines;
while (<POUT>) {
chomp;
push(@pdfLines, $_);
}
waitpid $processId, 0;
#Insert Code Here
print "Content-Type: application/pdf\n";
print "Content-Disposition: attachment; filename=driverhistoryrecord.pdf\n\n";
print "$_\n" foreach(@pdfLines);
}
答案 0 :(得分:0)
PDF :: Tk并不完全直观,<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.+</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.+</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.3</version>
</dependency>
执行call_pdftk($INPUT, $OUTPUT, @ARGS)
...您可以从man pdftk获取有关向@ARGS提供内容的帮助。
pdftk $INPUT @ARGS output $OUTPUT
或者,您可能需要查看支持my $pdftk = PDF::Tk->new;
$pdftk->call_pdftk(\$PDF_AS_STRING, \$OUT, 'background', 'bg.pdf');
print "Content-Type: application/pdf\r\n";
print "Content-Disposition: attachment; filename=done.pdf\r\n\r\n";
print $OUT;
和<body background="bg.jpg">
功能的HTML::HTMLDoc内容。
set_bodyimage($image)