Printing from html - Page 1
Forum section: electronics / general

author: westfw
author_rank: Super Contributor
timestamp: October 10, 2022, 09:20:47 am
content: What tools are there for printing (or,perhaps converting to pdf) snippets of html? (That aren’t full web browsers.)Something multi platform would be great.You can assume that the html is “printable”, containing text (with funny html characters like &nbsp), font, face, and color settings….

author: sokoloff
author_rank: Super Contributor
timestamp: October 10, 2022, 09:28:26 am
content: I’d look into a browser rendering engine (Blink and similar), using headless Chrome, or one of the browser automation tools.It’s a bit hard to answer your question because on the spectrum of “can read and correctly interpret html” and “but isn’t a full browser” it’s hard to know what part of full browser you’re trying to avoid.

author: voltsandjolts
author_rank: Unknown
timestamp: October 10, 2022, 09:39:02 am
content: Maybe you're looking for an XSLT processor, although I don't know to what extent that would support the HTML tags you want.

author: Hogwild
author_rank: Regular Contributor
timestamp: October 10, 2022, 05:04:24 pm
content: MS Word has been able to import HTML for a long time. It may mangle things a little, so I'd do some quick tests to verify.There are things like this (written in pure .js):https://github.com/eKoopmans/html2pdf.js

author: boB
author_rank: Frequent Contributor
timestamp: October 10, 2022, 05:22:45 pm
content: I use the Fireshot plugin. It may be free too but I gave them like, $20 or $30 for lifetime support.I tried MANY different things to be able to print HTML pages and this is the only thing I found that works well.The mode I normally use is to save as PDF though. I have successfully printed at least a couple hundred pages of forum posts.I find that print to PDF from windoze only works for the simplest of pages.https://getfireshot.com/It will also save as text and links when it can.boB

author: Picuino
author_rank: Super Contributor
timestamp: October 10, 2022, 05:22:48 pm
content: I use phantomjs to automatically convert (with makefiles) from HTML source code to an image.https://phantomjs.org/"""PhantomJS is a headless web browser scriptable with JavaScript. It runs on Windows, macOS, Linux, and FreeBSD.Using QtWebKit as the back-end, it offers fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.The following simple script for PhantomJS loads Google homepage, waits a bit, and then captures it to an image.var page = require('webpage').create();page.open('http://www.google.com', function() {setTimeout(function() {page.render('google.png');phantom.exit();}, 200);});PhantomJS is an optimal solution for:Page automationAccess webpages and extract information using the standard DOM API, or with usual libraries like jQuery.Screen captureProgrammatically capture web contents, including SVG and Canvas. Create web site screenshots with thumbnail preview.Headless website testingRun functional tests with frameworks such as Jasmine, QUnit, Mocha, WebDriver, etc.Network monitoringMonitor page loading and export as standard HAR files. Automate performance analysis using YSlow and Jenkins."""

author: Picuino
author_rank: Super Contributor
timestamp: October 10, 2022, 05:31:08 pm
content: List of headless web browsers:https://github.com/dhamaniasad/HeadlessBrowsers

author: ledtester
author_rank: Super Contributor
timestamp: October 10, 2022, 05:48:11 pm
content: Also check out Prince:https://www.princexml.com/Cross platform and runnable from the command line. "It's free to download Prince software for non-commercial use."

author: voltsandjolts
author_rank: Unknown
timestamp: October 10, 2022, 06:38:08 pm
content: Well, this is turning out to be a bit of a partyMore FOSS options:https://weasyprint.org/https://pandoc.org/

author: boB
author_rank: Frequent Contributor
timestamp: October 10, 2022, 07:53:11 pm
content: Here is an example of Fireshot if you want to take a look.Just captured this particular page to PDF here...Well.. Not a great example because just ^P and printing to PDF appeared to work just fine here.

author: DiTBho
author_rank: Super Contributor
timestamp: October 11, 2022, 07:56:00 am
content: what if a page contains tons of crappy JavaScript?the browser of my new 2022 kindle is unable to correctly show some html documentsyeah, modern web sucks!

author: westfw
author_rank: Super Contributor
timestamp: October 11, 2022, 09:09:20 am
content: Like I said, “assume the html is printable.”The actual thing I’m looking at is Arduino’s “copy to html” command, which does a fine job of creating a formatted and colorized source code snippet. As oppose to its “print” command, which is unbelievably crappy. Apparently the “copy” function uses some common library for tokenizing input to colorized html, but doesn’t do other “printer friendly” formats.Cross-platform standardized printing seems to have deteriorated since the days you could send 132 column output to a line printer with a bit of Fortran code, and have it be portable…

author: Warhawk
author_rank: Frequent Contributor
timestamp: October 11, 2022, 09:30:22 am
content: Quote from: westfw on October 10, 2022, 09:20:47 amI am not sure if you're asking for printing the HTML tags or parts of the webpage. For parts of the websites I use this:https://www.printfriendly.com/I started backing up different tutorials and forum snippets if I find something I may need in future (e.g. Mikrotik Router know-how, etc.).

author: JustMeHere
author_rank: Frequent Contributor
timestamp: October 16, 2022, 06:57:56 pm
content: I've never encountered something that does a perfect job. That is for PostScript and PDF. HTML is just way too open to "interpretation" by the rendering agent.Adobe had their Distiller product which was good, but expensive, and I believe long gone.iText has a product I haven't used.These days all OSes have some type of print driver that outputs PDFs.

author: DiTBho
author_rank: Super Contributor
timestamp: October 17, 2022, 04:19:39 pm
content: I wrote a program that takes c code in input and outputs a colorured pdf..It was usesul to include the sources into my thesis.I can adapt it for hrml, with or without a cssUmm. Latek should have a similar module

author: AndyBeez
author_rank: Frequent Contributor
timestamp: October 17, 2022, 04:45:35 pm
content: Define 'html' on a web page. Many web pages are now dynamically generated from Javascript frameworks feeding off of JSON callbacks. In English, the 'page source' is just links to Google and Github APIs. Only the browser's developer mode can reveal the true shape and context of the web page, after the page framework has achieved a 'post render' state.If you want to 'pretty print' html, most web developer IDEs will pretty print code snippets to a target output.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: October 17, 2022, 04:48:14 pm
content: What's really wrong with a browser, you're using one right now, everyone has one?IIRC, most browsers have command line options, that aren't obvious since you normally just use it plain, but a perusal of those features might yield a ready-to-go solution. Otherwise the "headless" suggestions above sound promising.Don't know if \$\LaTeX\$ has a more fancy (auto language parsing / coloring) package for that; probably. Well, maybe a big PITA to write language parsers in TeX for whatever languages people want... but technically possible, at least.See also Doxygen, which I think? uses HTML or LaTeX backend depending on desired output formats. Also don't know if coloring is implemented.Tim