HTML::HTMLDoc如何包含base64 img。

时间:2021-08-04 21:12:21

I am trying to include either a base64 image or a src="getImage.pl?image.jpg" when creating a PDF with HTML::HTMLDoc. No Luck.

我正在尝试将一个base64图像或src="getImage.pl?image.jpg"包括在HTML::HTMLDoc中创建PDF。没有运气。

Does anybody have experience with this module and have some wisdom to share?

有没有人对这个模块有经验并且有一些分享的智慧?

Thank You, ~D

谢谢你,~ D

+-------------------------------------------------+

+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +

#!/usr/bin/perl
use HTML::HTMLDoc;

$html = new HTML::HTMLDoc('mode'=>'file', 'tmpdir'=>'/tmp'); # Start instance

$html->set_page_size('letter'); # set page size
$html->set_bodyfont('Arial');   # set font
$html->set_fontsize(8.0);       # set fontsize
$html->set_permissions('no-copy'); 
$html->set_permissions('no-modify');
$html->set_permissions('no-annotate');

$html->set_html_content(
qq{
<html><body>Hello World...
<br />
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4QAWRXhpZgAATU0AKgAAAAgAAAAAAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCABeAF4DASIAAhEBAxEB/8QAHAAAAQUBAQEAAAAAAAAAAAAABQIDBAYHCAEA/8QAQRAAAQMDAwEFAwkFBgcAAAAAAQIDBAAFEQYSITEHE0FRYRQycRUiQlKBkaHB0QgjYnOxFhckM1NyRGOSk6Lh8f/EABkBAQEAAwEAAAAAAAAAAAAAAAABAgMEBf/EACYRAAIBAwIGAgMAAAAAAAAAAAABAgMEEQUhEiIxQVFhE3EjkfD/2gAMAwEAAhEDEQA/ANkQeTnkmnkbcYOKjklIJ5GB5UPVdUISjeptK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p1tvvOBxgUB//9k=" border="0" alt="Hello Image">
</body></html>});
$html->title();
$html->set_header('.', 't', '.');
$html->set_footer('D', '.', '/');

$pdf = $html->generate_pdf(); # generate document

$http_headers_out{'Content-Type'} = 'application/pdf';

print $pdf->to_string();

1 个解决方案

#1


0  

It looks like HTML::HTMLDoc will NOT handle img src from base64 data NOR a cgi script.

它看起来像HTML::HTMLDoc不会从base64数据或cgi脚本中处理img src。

There was a great response to this question here: http://www.perlmonks.org/?node_id=1081554

对于这个问题,有一个很好的回答:http://www.perlmonks.org/?node_id=1081554。

#1


0  

It looks like HTML::HTMLDoc will NOT handle img src from base64 data NOR a cgi script.

它看起来像HTML::HTMLDoc不会从base64数据或cgi脚本中处理img src。

There was a great response to this question here: http://www.perlmonks.org/?node_id=1081554

对于这个问题,有一个很好的回答:http://www.perlmonks.org/?node_id=1081554。