mdBook icon indicating copy to clipboard operation
mdBook copied to clipboard

Exporting to PDF and ePub

Open kravemir opened this issue 6 years ago • 19 comments

Does mdBook support exporting to PDF and ePub? If not, then this is a feature request/suggestion, otherwise documentation request/suggestion.

kravemir avatar Nov 04 '18 10:11 kravemir

I found https://github.com/lise-henry/crowbook. It might be worth it to take a look and integrate it (I'm not Rust developer). Also, that was my first google search result, there might be better tools/libraries.

kravemir avatar Nov 04 '18 11:11 kravemir

A while back I created an alternate backend for generating EPUB documents and published it on crates.io. It's pretty rough around the corners and doesn't do any styling, but I'd be happy to help mentor people if they want to take over development.

mdbook has a pretty good plugin architecture (docs), so it's also quite possible to write your own backend if you want.

Michael-F-Bryan avatar Nov 04 '18 12:11 Michael-F-Bryan

Would be nice to have! I heard some people migrating from mdBook to another solutions, some proprietary exactly because of the missing export to PDF.

XVilka avatar Aug 16 '19 06:08 XVilka

I'm not too involved in mdbook development these days, but if someone wants to help work on mdbook-epub I'd be happy to add them as a collaborator.

Michael-F-Bryan avatar Aug 19 '19 05:08 Michael-F-Bryan

There is also mdproof for generating PDFs from Markdown files. Maybe it can be integrated with mdBook?

XVilka avatar Aug 19 '19 05:08 XVilka

I'm currently working on mdbook-latex, a backend for mdbook that aims to support LaTeX and PDF exports. It's primarily built upon pulldown-cmark, Tectonic, md2pdf, and a lot of other great programs.

Here is The Rust Programming Language PDF and LaTeX files generated by mdbook-latex:

The Rust Programming Language.pdf The Rust Programming Language.tex

On my Thinkpad x220, it took 4.757 seconds to generate the LaTeX, and 1 minute 8.62 seconds to generate the PDF (so it won't break any speed records). And there are typesetting errors aplenty that I plan to fix in future releases.


I'm very new to Rust (and programming in general), so there are a lot of things that can be improved upon (and a better alternative PDF exporter is almost certainly possible!). Pull requests, forks, and plain old copy-pasting are actively encouraged!

There is also a roadmap to the stable release for mdbook-latex.

For anyone else looking to making a PDF or LaTeX mdbook backend, mdbook-epub and crowbook are two programs that are super helpful for learning how to parse markdown or write a proper backend. The mdbook User Guide has a terrific section regarding that as well!

lbeckman314 avatar Aug 20 '19 04:08 lbeckman314

+100500 for Tectonic. They seem to improve based on arXiv dataset testing, along with better integration with texlab.

XVilka avatar Aug 20 '19 04:08 XVilka

That's awesome! I'll check out mdproof as well, It would be great to have the option to skip any LaTeX dependencies if you wanted a quick and simple PDF.

lbeckman314 avatar Aug 20 '19 05:08 lbeckman314

Note, there is ongoing effort to Oxidize the Tectonic, and ditch legacy C code out of its engine. After this is done, probably better integration will be possible.

XVilka avatar Sep 30 '19 06:09 XVilka

That's a feature I'd definitely love to see. Currently I'm using R's Bookdown and blogdown to author books and blogs. I wish there will be similar implementations of these packages in Rust.

I'm current learning Rust, and I hope I can contribute to this feature (probably in the summer when I have a good understanding of Rust).

TianyiShi2001 avatar Mar 02 '20 21:03 TianyiShi2001

This is a duplicate of #88 (Support ebooks and pdf export)

heyakyra avatar Apr 29 '20 20:04 heyakyra

That's a feature I'd definitely love to see. Currently I'm using R's Bookdown and blogdown to author books and blogs. I wish there will be similar implementations of these packages in Rust.

I'm current learning Rust, and I hope I can contribute to this feature (probably in the summer when I have a good understanding of Rust).

How is progress? I'm waiting for it.

magj2006 avatar May 22 '20 00:05 magj2006

@lbeckman314 I would want to donate for your efforts, and I think many others as well. Could you please setup a an account for that? GitHub Sponsors, OpenCollective, etc

XVilka avatar Jun 10 '20 10:06 XVilka

Since there is zero interest to support that in mdBook, I recommend a relatively new framework to create books, more flexible that commonly known Bookdown - Quarto. It's pandoc-based, thus can export to basically anything. You can see their gallery for samples how such different formats and exports look like. It's quite actively developed as well.

XVilka avatar Sep 22 '21 04:09 XVilka

Hi all! I just created a mdBook backend named mdbook-pdf for generating PDF based on headless chrome and Chrome DevTools Protocol Page.printToPDF. It depends on Google Chrome / Microsoft Edge / Chromium. The generated page are pretty much alike the one you manually printed to PDF in your browser by opening print.html or mentioned here: https://github.com/rust-lang/mdBook/issues/88#issuecomment-541337635 , but with customization of PDF paper orientation, scale of the webpage rendering, paper width and height, page margins, generated PDF page ranges, whether to display header and footer as well as customize their formats, and more, as well as automation. It supports all the platform where Google Chrome / Microsoft Edge / Chromium would work. You can check samples of the generated PDF files in the Artifacts here.

HollowMan6 avatar Jan 30 '22 03:01 HollowMan6

PDF format with Table of Contents is needed.

SteveBetter avatar May 17 '22 01:05 SteveBetter

PDF format with Table of Contents is needed.

mdbook-pdf now supports Table of Content, see: https://github.com/HollowMan6/mdbook-pdf/issues/1#issuecomment-1366157949

HollowMan6 avatar Dec 27 '22 20:12 HollowMan6

I just released mdbook-typst. While it isn't 100% done, it supports PDF output with links, bookmarks, and pdf metadata. Attached is the converted guide and a screenshot.

If you want more control, you may be interested in the other 2 projects I just released:

  • https://github.com/LegNeato/pullup/tree/main/pulldown_mdbook
  • https://github.com/LegNeato/pullup (which uses the previous)

Converted book.pdf

Screenshot 2023-11-29 at 4 54 43 PM

LegNeato avatar Nov 29 '23 20:11 LegNeato

I built mdbook-pandoc, a backend powered by Pandoc. Pandoc is quite mature and supports many output formats, including PDF (I've mainly tested LaTeX) and EPUB. Sample rendered PDF books are here.

max-heller avatar Dec 23 '23 18:12 max-heller