Skip to content

Latest commit

 

History

History
85 lines (66 loc) · 3.63 KB

README.md

File metadata and controls

85 lines (66 loc) · 3.63 KB

pdfff









A simple pdf font fix using Bash (linux/wsl) and Ghostscript. :)



Why

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 :(



How Ghostscript works

This script creates a batch process to extends the ghostscript commands allowing repair (not)embedded font issues, compress to re-distribute



Base ghostscript command to embed fonts:

gs -o repaired.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress original.pdf





Base ghostscript to embed and compress:

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





Check your PDF file using pdffonts (requires poppler app)

pdffonts your_pdf.pdf



Results:
image
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.



Update cidfmap

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 and fonts

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



Howto use pdfff

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:





References





Todo

  • Send your idea :P