File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 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{ 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+ }
You can’t perform that action at this time.
0 commit comments