Export PDF via command line

Hi! I tried to search for a similar feature request, but I did not happen to find one, although I scanned through a lot of PDF related feature requests.

Use case or problem

I’d like to automate exporting content that I will share with third parties. If I generate a PDF and send it to someone (might be via email or via Git, for example), I might notice later that there is some typo in my content. Then I fix the typo and need to generate a PDF file again.

If I could write a Windows Batch script or a Linux Bash script that calls the Obsidian executable, I could store all the PDF settings in the script file (page size, orientation, margin, downscale percent, source file, and output file name). Then I can be certain that if I ever need to generate the PDF again, it will have the same layout and output file name as before.

This would also enable better automatisation: for example, after generating the PDF, my script could commit the new/updated PDF file to Git, and then push it to some remote repository where it would be processed further. Or my script could send an email with the PDF attached to it (or open Thunderbird with a new email message window and the PDF already attached). The possibilities are endless.

Proposed solution

An example of how a command line call could look like:

Obsidian.exe generate-pdf MyNote.md MyNote.pdf --page-size A4 --landscape on --margin default --downscale-percent 100

Obsidian would use the vault that is located in the current working directory. If the current working directory does not contain a vault, Obsidian would response with an error message.

Current workaround (optional)

Currently I’m just using the GUI to generate PDFs.

Related feature requests (optional)

The command line export feature could also support exporting multiple files into a single PDF, like discussed here.

Thank you for your support! :slight_smile:

9 Likes

My workaround is to use pandoc, a tool that can basically convert all text base formats into each other - it also works similar to what your example cli looks like.
However it will not respect your theme, you would need to configure pandoc manually.

A few pointers:
https://www.pandoc.org/demos.html

1 Like

I too would like to see something like this.

I have a specific need where I need to share the contents of a single Obsidian doc (including images) with someone, and since they don’t run Obsidian, a PDF to share is the logical choice.

Sadly, there’s no easy way for me to get the content of that note out of Obsidian–even a copy and paste of the entire doc into a Google doc doesn’t work, which is unfortunate.

1 Like

You can use this in Markdown

+1 Please add native support for exporting multiple notes to separate PDF files.

3 Likes

I used some bash script as a walkaround until Obsidian developers add this feature, I hope :smiling_face_with_tear:

1 Like

Hi, how should one install your script?

I haven’t tried it, but I would also like to export the results of my Dataview queries and dataviewjs queries into the PDF. Is pandoc capable of handling that as well (since it is not part of the markdown specification)?

Would it recognise %% comments %% though? I mainly need to export to PDF via Obsidian for this, and the Pandoc online preview doesn’t seem to have an option to recognise this particular flavour feature.

Looks like I’ll have to manually remove them with a custom script…

UPDATE: interestingly, the Pandoc plugin stripped %% comments %% when using the Export as HTML (without Pandoc) command so it may work with PDF too… I have not installed Pandoc yet and I need to write my own script anyway to combine pages together, so I’ll check this later.