Live data from Hacker News

Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

news.ycombinator.com

31–40 of 58 posts

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#33
I think Pandoc and Calibre could work for you.

I've worked on PAIP, Paradigms of Artificial Intelligence Programming, and I might be able to help you a bit. It's around 1k pages long. I used Pandoc to generate an epub file, and then Calibre to turn that into a PDF file. I just tried using Pandoc to generate the PDF file directly, and it/LaTeX choked on some Unicode characters.

For internal ebook links, there's a Lua script. You'll have to keep anchors unique across the book for this:

* good: "chapter1#section1_1" and "chapter2#section2_1"

* bad: a "chapter1#section1" and a "chapter2#section1"

WIP: https://github.com/norvig/paip-lisp/pull/195

For line wrapping of code, there's CSS. I first used it over on "Writing an Operating System in 1,000 Lines"; here's the PR: https://github.com/nuta/operating-system-in-1000-lines/pull/...

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#34

Have you explored the AST (abstract syntax tree) tools yet, like Mdast and the related remark and micromark? https://github.com/syntax-tree/mdast-util-from-markdown It might work better if you parse it into an intermediary Mdast format first, do whatever processing you need to implement "pages" (not a part of any Markdown dialect I'm familiar with?" but it shouldn't be hard to write a custom parser for that in Mdast)…

I wonder how the Mdast and pandoc ASTs compare?

I did a customized-MD pipeline which normalized to pandoc (extra features got encoded to pass through pandoc), obtained the pandoc JSON ast, and emitted html/latex/etc using Julia pattern matching. The code was small, and the yak shave and husbandry was worth escaping the struggle with sea of crufty candidate tools, each with assorted one-chosen-point in a high-dimensional design space, and missing features, misfeatures, gotchas, and mazes ("maybe if I combine this unmaintained plugin with that one and add a postprocess massage step over there and then maybe..." - blech).

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#36
IMHO electron based markdown editors are generally slow, bloated, short-lived, and often platform-limited.

Use this and add sed lines for any required non-breakyness per normal CSS, rules can be specific to @media print as required.

  $ cat ~/bin/mdview 
  #!/bin/bash
  # markdown viewer
  tmpfile=.mdview.tmp-`uuidgen`.html
  # start html
  echo "img{margin:20px;max-width:100%}@media print{img{max-height:90%;max-width:90%;page-break-after:always}}body{margin:6em;font-family:sans}pre,code{font-weight:bold;font-size:110%;font-family:Ubuntu Mono}" >${tmpfile}
  # duplicate markdown for modification
  cp ${1} ${1}.mdtmp
  # add extra newline after trailing :
  sed -i -e 's/: \*$/:\r\r\n\n/' ${1}.mdtmp
  # generate HTML from markdown
  #  note the --html-no-skiphtml --html-no-escapehtml allows the preservation
  #  of  anchors within text to allow [link][#anchorname]
  lowdown --html-no-skiphtml --html-no-escapehtml -thtml ${1}.mdtmp >>${tmpfile}
  # remove the temporary markdown file
  rm ${1}.mdtmp
  # add newline before images
  sed -i -e 's/

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#37

It's not marketed as a markdown-to-pdf tool, but I've found that Obsidian ( https://obsidian.md ) does an excellent job. Just create a new "vault", paste your markdown into a new note, and export to PDF.

I love Obsidian too, however I found that internal links didn't work when exporting it. Do you know what format works? My internal links work in the Obsidian preview but not in the PDF export.

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#38
post #26

If you’re on a Mac or iOS you could try creating a Shortcut where you input Markdown, convert to rich text, then output as a PDF. I use Shortcuts regularly. It’s pretty easy to set up. I haven’t tried it on something as larger as 500 pages, though. YMMV

I'm on Windows (with WSL) so unfortunately I can't.

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#39

I would love to read your feedback how it works with MonsterWriter. 1. Download the app [01] 2. Create a new empty document 3. Insert a markdown section type 4. past your markdown code into the markdown section 5. click on "Preview & Export" 6. Configure your PDF I'm the creator of MonsterWriter. For complex markdown it probably has some shortcomings but I would love to hear what is missing for your use case. [01] ht…

Does it support code blocks for Python, JS, HTML and CSS? Also my Markdown is auto-generated by a script of mine. Can I paste Markdown directly into y our platform?

Re: Ask HN: Where are the good Markdown to PDF tools (that meet these requirements)?

#40
I've been saving Markdown transcripts of my more involved AI chats, and I was unhappy with how any tool rendered to PDF. In either Cursor or Windsurf, I had Claude 3.5 Sonnet code a Ruby script for me that converts Markdown to Typst, a LaTeX alternative that looks a lot like Markdown. Typst offers beautiful formatting control for the output PDFs.
Post reply on HN