-1

I use GhostScript to fix/repair non-compliant/corrupted PDFs in order to let them be successfully opened by PDF readers and be edited with Acrobat Pro without errors or warnings.

gs \
  -o repaired.pdf \
  -sDEVICE=pdfwrite \
  -dPDFSETTINGS=/default \
   corrupted.pdf

I noticed however that PNGs images into the PDF are turned into JPEGs with a loss of quality.

Is there a way or specific option to avoid that?

I searched into the documentation without success.

Paolo
  • 15,233
  • 27
  • 70
  • 91
  • SO is a programming Q&A platform and this question is not about programming. Questions about operating systems, their utilities, networking and hardware, are off topic here. [What topics can I ask about here?](https://stackoverflow.com/help/on-topic). Please delete this and ask, instead, on or https://superuser.com/ – Rob Oct 29 '22 at 08:10
  • I wasn't aware but will work on that now. I can't do it all by myself – Rob Oct 29 '22 at 09:33
  • `git` is a programming tool. The other two are not and I routinely work on those along with comments that have nothing to do with the question at hand. – Rob Oct 29 '22 at 10:49

1 Answers1

1

PDF cannot contain PNG images, because the PDF format does not support PNG. Images can be compressed with a variety of algorithms and the options are documented. See:

https://ghostscript.readthedocs.io/en/latest/VectorDevices.html#distiller-parameters

You will want to alter the AutoFilter...Images switches and then the ColorImageFilter, MonoImageFilter and GrayImageFilter settings.

And there's really no point in putting -dPDFSETTINGS=/default :-)

KenS
  • 30,202
  • 3
  • 34
  • 51
  • thank you for deepening. I wrongly thought PDF could embed JPEGs, GIFs, TIFFs, PNGs. I asked because in the process I noticed a quality loss of images that where originally PNGs (the PDF is produced via macOS's Quartz). My my firtst thought was that GS was turning PNGs into JPEGs. I was obviously wrong. – Paolo Oct 31 '22 at 09:28
  • The PNG will have been decompressed and then stored as an image in the PDF file using some compression format (no idea what, but not JPEG). If you then run the PDF through pdfwrite the default compression for colour images is indeed JPEG (DCT). If you don't want that, and I can see why, then you need to tell pdfwrite to use a different compression filter. Flate is probably good enough. – KenS Oct 31 '22 at 16:21