A simple pdf font fix using Bash (linux/wsl) and Ghostscript. :)
Sometimes the PDF generated doesn´t have embedded ttf fonts and you got issues when the file is sent to a printer.
It causes bad behavior! I mean due to a failure in the font substitution process if you´re using a system without the required font or especially when the host is an Android device.
So your hard copy will be printed with the wrong font :(
This script creates a batch process to extends the ghostscript commands allowing repair (not)embedded font issues, compress to re-distribute
gs -o repaired.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress original.pdf
gs -q -o repaired.pdf -sDEVICE=pdfwrite -dCompatibilityLevel=1.3 -dPDFSETTINGS=/ebook -dAutoRotatePages=/None -dColorImageDownsampleType=/Bicubic -dColorImageResolution=72 -dGrayImageDownsampleType=/Bicubic -dGrayImageResolution=72 -dMonoImageResolution=72 original.pdf
pdffonts your_pdf.pdf
Results:
If the results has "no" on "emb column" and you are gettings issues on your printing process, consider update the cidfmap and run pdfff to fix it.
So if your pdf file has a font that your system doesn´t, you could add the entry bellow on /var/lib/ghostscript/fonts/cidfmap
/Arial << /FileType /TrueType /Path (/usr/local/share/fonts/arial.ttf) /SubfontID 0 /CSI [(Identity) 0] >> ;
Arial on this sample, replace with font name that fits your needs
Path:
- If you´re using an installed font on your Microsoft Windows and running this script on WSL you could use "/mnt/c/Windows/Fonts/font.ttf" as a PATH
- If you want to point directly to ttf file, copy that to "/usr/local/share/fonts/font.ttf" and use it as a PATH
- You arelady got it!
Fonts:
- You could install Microsoft fonts if you hasn´t, run "sudo apt install ttf-mscorefonts-installer"
- You could download Microsoft fonts from https://www.w7df.com/ and manually install
Get the script file, make it executable
sudo chmod +x pdfff.sh
Run
./pdfff.sh
Sample PDFs to test if you have no one to start:
- https://www.learningcontainer.com/wp-content/uploads/2019/09/sample-pdf-file.pdf
- https://www.learningcontainer.com/wp-content/uploads/2019/09/sample-pdf-download-10-mb.pdf
- https://www.learningcontainer.com/wp-content/uploads/2019/09/sample-pdf-with-images.pdf
- https://www.pdf2go.com/repair-pdf
- https://www.makeuseof.com/how-to-analyze-pdf-file-fonts/amp/
- https://superuser.com/questions/278562/how-can-i-fix-repair-a-corrupted-pdf-file
- https://stackoverflow.com/questions/15093661/cidfmap-on-ghostscript-8-64-substitute-cid-font-adobe-identity-is-not-provide
- https://gist.github.com/firstdoit/6390547#gistcomment-3467053
- https://www.learningcontainer.com/sample-pdf-files-for-testing/
- https://www.pdf-online.com/osa/optimize.aspx
- http://pdf-analyser.edpsciences.org/
- https://ghostscript.com/doc/9.26/Use.htm
- https://www.mankier.com/package/poppler-utils
- Send your idea :P