9 ms·
Show HN: ReLaXed – High-quality PDFs using web technologies
- Ecco 8y agoHow would that compare to, say, an HTML template + wkhtmltopdf? Also I feel like the biggest gripe with generating (long) PDFs from HTML are things such as page numbering, orphans and widows, semantically correct word-wrapping, page margins, etc... Chrome does a decent job but is nowhere close to what LaTeX can do.
- jahewson 8y agoCSS paged media supports page numbering, widow and orphan control and page margins. https://developer.mozilla.org/en-US/docs/Web/CSS/Paged_Media https://developer.mozilla.org/en-US/docs/Web/CSS/Paged_Media
- zulko 8y agoI have gathered some comparisons in this wiki page: https://github.com/RelaxedJS/ReLaXed/wiki/ReLaXed-vs-other-solutions https://github.com/RelaxedJS/ReLaXed/wiki/ReLaXed-vs-other-s... It is open to contributions, so any thoughts welcome. In a nutshell, all your points are valid. Chrome is one of the best browsers, but still behind LaTeX in some aspects. But which will evolve faster in the future ?
- netheril96 8y ago> But which will evolve faster in the future ? Are you comparing Chrome and LaTeX? Chrome is certainly evolving faster overall, but features related to PDF printing have not changed much, or any at all.
- spronkey 8y agoI'd suggest there's quite a lot more inertia to overcome with Chrome (or any HTML/CSS-based tech) to get improvements in print features than with a non-web tech... But hey, no reason not to try :)
- tingletech 8y ago> Also I feel like the biggest gripe with generating (long) PDFs from HTML are things such as page numbering, orphans and widows, semantically correct word-wrapping, page margins, etc... a blog about this issue: http://www.pagedmedia.org http://www.pagedmedia.org
- wyas 8y agoVery cool. Could standard Latex mathmode be used here?
- zulko 8y agoMathjax notation is supported: https://www.mathjax.org/ https://www.mathjax.org/ See some basic use in ReLaXed in the "paper" or "slideshow" examples, or here for a basic documentation: https://github.com/RelaxedJS/ReLaXed/wiki/Features#equations https://github.com/RelaxedJS/ReLaXed/wiki/Features#equations
- williamscales 8y agoHow does this compare with Prince?
- evilduck 8y agoFor one, everything here appears to be free and open source. Prince is pretty costly to run as a small endeavor and last I knew their pricing model wasn't very kind to horizontal scaling.
- zrail 8y agoDocRaptor is PrinceXML as a service with reasonable pricing. https://docraptor.com https://docraptor.com
- exhilaration 8y agoDocRaptor is great. We used it for generating invoices for several years until our volume justified buying Prince and running it locally.
- deedubaya 8y agoCheck out https://breezypdf.com https://breezypdf.com, which is reasonably priced with horizontal scaling.
- zulko 8y agoPrince is a 3800$ software. Prince seems to encourage XML/HTML/CSS for writing documents, and I didn't like this. With ReLaXed I am trying to show that Pug/SCSS makes document writing much more natural. Where Prince wins is in its support for CSS @page extensions (having pages with different margins etc.), it looks much more adapted to professional publishing. There are certainly many more advantages related to typography but I don't know them. Link to Prince: https://www.princexml.com https://www.princexml.com
- SigmundA 8y agoLooks like it uses headless chrome for HTML to PDF conversion so its not going to support advanced print CSS like Prince. Real issue is Prince is the only browser that supports full print CSS, none of the major browsers seem to care about better print output anymore.
- deleted 8y ago[deleted]
- killercup 8y agoWaiting to see an example with footnotes and auto references ;)
- zulko 8y agoI am thinking about it and there may be a way to do it using Pug mixins (like LaTeX macros). Also, ReLaXed supports Markdown-it, which in turn has plug-ins for footnotes and citations, for instance. Not sure what you mean by auto-reference, but that should be possible, like in any other HTML page, wouldn't it ?
- Drdrdrq 8y agoNot OP, but one of the most useful things about wkhtmltopdf is its ability to create an index page (edit: TOC) with references to all heading tags (<h1>,...). Is this something that can be done with ReLaXed?
- zulko 8y agoYour PDF will automatically reference the h1, h2, etc, as sections and subsections in your PDF (i.e. you should see them in the sidebar's document tree in PDF viewers that have such a feature). You can also certainly generate a TOC using some javascript framework. For a quick google search I found this: https://css-tricks.com/automatic-table-of-contents/ https://css-tricks.com/automatic-table-of-contents/
- sebazzz 8y agoThat will probably be difficult because Chrome just "prints" a PDF. Therefore headers, footers, footnotes, and page numbering is a difficult issue to solve.
- alexwebb2 8y agoFYI, Puppeteer does indeed support header and footer templates when printing to PDF: https://github.com/GoogleChrome/puppeteer/blob/v1.3.0/docs/api.md#pagepdfoptions https://github.com/GoogleChrome/puppeteer/blob/v1.3.0/docs/a...
- foobaw 8y agoHow do we pronounce this? Re-LACKED?
- fmntf 8y agoProbably. People is abusing the X letter (do they know that it is not pronounced anymore as "ki" in modern greek?).
- Mediterraneo10 8y ago> Do they know that it is not pronounced anymore as "ki" in modern greek? They may know that, but it is irrelevant. English lacks the phoneme /x/ and the usual substitution in assimilating foreign words (or the letter-play that Donald Knuth started with TeX) is the closest unvoiced velar that English has: /k/. See how most English speakers pronounce the name of J. S. Bach as [bak], with only a small number of pedants saying [bax]. Or, outside of Scotland, Loch Ness is usually [lɔk], not [lɔx].
- thangalin 8y agoHow does this improve upon Pandoc? https://i.imgur.com/tMkMjNV.png https://i.imgur.com/tMkMjNV.png In the image, ConTeXt generates PDFs. The EA box represents HTML documentation exported from Enterprise Architect, but could be any structured document that pandoc can parse. The source repository contains various themes for the final PDF. Using ConTeXt offers several compelling features, such as: citations, cross-references, and ability to produce EBPUBs.
- baby 8y agoI'm not sure I understand the image, but to my knowledge you can't just do any html -> pdf with pandoc.
- maxerickson 8y agoI have no idea how well it works, but pandoc supports html as an input format (if I understand right, it supports most/all input->output pairs).
- omnimus 8y agoI believe they generate Latex fromh html and pdf from latex.
- lahcim8 8y agoWould you happen to know the origin of this diagram? I like the font and overall style.
- vorpalhex 8y agoPandoc ultimately either has to move the html through another markup format such as laTeX or uses a plugin that attempts to convert html4 to pdf code. This uses a full browser rendering engine that supports modern html5/css3/js by ultimately running a headless browser. I suspect pandoc is still a great approach for a lot of cases. Running a headless browser isn't cheap, especially at scale. If your output is a simple book or an invoice, pandoc is probably the way to go. If you want to pdf websites or dump an html file with charts into a pdf, use this.
- pritambaral 8y agoGiven that some of the usecases are to print books, and that this internally uses HTML and CSS< would there be an officially supported way to publish ePubs?
- zulko 8y agoReLaXed really focuses on PDFs right now (to keep the initial focus small) but it produces an HTML file as a byproduct. From what I understand there is not far from an HTML file to an Epub. This being said, the primary goal of this library is to enable to make documents with complex or fancy layouts. Epubs generally have a simple structure (chapter/section/paragraph) and can be written using for instance Markdown: https://pandoc.org/epub.html https://pandoc.org/epub.html
- lkurusa 8y agoInteresting project! Can this be used to potentially include JavaScript in resulting PDF files and use them to animate images in the PDF? This would be useful for some presentations I think.
- zulko 8y agoYou can include Javascript in the pages, but it won't be animated in the end. Maybe you would be interested by this project to make slideshows with Pug/SCSS/Vue.JS. There you can make plenty of animations: https://zulko.github.io/eaglejs-demo/#/ https://zulko.github.io/eaglejs-demo/#/
- lkurusa 8y agoThank you! That is a brilliant suggestion indeed.
- deleterofworlds 8y agoThis is neat, but perhaps switching the final typesetting engine from chromium's PDF printer to LaTex (via Pandoc maybe) would make it more useful. You'd get more control over things like page numbering and TOCs, plus good justification/microtypography, which is important to most publishers.
- leephillips 8y agoThe examples lack hyphenation, which partly explains the too-variable interword spacing. Is this because Chrome still fails to support hyphenation, unlike, for example, Firefox? There are other subtle defects, which make these PDFs pretty good, but not high quality. Here is a brief discussion of some of the shortcomings of web typography, and why we still need to use TeX if we want the most beautiful and easiest to read results: https://lwn.net/Articles/662053/ https://lwn.net/Articles/662053/ All that aside, this is impressive and should be useful to many people.
- zulko 8y agoHyphenation can be tuned via CSS but I have never been happy with it: https://www.w3schools.com/cssref/css3_pr_word-break.asp https://www.w3schools.com/cssref/css3_pr_word-break.asp From what I remember LaTeX has better algorithms, both in how to distribute words between lines, and in knowing where in a word it is ok to cut.
- taeric 8y agoFor anyone that wants to have a good read, try reading the TeX-book's section on hyphenation. Tons of fun that goes over some of the difficulties. As a fun trivia, think where to hyphenate the word record. In all forms.
- ximeng 8y agohttp://www.ctex.org/documents/shredder/src/texbook.pdf http://www.ctex.org/documents/shredder/src/texbook.pdf Page 449
- leephillips 8y agoAs recently as a year ago, Chrome support of automatic hyphenation only worked on some platforms. If the support is better now, I'm glad to hear it.
- blaisio 8y ago
- buildbuildbuild 8y agoI find Markdown most natural for writing because I do not have to worry about formatting or syntax. Currently I deliver ~2 PDF reports per week using Ulysses or MacDown for content creation (distraction-free writing), and then typesetting everything into InDesign. Thank you for creating this tool, I will try it next week. The ability to render Markdown to Pug as an "Import Markdown" feature would be key for many people to adopt this.
- zulko 8y agoInline markdown and external markdown files are both supported. Have a look at the "Book" example. Every chapter is in its own Markdown file. Most of the other examples have parts where I simply switch to markdown. I am also a big markdown user and I have found that for writing reports all day long markdown clearly wins over Pug, in particular with tools like https://atom.io/packages/markdown-preview-enhanced https://atom.io/packages/markdown-preview-enhanced But the day where you need to produce a super-nice report with a bit of custom layout, Pug/SCSS is awesome.
- buildbuildbuild 8y agoCompletely missed that. Thanks, will try.
- nateroling 8y agoRelated, why doesn't anyone ever mention [Apache FOP](https://xmlgraphics.apache.org/fop/ https://xmlgraphics.apache.org/fop/) for this kind of thing? I've had great success with it.
- ghrifter 8y agolol markdown linking on HN
- jakear 8y agoNot sure if this is related to the format of the PDF somehow, but my computer completely froze when trying to open the Alice pdf in the GitHub viewer. This is on Safari, Chrome was fine.
- jakear 8y agoUpon further inspection, the GitHub renderer works fine on PDF's much larger [1], and the native Safari PDF viewer opens these PDF's fine. I suspect there is something the GitHub renderer, your pdf generator, and Safari's js engine disagree on. [1]: https://github.com/mynane/PDF/blob/master/Docker%20——%20从入门到实践%20-%20v1.0.pdf https://github.com/mynane/PDF/blob/master/Docker%20——%20从入门到...
- deedubaya 8y agoReally beautiful stuff! I'm in the process of launching BreezyPDF.com which can generate equally as wonderful PDFs from the HTML/JS/CSS you're already using. Here's a demo of turning a complex dashboard into a PDF: https://ruby.demo.breezypdf.com https://ruby.demo.breezypdf.com
- baby 8y agoDoes it support things like mathjax? This is a really important question to me.
- aidangarza 8y agoAccording to this example in their repo, it does indeed support mathjax: https://github.com/RelaxedJS/ReLaXed-examples/blob/master/examples/slides/slides.pdf https://github.com/RelaxedJS/ReLaXed-examples/blob/master/ex...
- kaycebasques 8y agoWhen I saw "... using web technologies" I was curious if it uses Puppeteer. package.json confirms that is indeed the case. https://github.com/GoogleChrome/puppeteer https://github.com/GoogleChrome/puppeteer (I work for Chrome DevTools team, creators of Puppeteer)
- nightmunnas 8y agoHappy serendipity!
- mrskitch 8y agoI was wondering the same as it’s a common use-case for the project I run (browserless.io). Seems to be a big demand for sane PDF rendering and generation. Been pretty interesting seeing webtech handle these kinds of problems
- che371291 8y agoSeems kind of neat. But for my purposes I will still use Markdown to PDF using pandoc etc. What really upsets me... the typography still looks shit compared to LaTeX... MS Word / LibreOffice can do better. Would rather stick with plaintext again.
- kevin_thibedeau 8y agoFOP is the only TeX alternative that can get close to it on basic typography in a FOSS implementation. I had a toolchain that ran ReST -> Docbook -> XSL-FOP -> PDF but the hard drive it was on bit the dust and I haven't gotten around to recreating it. Still much more pleasant than wrestling with LaTeX's rigid predetermined layouts. The result was nice and didn't have the crusty PDF LaTeX appearance.
- blattimwind 8y agoWell there are a bunch other engines out there, but it just so happens they all eat tex or something very close to it (context). Five or six years or so ago I used reportlab (in Python) to generate some PDF reports (using the flowables API); it does kinda work but layout is more complicated than in tex and output quality is several notches down. As far as appearance goes, you can make tex look like almost anything, even with fairly low effort.
- deleted 8y ago[deleted]
- nmca 8y agoThis looks nice - as a regular latex user, I'd say it (latex) sits roughly between excruciating agony and the actual worst thing in the world. So the beginnings of an alternative looks great!
- agussell 8y agohttps://github.com/bramstein/typeset https://github.com/bramstein/typeset This is an implementation of the line breaking algorithm used in TeX in Javascript. It would be nice to add to obtain better typographic results with justified text.
- omnimus 8y agoOh how much i would love to have good way how to generate print quality PDFs. The real problem is not hyphenation but how lines are composed. If you want even lines in type set to block then there is probably only Adobe Indesign and LaTeX anything else uses "single line composer" i dont know the algorythm but Latex and Indesign are only ones which take multiple lines into considiration. Latex is sort of Okay but the algorythm in Indesign is still highly superior. I suspect that is some Adobe secret sauce. Pity because you cant run indesign on server, you have it open and use "extendscript" their version of old ECMAScript 3 :(
- rayiner 8y agoThis thesis has a good discussion of the issue. Pages 15-16 discuss Adobe’s secret sauce (though it is secret). https://www.tug.org/TUGboat/tb21-4/tb69thanh.pdf https://www.tug.org/TUGboat/tb21-4/tb69thanh.pdf
- lobster_johnson 8y agoHave you looked at Prince [1]? It's commercial, but highly regarded. The coolest project I've seen with it is OMA (Rem Koolhaas' architecture firm), which uses it to print internal, very professional-looking booklets automatically generated from data, text and photos stored in Sanity [2]. (The Sanity team also built the system to make the booklets.) [1] https://www.princexml.com https://www.princexml.com [2] https://www.sanity.io/docs/introduction/what-the-headless https://www.sanity.io/docs/introduction/what-the-headless
- omnimus 8y agoI know about it but it is pretty expensive so i never gave it any thought. I am not sure if i can test it anyhow. It is probably nobrainer if you are generating pdfs all the time but i would have to use it on multiple projects to make it financially possible. Funnily enough right now i am working on archive for architecture company. But thats like 100 pdfs.
- lobster_johnson 8y ago
- Wehrdo 8y agoLooks like the perfect solution to my resume. The latest iteration is in HTML/CSS, because it allowed me to easily get the exact layout I wanted (so painful in LaTeX...), but getting a consistent PDF was a challenge.
- felixfbecker 8y agoAll I want is a system that gets the basic right and is version-controllable in git (plain text source code). Latex is just ridiculously complex and inconsistent. Even after years of using it, I have to google how to do most things every time. I would prefer a simple PDF generator that uses pug/HTML (which I know by heart) any day.
- Klasiaster 8y agoI produce all my PDFs with pandoc's markdown and in-line html: letters, slides and papers with citations. Depending on whether I need mathjax I use wkhtmltopdf or chromium (JS-based hypens with Hyphenopoly) or just http://weasyprint.org/ http://weasyprint.org/ if no JS is involved. This pug language seems to be a good alternative to intermixed markdown+html.
- czechdeveloper 8y agoLooks awesome. Can it use CMYK colors? That is killer feature for print centers.
- prueba4 8y agoIneresting!