Live data from Hacker News

Show HN: Generate pdf with gitbook or mdbook url

github.com

21–30 of 45 posts

Re: Show HN: Generate pdf with gitbook or mdbook url

#21
post #3

Or you can just run the target in Sphinx, and get better organized output with real table of contents and indexes - it supports a huge number of output formats: https://www.sphinx-doc.org/en/master/usage/builders/index.ht... If you must use markdown, there's always https://mystmd.org which integrates directly into Sphinx, modulo minor bits of weirdness due to markdown being a mishmash of extensions.

[deleted]

Re: Show HN: Generate pdf with gitbook or mdbook url

#23
Just recently I was tasked to convert some huge html pages (with lots of small entries) into a pdf file. The requirements are "fully automated solution" and "pdf must look the same as the page when viewed in a browser". Probably takes less than five minutes, right? I thought the same.

Wrong.

Chrome/Chromium crashes due to hard coded memory limit in V8.

Firefox has no command line option for printing pdfs.

No other libraries render the pdfs correctly because they are not full-fledged web engines.

So what were my options?

1. Read/understand Chromium source, recompile to lift the memory limit.

2. Read/understand Firefox source, recompile to add a command line option.

3. Use some UI testing framework to automate pdf printing in Firefox.

Eventually I did 4, which is split the html files into smaller chunks, convert and re-combine. Of course the problem is how do you know where to split the html so that it's at the boundary of the page? The solution is to do a binary search for the number of entries to put into each chunk when the number of generated pdf pages changes. What a pain.

Re: Show HN: Generate pdf with gitbook or mdbook url

#24
I developed KeenWrite[0] with similar ideas to mdbook: typeset Markdown documents into PDF. Technically, this happens in three stages. First, the Markdown is converted to XHTML. Second, the XHTML is converted to TeX commands. Third, the ConTeXt typesetting system produces a PDF file. Both the GUI and CLI can export to PDF.[1] (This means that XHTML also can be converted to PDF.)

Like mdbook, the themes are isolated. Instead of CSS, KeenWrite themes are written in ConTeXt. There are several example starter themes.[2] A "thesis" theme would be a nice addition, but there's a problem.

Markdown lacks a standard for cross-references and citations. An open KeenWrite issue animates a possible UX solution.[3] The topic of references/citations has been discussed on CommonMark[4] without much movement. Parsing cross-references and citations would likely benefit all flexmark-java[5] integrations. KeenWrite uses flexmark-java, but I'm otherwise unaffiliated. If anyone is interested in helping, reach out (see profile).

[0]: https://keenwrite.com/

[1]: https://gitlab.com/DaveJarvis/KeenWrite/-/blob/main/docs/cmd...

[2]: https://gitlab.com/DaveJarvis/keenwrite-themes/

[3]: https://gitlab.com/DaveJarvis/KeenWrite/-/issues/145

[4]: https://talk.commonmark.org/t/cross-references-and-citations...

[5]: https://github.com/vsch/flexmark-java

Re: Show HN: Generate pdf with gitbook or mdbook url

#25

Just recently I was tasked to convert some huge html pages (with lots of small entries) into a pdf file. The requirements are "fully automated solution" and "pdf must look the same as the page when viewed in a browser". Probably takes less than five minutes, right? I thought the same. Wrong. Chrome/Chromium crashes due to hard coded memory limit in V8. Firefox has no command line option for printing pdfs. No other li…

Have you considered Playwright? It offers very straightforward APIs to do exactly this.

Re: Show HN: Generate pdf with gitbook or mdbook url

#26

Just recently I was tasked to convert some huge html pages (with lots of small entries) into a pdf file. The requirements are "fully automated solution" and "pdf must look the same as the page when viewed in a browser". Probably takes less than five minutes, right? I thought the same. Wrong. Chrome/Chromium crashes due to hard coded memory limit in V8. Firefox has no command line option for printing pdfs. No other li…

Run the browser’s native print to pdf and save the result.

Re: Show HN: Generate pdf with gitbook or mdbook url

#27
post #17
post #4

Earlier quoted context omitted.

They have become a reliable way in office & legal processes around the world in terms of fixed layouts & content immutability (in a sort of layman view. Knowing Acrobat Pro exists & PDF editing too - but I'd argue that in majority of cases its not as trivial as modifying text file or markup sources, with intention to change or forge). Correct me if wrong but Word/LibreOffice layouts could change depending on the mach…

https://en.m.wikipedia.org/wiki/PDF/A PDF/A is made especially for archival and long term preservation

It's just a useless label on the cover. PDF/A is nothing but a subset of PDF without proprietary expandability limited to what is considered to “work everywhere” when dealing with common printed matter. It adds nothing to non-existent error handling rules or parsing strategies. There are 5 different ways for an object to be found undefined/nil, but the specification is silent on whether there's any difference in meaning or handling based on the level it happens. Therefore libraries and tools do what they find most suitable, and anything generated by the numerous easy-to-use sites is potentially not quite the same as originally uploaded.

PDF resembles the state of HTML years after HTML4, it barely says what should happen in the best case.

Re: Show HN: Generate pdf with gitbook or mdbook url

#28
post #2

Sometimes I feel we're never going to be rid of PDFs. Everything can be converted into one, but you can't reliably convert from it. They're going to be here in 200 years.

I feel that there's a lot of value in how a finished PDF document is visually inflexible. This is how the document looks, and this will be how the document look in the next generation PDF viewer on a completely different computing platform of a different type of device. If it works on my machine, it works on yours, too. (This is ignoring the dynamic PDFs with javascripts in them)

It doesn't evolve with the electronic device, which means you might need to zoom and pan, but it also means that it probably won't be completely bungled.

I've bought an EPUB which only works on iPad. If the screen is sized differently, or uses a different font, etc., the texts are all messed up. It simply wouldn't happen if the book was distributed via PDF.

Re: Show HN: Generate pdf with gitbook or mdbook url

#29
post #2

Sometimes I feel we're never going to be rid of PDFs. Everything can be converted into one, but you can't reliably convert from it. They're going to be here in 200 years.

> Everything can be converted into one, but you can't reliably convert from it.

My favorite “workaround” for turning a pdf into html is to render the pdf with something like pdf.js; create a canvas, render contents, scale responsively, done. It works good enough for e.g. displaying book previews. Demo: https://merely.xyz/seven-photo-challenges/ (photo exercise ebook).

Re: Show HN: Generate pdf with gitbook or mdbook url

#30

Just recently I was tasked to convert some huge html pages (with lots of small entries) into a pdf file. The requirements are "fully automated solution" and "pdf must look the same as the page when viewed in a browser". Probably takes less than five minutes, right? I thought the same. Wrong. Chrome/Chromium crashes due to hard coded memory limit in V8. Firefox has no command line option for printing pdfs. No other li…

I use PrinceXML for converting long HTML into PDFs and haven’t had trouble with large documents, though I don’t know if we’re in the same ballpark in terms of file size or element count. It’s expensive but is a one-time purchase (and I think it’s free to use personally and to evaluate). You can also use it indirectly through DocRaptor (basically a PrinceXML SaaS with an API), though I’ve never tried it.
Post reply on HN