Skip to content

Instantly share code, notes, and snippets.

@pirpyn
Created November 11, 2019 11:17
Show Gist options
  • Save pirpyn/c3cb46bd4c338ef355cd135946e008dd to your computer and use it in GitHub Desktop.
Save pirpyn/c3cb46bd4c338ef355cd135946e008dd to your computer and use it in GitHub Desktop.
PDF page number fix
#!/bin/bash -e
if [[ $# -ne 2 ]]; then
echo pdf2qdf2pdf in.pdf out.pdf;
exit 1;
fi;
qpdf -qdf $1 ${1/.pdf/.qdf};
FIX="/Catalog \n
/PageLabels << \n
/Nums [ \n
0 << /S /r >> \n
10 << /S /D >> \n
] \n
>>"
SEDCMD=$( echo "s|/Catalog|${FIX}|" | tr '\n' ' ')
sed "${SEDCMD}" ${1/.pdf/.qdf} > tmp.qdf
fix-qdf tmp.qdf > tmp.fix;
qpdf tmp.fix ${2};
rm tmp.qdf tmp.fix;
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment