Skip to content

Commit 477325e

Browse files
committed
pdfmaker
1 parent d5340fc commit 477325e

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

nix/pdfmaker.nix

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
let
2+
pkgs = import ./nixpkgs.nix;
3+
in
4+
pkgs.writeShellApplication {
5+
name = "pdfmaker";
6+
text = ''
7+
set -euo pipefail
8+
9+
INPUT="$1"
10+
BASENAME="$(basename "$INPUT" .md)"
11+
OUTPUT="$BASENAME.pdf"
12+
13+
TMP="$(mktemp -d)"
14+
WORK="$TMP/processed.md"
15+
cp "$INPUT" "$WORK"
16+
17+
LINKS=$(sed -n 's/.*(\(http[^)]*\)).*/\1/p' "$INPUT" | sort -u)
18+
19+
i=1
20+
for URL in $LINKS; do
21+
PNG="$TMP/qr_$i.png"
22+
PDF="$TMP/qr_$i.pdf"
23+
24+
qrencode -o "$PNG" -s 3 -m 1 "$URL"
25+
26+
magick "$PNG" "$PDF"
27+
28+
ESCAPED=$(printf '%s\n' "$URL" | sed -e 's/[\/&]/\\&/g')
29+
sed -i "s|($ESCAPED)|($ESCAPED)\n\n![]($PDF){ width=2cm }|g" "$WORK"
30+
31+
i=$((i+1))
32+
done
33+
34+
pandoc "$WORK" --standalone --pdf-engine=xelatex -o "$OUTPUT"
35+
'';
36+
37+
runtimeInputs = with pkgs; [
38+
pandoc
39+
busybox
40+
qrencode
41+
texliveSmall
42+
imagemagick
43+
];
44+
}

0 commit comments

Comments
 (0)