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

PDFtoHTML Mod

by randor (Novice)
on Sep 26, 2012 at 15:25 UTC ( #995794=perlquestion: print w/ replies, xml ) Need Help??
randor has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

Im back. Well, working with TK and I am trying to figure out a solution to be able to print a page. I tried WIN32::Printer but to no avail, I kept getting error -3 "Unable to connect to printer" I tried every possible solution (I think it might have to do with the fact that all printers are on a network and none are local to me) but anyway, I have since moved onto trying to build an HTML page and convert it to PDF, then linking to it from the program so they can print it.

I am getting this error:

Tk::Error: Can't write to '\CompletedOrder.gif-3128': Permission denie +d at C:/Perl/lib/LWP/Protocol.pm line 105. at C:/Perl/lib/LWP/UserAge +nt.pm line 891. at C:/Perl/site/lib/PDF/FromHTML.pm line 141. LWP::UserAgent::mirror at C:/Perl/lib/LWP/UserAgent.pm line 891 LWP::Simple::mirror at C:/Perl/lib/LWP/Simple.pm line 91 PDF::FromHTML::Twig::__ANON__ at C:/Perl/site/lib/PDF/FromHTML/Twig.p +m line 192 XML::Twig::_twig_end at C:/Perl/site/lib/XML/Twig.pm line 2295 XML::Parser::Expat::parse at C:/Perl/lib/XML/Parser/Expat.pm line 474 XML::Parser::parse at C:/Perl/lib/XML/Parser.pm line 192 Carp::croak at C:/Perl/site/lib/Carp.pm line 100 XML::Twig::_croak at C:/Perl/site/lib/XML/Twig.pm line 2821 XML::Twig::_checked_parse_result at C:/Perl/site/lib/XML/Twig.pm line + 766 XML::Twig::parse at C:/Perl/site/lib/XML/Twig.pm line 747 PDF::FromHTML::parse_file at C:/Perl/site/lib/PDF/FromHTML.pm line 14 +1 PDF::FromHTML::convert at C:/Perl/site/lib/PDF/FromHTML.pm line 172 main::ViewSingleOrder at C:\BLABAD~1\/ViewOrder.pl line 244


I am using the following code (Taken from CPans Docs):
my $pdf = PDF::FromHTML->new( encoding => 'utf-8' ); # Loading from a file: # $pdf->load_file('source.html'); # Or from a scalar reference: $pdf->load_file(\$page_html); # Perform the actual conversion: $pdf->convert( # With PDF::API2, font names such as 'traditional' also works Font => 'font.ttf', LineHeight => 10, Landscape => 1, ); # Write to a file: $pdf->write_file('target.pdf');


Thank you
Bob

Comment on PDFtoHTML Mod
Select or Download Code
Re: PDFtoHTML Mod
by talexb (Canon) on Sep 26, 2012 at 16:25 UTC
      Tk::Error: Can't write to '\CompletedOrder.gif-3128': Permission denied at C:/Perl/lib/LWP/Protocol.pm line 105. at C:/Perl/lib/LWP/UserAgent.pm line 891.

    You should probably deal with this first error -- it looks like it's also the easiest one to deal with. Try writing to your Desktop (or somewhere that you own) instead of the root directory of your machine (which is owned by the system).

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Re: PDFtoHTML Mod
by rpnoble419 (Pilgrim) on Sep 26, 2012 at 17:56 UTC

    I use Win32::Printer everyday on network printers. The trick is to have the printer name exactly match the name of the printer queue.

    Here is sample code to print to the PDF file or the printer

    if ($PrintAsPDF==0) { our $dc = new Win32::Printer( width => $PageWidth, height => $PageHeight, description => 'Sample Description', printer => $PrinterName, orientation => $PageOrientation, unit => $Units); } else { our $dc = new Win32::Printer( width => $PageWidth, height => $PageHeight, description => 'Sample Description', printer => $PrinterName, file => $PDFFileName.'.pdf', pdf => 1, unit => $Units); }

    I usually use the rename function on the printers queue to highlight the printer name and copy it into my application configuration YAML.

    Don't forget to to install Ghostscript or you can't print a PDf file.

    From the Win32::Printer POD

    "Set this attribute if You want to convert PostScript printer drivers output to PDF format. WARNING: This feature needs installed Ghostscript and atleast one PostScript printer driver. Use this attribute with "file" or "prompt" attributes."

Re: PDFtoHTML Mod
by Anonymous Monk on Sep 27, 2012 at 01:29 UTC
    I have found that it is easy to convert from docbook to HTML and from docbook to PDF. This might be worth looking into http://www.sagehill.net/docbookxsl
Re: PDFtoHTML Mod
by Steve_BZ (Hermit) on Sep 27, 2012 at 12:35 UTC

    Hi Randor,

    Are going to or from pdf?

    If you are trying to generate a pdf doc, you could try: Wx::PdfPrinter. Admittedly it means using Wx, but I guess you could confine it to a module to:

    1. Create an html object,
    2. Load the html page into the object,
    3. create an wxHtmlEasyPrinting object and pass it to Wx::PdfPrinter.

    Maybe it's overkill for what you want.

    Good luck.

    Steve

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://995794]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-12-21 03:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (102 votes), past polls