2016-09-26 56 views
3

我在Perl中使用Open2打印PDF,它將HTML模板打印出來,並將其打印到可通過按鈕下載的PDF中。Perl可以使用CSS將圖像打印到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; 
} 
+2

如果您使用'html2ps'從命令行生成PDF,它會顯示水印嗎? 「html2ps」是否可以訪問水印的路徑? – choroba

+0

這不是Perl的問題。 –

回答

1

忽略html2ps的包含在HTML文檔中的CSS。您可以在配置文件中定義 樣式。 html2ps僅支持CSS的一個子集。

所以你需要把它放在conf文件中。

見這個例子:https://www.w3.org/MarkUp/2008/ED-xml-events-20080624/html2ps.conf

在這個例子中,你可以BODY標籤注意到的background-image使用。

相關問題