shrink/actions-document-publish

New page per file in PDF

omeganot opened this issue · 5 comments

Hello there! Thanks for the awesome action. It was simple to set up, and I love the quick concatenation of several folders and files to pull from, in order, when generating a PDF. It's great.

I'm curious, would there be a way to configure the action to start a new page in the PDF document for each Markdown file it encounters? It would help me segment some of my content and make it easier to read, especially with a table of contents. It seems the converter first generates HTML, then a PDF from that, so I'm not sure what the technique would be to separate pages, but it'd be an awesome feature if possible. If you have any thoughts let me know, and I'd be happy to help if I can.

Hi @omeganot. Thank you for the kind words, and the question! The action was designed for a very specific use-case, i.e: a single document that can be signed, released and distributed with ease (using shrink/actions-document-sign). I would like to keep the action single-file only, because introducing multi-file options will increase the scope dramatically, however, there are certainly ways to achieve this and you're more than welcome to fork this action with some changes to support multiple output files.

That said... as noted in the README, the action takes advantage of baileyjm02/markdown-to-pdf which supports multiple files by default. I would definitely recommend skipping my action and going straight to baileyjm02/markdown-to-pdf as it is much more suited to your needs, and includes a helpful example in their README. If there's a reason that using baileyjm02/markdown-to-pdf directly isn't suitable for your use case, please let me know and I'm happy to either point you in a better direction, or describe the changes you'd need to make to this action.

Thank you for the info! I looked into https://github.com/baileyjm02/markdown-to-pdf as well, but it seems that action is meant to create multiple PDFs from multiple Markdown files. I actually commented over there on looking into that action, and mixed up what did what. Another good repo owner over there looking to be helpful as well! =)

Yours brings them together in one single document, which is what I was after. I was just looking to have each Markdown file start on its own page, whereas right now they mash together with only a new line separating them.

For example, if Markdown File 1 results in two and a third pages of content, I'd like Markdown File 2 to begin on page 4, not right after the content on page 3. I guess merging a bunch of PDFs into one PDF would suffice, yet might miss a shared table of contents. Any thoughts on other ways to accomplish this?

@omeganot Ah! I'm sorry, I totally misunderstood your question.

I don't know of a good solution off the top of my head, because the Markdown parser doesn't have the concept of "pages" -- we're just rendering a bunch of HTML (from Markdown) and letting a browser render it. However, because we're ultimately using HTML we could try using styling to force the output of each input file to be exactly the height of n pages. For example, if the Markdown output is 10.5 pages then we display it in an element that is 11 pages tall, so the next file output starts on page 12...

...but maybe that's overcomplicating things, maybe we can force a new page using styling without any additional page-based logic. The break-after css property supports page which...

Forces a page break right after the principal box.

So in theory something like this would work:

<div style="break-after: page;">
  <!-- contents of Markdown page 1 -->
</div>
<div style="break-after: page;">
  <!-- contents of Markdown page 2 -->
</div>
<div style="break-after: page;">
  <!-- contents of Markdown page 3 -->
</div>

The best way to implement this would be to add that element to wrap the file variable, the easiest way to implement this would be to add that wrapping to each of your source files.

for file in $SOURCES; do (cat "${file}"; echo) done > $DOCUMENT

I haven't tried this yet, and might not have time tonight, but I'll report back on whether or not it works -- if not, feel free to try it yourself!

I like the way you're thinking. I tried implementing what I think you're saying, though it didn't seem to create new pages for each Markdown file. What I did was:

for file in $SOURCES; do (cat "<div style='break-after: page;'>${file}</div>"; echo) done > $DOCUMENT

Perhaps that's not exactly what you meant, or perhaps the break-after: page; style doesn't create new pages when converting to PDF.

I did some searching on styles and found https://stackoverflow.com/questions/1664049/can-i-force-a-page-break-in-html-printing which noted using page-break-before for media print styles, which I tried but couldn't get to work. Perhaps it's because of how markdown-it "prints" the HTML to PDF. I'm not sure.

You can check out the changes I made at my fork - https://github.com/omeganot/actions-document-publish/blob/action/publish.sh

I'm closing this issue as I am archiving this GitHub Action (see #15). The Action will continue to work as-is, but no further changes will be made.