yzhang-gh / vscode-markdown

Markdown All in One
https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one
MIT License
2.93k stars 325 forks source link

Exploration: export as PDF (no satisfatory solution) #875

Open yzhang-gh opened 3 years ago

yzhang-gh commented 3 years ago

Updated: 2024-04

Considering the complexity and the foreseeable outcome of the current possible solutions, we may not plan to implement this feature until there are better ways.

Users can use Markdown PDF for this missing feature.


cc #270.


install.ts https://github.com/puppeteer/puppeteer/blob/main/src/node/install.ts


Help wanted

In case anyone knows how Typora (Electron-based) generates bookmarks for headings.

https://www.electronjs.org/docs/api/web-contents#contentsprinttopdfoptions


Found a Python-based TOC generation tool https://github.com/Krasjet/pdf.tocgen

ComFreek commented 3 years ago

Note that Chrome's print-to-pdf functionality does not always retain working hyperlinks in the output PDF, see here: https://superuser.com/questions/809627/print-webpage-to-pdf-with-working-hyperlinks

Retaining hyperlinks might be a desirable feature of markdown-to-pdf, though.

yzhang-gh commented 3 years ago

As far as I know, it works well in general. (The superuser link looks quite outdated.)

dschuessler commented 3 years ago

Are you aware of https://github.com/yzane/vscode-markdown-pdf?

yzhang-gh commented 3 years ago

Yep, I know it from the very beginning. It uses Puppeteer now so it also has the problem that it doesn't generate bookmarks.

MatrixRanger98 commented 3 years ago

Why not consider pandoc? It works well with bookmarks. Check out this vscode-pandoc. Note that Typora uses pandoc to export to many formats including epub, rtf, LaTeX, docx, etc. but not PDF and HTML. I guess Typora uses the print API of Electron to export PDF? There is an open source markdown editor similar to Typora called Mark Text which seems to use this API.

Besides, FYI Markdown Extended uses Puppeteer and nbconvert of Jupyter Notebook uses both pandoc and Puppeteer (provides two versions of PDF export).

yzhang-gh commented 3 years ago

pandoc

The PDF is generated by TeX so the layout is totally different. If users want that, they already have vscode-pandoc as you mentioned...

I guess Typora uses the print API of Electron to export PDF? There is an open source markdown editor similar to Typora called Mark Text which seems to use this API.

Mark Text does use the API from Electron. But I guess it doesn't have bookmarks (unlike Typora).

https://github.com/marktext/marktext/blob/0fa6c33c44e92d0d1729d3d557d02ac7db87e73f/src/main/menu/actions/file.js#L72

MatrixRanger98 commented 3 years ago

I see what you mean. They say nothing about what Typora uses for its PDF export on their website. Maybe can try WeasyPrint. This one works well with both bookmarks and CJK.

MatrixRanger98 commented 3 years ago

Note that this one directly uses the python library pydyf to create PDFs and does not require a chromium.

yzhang-gh commented 3 years ago

WeasyPrint

Interesting. Adding to the list.

scott-parkhill commented 3 years ago

I just wanted to say that I am so happy this is under consideration because I love this extension so much, but what annoys me is having to export everything to HTML, then open the HTML in Firefox, then save the page as a PDF, and in many cases then have to use another program to merge the pdfs together into one file. I just wanted to say that I'm so happy this issue is open and I hope it's progressing well! Thank you for your work, this is a great extension!

javix64 commented 7 months ago

hey @yzhang-gh any update about this nice feature?

ruiyuanlu commented 7 months ago

Hi, any updates here?

It will be really help if pdf can be generated.

One more issue about the markdown-pdf extension is the lack of math formula conversion support.

Although this issue can be fixed by adding following code, but this fix doesnt work in private net.

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: {inlineMath: [['$', '$']]}, messageStyle: "none" });</script>

Any plan to add support?

It would be really nice to install only one extension for markdown rather than lots of different extensions.πŸ˜‚

yzhang-gh commented 7 months ago

Hi, thank both of you for the interest. As you may already know, (up to now) there is no good API for the PDF related functionality. And different external tools have different issues, any of the solutions not only requires great effort but also is not that satisfactory. It might be a better idea to make improvements to the existing markdown-pdf extension rather than implementing a new one.

javix64 commented 7 months ago

Thanks for answering @yzhang-gh, I know what you mean. Thanks for your effort and your work, excellent work!

I guess it is a good idea if you write explicity that this addon does not support PDF (and write which one can do it, if you want) in the README.md section and also is not planned, just for clarify the situation like many people open the issue about this topic.

Have a good developing time!