Reputation: 16213
Pandoc allows a user to translate multiple Markdown input files into one PDF file.
pandoc --pdf-engine=xelatex -o test.pdf *.md
With this call, all Markdown pages are continuously listed in the PDF output without any new-page. I would like to start a new PDF page per Markdown file.
How to add a \newpage
after or before every inserted Markdown file?
Upvotes: 2
Views: 1375
Reputation: 89
You can do it without Pandoc with simple Python script like this:
pip install markdown-pdf
from markdown_pdf import Section, MarkdownPdf
pdf = MarkdownPdf()
# each section (content of single md file) starts from new page in pdf file
pdf.add_section(Section(open("file1.md").read())) # page 1
pdf.add_section(Section(open("file2.md").read())) # page 2
pdf.save("out.pdf")
Upvotes: 0
Reputation: 207345
If you use GNU awk, i.e. gawk
, with multiple files, it has an extension that triggers at the end of each file so you can use that to insert "newpage" commands like this:
gawk '1; ENDFILE{print "\\newpage"}' *.md | pandoc --pdf-engine=xelatex -o test.pdf
The 1
in gawk
evaluates to "True" which causes gawk
to do its default action, which is to print the current line, so that means all lines get printed, in addition to the "newpage" commands at the end of each file.
You can probably get the same result with GNU sed
if you add the -s
option to treat each document as separate, so you get a separate "last line" for each document:
sed -se '$a\\\newpage' doc*.md | pandoc ...
Upvotes: 2