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.
Developer Tools. The DevTools ( F12 or Cmd/Ctrl + Shift + I ) can emulate print styles, although page breaks won't be shown. In Chrome, open the Developer Tools and select More Tools, then Rendering from the three-dot icon menu at the top right. Change the Emulate CSS Media to print at the bottom of that panel.
Open a document in the HTML editor. On the main menu, click File > Print Setup. The Print Setup dialog box appears. Specify the printer, printer properties, paper size, paper source, and orientation, then click OK to accept, or Cancel to abort changes.
This rule allows you to specify different style for different media. So, you can define different rules for screen and a printer. The example below specifies different font families for screen and print. The next CSS uses the same font size for both screen as well as printer.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With