simonhaenisch / md-to-pdf

Hackable CLI tool for converting Markdown files to PDF using Node.js and headless Chrome.
https://www.npmjs.com/md-to-pdf
MIT License
1.12k stars 108 forks source link

Merge Feature #291

Closed LoganBolton closed 3 months ago

LoganBolton commented 4 months ago

I added the ability to turn every .md file contained in a directory into one merged pdf. This is a useful feature if you take notes in pure markdown in editors like Obsidian. If you add the argument --merge and then pass in a directory, it will turn all the markdown files into one pdf called {root_directory}_MERGED.pdf.

simonhaenisch commented 4 months ago

Thanks for the contribution, however wouldn't it also be possible to just cat all the markdown files and then feed that into md-to-pdf via stdin? i.e.

cat **/*.md | md-to-pdf > merged.pdf
LoganBolton commented 4 months ago

That is a cool way to add all the md files into one pdf, but its missing a few things I want. What inspired me to create this feature is that I take all my notes in Obsidian and I wanted an easy way to share them with (non techincal) people in my classes. Because of that, its important to know exactly what file you're looking at. This PR adds the current file's title to the top of every page and also keeps track of what page it is at the bottom.

I also ran this shell command in some of my Obsidian directories and there seems to be some odd bugs with rendering titles on some pages. Kinda weird since some of them render in the pdf, but some of the don't.

Another advantage of having a merge CLI argument instead of a shell command is that it lets you debug easier. I'm sure the issue I described above could be solved, but it would a lot more difficult to figure out the perfect command instead of just changing a few lines in a separate file.

That being said, I wish that specific shell command you stated would be in the ReadMe. I'm not great with shell commands and didn't realize this was possible so I'm sure someone else would appreciate it too.

Thanks for your quick response on this PR

simonhaenisch commented 4 months ago

https://github.com/simonhaenisch/md-to-pdf/blob/7e0b9fc7a1209dc681903fab25f5af3a0551fd3a/readme.md#L92

there's that in the readme but yeah i agree it's not very prominent and doesn't show wildcard usage. i'll try to improve it when i have some time

LoganBolton commented 3 months ago

Hi Simon, do you have any additional feedback on ways I could improve this PR?

simonhaenisch commented 3 months ago

Hey Logan, thanks for the ping... sorry I don't really want to maintain this feature because it's a quite a bit of code and I find it too specific for your use-case, e.g. the added header and footer templates that can't be customized. I think it's better to keep this as a fork.

Thanks for your contribution anyway, people searching for a way to use this to turn their Obsidian notes into a PDF can find this thread and use your fork instead (:

LoganBolton commented 3 months ago

Makes sense, I enjoyed working with this code base so I would be interested in working on additional features in the future