Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nit] add link colors to pdf #90

Merged
merged 10 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions .github/workflows/generate-pdf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Pandoc, Latex necessities
run: sudo apt-get install -y pandoc texlive texlive-latex-extra poppler-utils texlive-extra-utils
- name: Install Pandoc, Latex necessities, and pdftk
run: |
sudo apt-get install -y pandoc texlive texlive-latex-extra poppler-utils texlive-extra-utils pdftk

- name: Install Python
uses: actions/setup-python@v4
with:
Expand Down Expand Up @@ -76,14 +78,15 @@ jobs:
)
for md_file in "${file_list[@]}"; do
pdf_file_name="pdf_output/$(echo "$md_file" | sed 's/\//_/g' | sed 's/.md//g').pdf"
python3 generate-pdf-edits.py "$md_file" | pandoc -V geometry:margin=1in --pdf-engine=pdflatex -o "$pdf_file_name"
python3 pdf-generation/generate-pdf-edits.py "$md_file" | pandoc -V geometry:margin=1in -V colorlinks=true -V linkcolor=blue -V urlcolor=blue --pdf-engine=pdflatex -o "$pdf_file_name"

if [ ! -f "$pdf_file_name" ]; then
echo "Error: PDF file $pdf_file_name not created!" >&2
exit 1
fi
done
pdfunite \

pdftk \
"pdf_output/index.pdf" \
"pdf_output/principles_index.pdf" \
"pdf_output/principles_principles.pdf" \
Expand Down Expand Up @@ -129,14 +132,34 @@ jobs:
"pdf_output/network_abusing-intrusion-detection.pdf" \
"pdf_output/network_malware.pdf" \
"pdf_output/network_tor.pdf" \
"textbook_full.pdf"
cat output "textbook_full_original.pdf"

- name: Inject page numbers back into the pdf
run: pdfjam --pagecommand '\pagestyle{plain}' --outfile textbook_full.pdf textbook_full.pdf
run: |
mkdir -p pdf_numbering_output

num_pages=$(pdftk textbook_full_original.pdf dump_data | grep NumberOfPages | awk '{print $2}')
sed -i "s/194/$num_pages/" pdf-generation/numbering.tex

# Don't continue if the sed failed
if [ $? -ne 0 ]; then
echo "Error: sed command failed" >&2
exit 1
fi

pdflatex pdf-generation/numbering.tex
pdftk pdf-generation/numbering.pdf burst output pdf_numbering_output/number_%03d.pdf
pdftk textbook_full_original.pdf burst output pdf_numbering_output/page_%03d.pdf
for i in $(seq -f %03g 1 $num_pages) ; do pdftk pdf_numbering_output/page_$i.pdf background pdf_numbering_output/number_$i.pdf output pdf_numbering_output/new_$i.pdf; done

pdftk pdf_numbering_output/new_???.pdf output textbook_full.pdf

sed -i "s/$num_pages/194/" pdf-generation/numbering.tex

- name: Remove temporary files, make temporary copy to upload as artifact
run: |
rm -rf pdf_output
rm -rf pdf_numbering_output
cp textbook_full.pdf textbook_full_cpy.pdf

- name: Upload PDF as an artifact
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,10 @@ $RECYCLE.BIN/
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/macos,windows,jekyll,node

# PDF Page Numbering
pdf-generation/numbering.aux
pdf-generation/numbering.fdb_latexmk
pdf-generation/numbering.fls
pdf-generation/numbering.log
pdf-generation/numbering.synctex.gz
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import re
import argparse

def adjust_images(input_file):
# thanks https://www.reddit.com/r/pandoc/comments/17tsijd/render_htmlsyntax_images_in_pdf_from_markdown/

def adjust_content(input_file):
# Read the contents of the input file
with open(input_file, 'r') as file:
content = file.read()
Expand All @@ -27,4 +29,4 @@ def adjust_images(input_file):

args = parser.parse_args()

adjust_images(args.input_file)
adjust_content(args.input_file)
Binary file added pdf-generation/numbering.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions pdf-generation/numbering.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
\documentclass[12pt,a4paper]{article} % https://cazencott.info/index.php/post/2015/04/30/Numbering-PDF-Pages
\usepackage{multido}
\usepackage[hmargin=.8cm,vmargin=1.5cm,nohead,nofoot]{geometry}
\begin{document}
\multido{}{194}{\vphantom{x}\newpage}
\end{document}
Loading