Can I print html files (with images, css) from the

2019-03-27 16:36发布

问题:

I want to print styled html pages with their images from a script. Can anyone suggest an open-source solution?

I'm using linux (Ubuntu 8.04) but would be also be interested in solutions for other operating systems.

回答1:

You could give html2ps a try, it is written in Perl, so I guess it wil run on any operating system that runs Perl. It does support CSS and images. It does not render as good as you may perhaps want.

To use in Debian/Ubuntu sudo aptitude install html2ps and then pipe the output to lpr to print:

html2ps \
    http://stackoverflow.com/questions/286583 \
    |lpr

Or pipe the output to ps2pdf to convert to a pdf file:

html2ps \
    http://stackoverflow.com/questions/286583 \
    |ps2pdf - stackoverflow.pdf


回答2:

You have a ton of options: html2ps, html2pdf, a huge list at: http://www.hypernews.org/HyperNews/get/www/html/converters.html

But personally I would recommend going with htmldoc it does postscript, PDF and is up to date (most recent release was <2 weeks ago. You'll need to use a tool like wget or elinks to actually download the HTML file and it's components.



回答3:

If your install has kde on it then you could launch konqueror and use dcop or dbus to send commands to it. It means that you have to have x running though, which may not work for you.



回答4:

I´m not sure if this code works with mono, but it should work with Windows and the "real" .NET Framework at least: http://pietschsoft.com/post/2008/07/C-Generate-WebPage-Thumbmail-Screenshot-Image.aspx