Compilation du PDF via un script python

Permet de gérer automatiquement le nombre de pages de la table des matières, le nombre de pages total du PDF, et de ne le re-généré que si le nombre de pages a changé dans le CSS.
This commit is contained in:
Youen 2023-05-10 23:39:35 +02:00
parent 1e1fb9c195
commit 2b5e828c59
4 changed files with 83 additions and 70 deletions

View file

@ -19,20 +19,5 @@ help:
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
# Default make weasyprint target has a bug so we have to call it manually on the generated index.html file
# Then we execute count_pdf_pages.py that will count the number of pages, and update print-theme.css
# Then we generate index.pdf again (with the correct number of pages in the footer)
# After that, extract table of content data from the pdf and generate a .tex file
# Then generate a toc.pdf from the .tex file
# And put them together in a .pdf file
# Finally, we generate the final PDF by adding the bookmarks (for easier navigation in the PDF)
# After all, clean up
pdf: weasyprint
weasyprint "$(BUILDDIR)/weasyprint/index.html" "$(BUILDDIR)/weasyprint/index.pdf" -s "$(SOURCEDIR)/css/print-theme.css"
python3 sphinx-tools/count_pdf_pages.py "$(BUILDDIR)/weasyprint/index.pdf" "$(SOURCEDIR)/css/print-theme.css"
weasyprint "$(BUILDDIR)/weasyprint/index.html" "$(BUILDDIR)/weasyprint/index.pdf" -s "$(SOURCEDIR)/css/print-theme.css"
./pdftoc-to-latex "$(BUILDDIR)/weasyprint/index.pdf" > "$(BUILDDIR)/weasyprint/toc.tex"
- pdflatex -interaction nonstopmode "-output-directory=$(BUILDDIR)/weasyprint" "$(BUILDDIR)/weasyprint/toc.tex"
pdftk "A=$(BUILDDIR)/weasyprint/index.pdf" "B=$(BUILDDIR)/weasyprint/toc.pdf" cat A1 B A2-end output "$(BUILDDIR)/weasyprint/vheliotech-without-bookmarks.pdf"
python3 sphinx-tools/update_pdf_bookmarks.py "$(BUILDDIR)/weasyprint/index.pdf" "$(BUILDDIR)/weasyprint/vheliotech-without-bookmarks.pdf" "$(BUILDDIR)/weasyprint/vheliotech.pdf"
#rm "$(BUILDDIR)/weasyprint/index.pdf" "$(BUILDDIR)/weasyprint/toc.tex" "$(BUILDDIR)/weasyprint/toc.pdf" "$(BUILDDIR)/weasyprint/GuidedemontageVheliotech.pdf"
python3 sphinx-tools/make_pdf.py "$(SOURCEDIR)" "$(BUILDDIR)"