Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

HTML::HTMLDoc -- Including a base64 img

by djlerman (Sexton)
on Apr 08, 2014 at 18:50 UTC ( #1081542=perlquestion: print w/replies, xml ) Need Help??

djlerman has asked for the wisdom of the Perl Monks concerning the following question:

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.

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

Thank You, ~D

#!/usr/bin/perl use HTML::HTMLDoc; $html = new HTML::HTMLDoc('mode'=>'file', 'tmpdir'=>'/tmp'); # Start i +nstance $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/4QAWRXhpZ +gAATU0AKgAAAAgAAAAAAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEh +EPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBE +UHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/ +wAARCABeAF4DASIAAhEBAxEB/8QAHAAAAQUBAQEAAAAAAAAAAAAABQIDBAYHCAEA/8QAQ +RAAAQMDAwEFAwkFBgcAAAAAAQIDBAAFEQYSITEHE0FRYRQycRUiQlKBkaHB0QgjYnOxFh +ckM1NyRGOSk6Lh8f/EABkBAQEAAwEAAAAAAAAAAAAAAAABAgMEBf/EACYRAAIBAwIGAgM +AAAAAAAAAAAABAgMEEQUhEiIxQVFhE3EjkfD/2gAMAwEAAhEDEQA/ANkQeTnkmnkbcYOK +jklIJ5GB5UPVdUISjeptKlJCsbFeNUBoAAcYNRZrqWWVOKSS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2ox8BT6QfMY8hSynKQelJ6HgCmANqGVeH3V4EDzpxXHBp1tvvOBxgUB//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();

Replies are listed 'Best First'.
Re: HTML::HTMLDoc -- Including a base64 img
by kcott (Archbishop) on Apr 08, 2014 at 20:19 UTC

    G'day djlerman,

    I ran a few tests:

    • Your HTML (<html>...</html>) by itself renders with an image.
    • Your code, as written, generates PDF without an image: I tried with both piping to xpdf and redirecting to a file and opening that file with two different PDF viewers.
    • I saved the image (from the base64 data) generated in the pure HTML test as a JPEG file and used that filename in the src attribute in your code: the generated PDF still had no image.
    • I also tried replacing the to_string() method with the to_file() method: again, PDF had no image.

    There are 22 new/open bugs (raised at various times over the last decade): Active bugs for HTML-HTMLDoc.

    The current version (0.10) was written 9 years ago. There was a developer release (0.11_01) 5 years ago. Here's a list of releases.

    Maintainance of this module appears to have been abandoned. The author didn't even reply to this (from 5 years ago): Bug #47649 for HTML-HTMLDoc: Question about maintenance for HTML::HTMLDoc.

    You can raise a bug report but I wouldn't hold my breath waiting for a fix.

    In your situation, I'd probably be looking for an alternative solution that didn't involve this module.

    -- Ken

      Thank You!!!

      This is amazingly helpful and I'm sure it will come it handy to others as well.

      ~Donavon

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1081542]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2022-06-27 11:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (88 votes). Check out past polls.

    Notices?