我正在使用Perl打印一个Open2,它接受HTML并将其打印到一个可以通过按钮下载的PDF中。
他们想要一个水印,所以我用
<style>
body {
background-image: url("watermark.jpg");
background-repeat: no-repeat;
}
</style>在预览页面上,它看起来很棒,但是当您将它下载到PDF时,它就消失了。我能把这个加到我的PDF里吗?
下面的PDF代码生成器
sub pdfGenerator {
my $data = shift;
my $file = "$OUTFILES/$data.html";
open(my $fileFH, '<', $file) or return "Can not find file\n";
my $processId = open2(\*POUT, \*PIN, qq(html2ps -U -f /home/dir/cgi-bin/dir2/html2psrc-label));
my @lines = <$fileFH>;
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;
print "Content-Type: application/pdf\n";
print "Content-Disposition: attachment; filename=pdfName.pdf\n\n";
print "$_\n" foreach(@pdfLines);}
我尝试过修改html2ps文件,但我仍然没有得到任何东西。我的代码在下面
@html2ps
{
paper
{
type: letter;
}
}
BODY
{
font-family: Helvetica;
margin: 2em 1em 2em 70px;
font-family: Helvetica, sans-serif;
color: black;
background-image: url("/dir/images/watermark.jpg");
background-repeat: no-repeat;
}
@page
{
margin-left: .75in;
margin-right: .75in;
margin-top: 1in;
margin-bottom: 1in;
}发布于 2016-09-27 07:58:16
html2ps忽略html文档中包含的css。可以在配置文件中定义样式。html2ps只支持css的子集。
所以你需要把它放在conf文件里。
参见本例:https://www.w3.org/MarkUp/2008/ED-xml-events-20080624/html2ps.conf
在本例中,您可以注意到background-image用于BODY标记的用法。
https://stackoverflow.com/questions/39711757
复制相似问题