From 923d5c4be78ff2ba1b2a50b4ed561f157ef64ea2 Mon Sep 17 00:00:00 2001 From: Youen Date: Wed, 10 May 2023 22:26:28 +0200 Subject: [PATCH 1/2] =?UTF-8?q?utilisation=20du=20param=C3=A8tre=20BUILDDI?= =?UTF-8?q?R=20plut=C3=B4t=20qu'une=20valeur=20hard-cod=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 16 ++++++++-------- sphinx-tools/count_pdf_pages.py | 5 +++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 273a77e..cffb8b8 100644 --- a/Makefile +++ b/Makefile @@ -28,11 +28,11 @@ help: # Finally, we generate the final PDF by adding the bookmarks (for easier navigation in the PDF) # After all, clean up pdf: weasyprint - weasyprint build/weasyprint/index.html build/weasyprint/index.pdf -s source/css/print-theme.css - python3 sphinx-tools/count_pdf_pages.py - weasyprint build/weasyprint/index.html build/weasyprint/index.pdf -s source/css/print-theme.css - ./pdftoc-to-latex build/weasyprint/index.pdf > build/weasyprint/toc.tex - - pdflatex -interaction nonstopmode -output-directory=build/weasyprint build/weasyprint/toc.tex - pdftk A=build/weasyprint/index.pdf B=build/weasyprint/toc.pdf cat A1 B A2-end output build/weasyprint/vheliotech-without-bookmarks.pdf - python3 sphinx-tools/update_pdf_bookmarks.py build/weasyprint/index.pdf build/weasyprint/vheliotech-without-bookmarks.pdf build/weasyprint/vheliotech.pdf - #rm build/weasyprint/index.pdf build/weasyprint/toc.tex build/weasyprint/toc.pdf build/weasyprint/GuidedemontageVheliotech.pdf + 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" diff --git a/sphinx-tools/count_pdf_pages.py b/sphinx-tools/count_pdf_pages.py index bc55c90..eaee5ea 100644 --- a/sphinx-tools/count_pdf_pages.py +++ b/sphinx-tools/count_pdf_pages.py @@ -1,8 +1,9 @@ import subprocess import re +import sys -pdf_filename = 'build/weasyprint/index.pdf' -css_filename = 'source/css/print-theme.css' +pdf_filename = sys.argv[1] +css_filename = sys.argv[2] additional_pages = 2 # count pages in index.pdf From 5e4746f67c3b3e79db14d8928c2af1ccab9dbd06 Mon Sep 17 00:00:00 2001 From: Youen Date: Wed, 10 May 2023 22:30:50 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Correction=20des=20bookmarks=20avant=20la?= =?UTF-8?q?=20table=20des=20mati=C3=A8res?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sphinx-tools/update_pdf_bookmarks.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sphinx-tools/update_pdf_bookmarks.py b/sphinx-tools/update_pdf_bookmarks.py index 3465a3a..e70125d 100644 --- a/sphinx-tools/update_pdf_bookmarks.py +++ b/sphinx-tools/update_pdf_bookmarks.py @@ -18,7 +18,8 @@ with open(bookmarks_filename) as bookmarks_file: # Offset page numbers def replaceBookmarkPageNumber(match): initial_page = int(match.group(1)) - return 'BookmarkPageNumber: ' + str(initial_page + 2) + final_page = initial_page + 2 if initial_page > 1 else initial_page + return 'BookmarkPageNumber: ' + str(final_page) metadata = re.sub('BookmarkPageNumber:\s+([0-9]+)', replaceBookmarkPageNumber, metadata) with open(bookmarks_filename, 'w') as bookmarks_file: