ArtifexSoftware / Ghostscript.NET

Ghostscript.NET - managed wrapper around the Ghostscript library (32-bit & 64-bit)

Home Page:https://ghostscript.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error When Decrypting PDF File

XxDaShTixX opened this issue · comments

GhostScript Version

GhostScript v10.03.1

Problem

"Sometimes" I get an error when I decrypt PDF files after I have encrypted them (also using GhostScript). I can't figure out what exactly is causing this.

Error/Issue

I receive the following error when I attempt to decrypt the previously encrypted file (by GhostScript):
GPL Ghostscript 10.03.1: PDFDocEncoding X is undefined
Where "X" can be an alphanumerical character or two.

I noticed that sometimes based on the permission bits I set when encrypting the same file, it can cause it to error out or succeed in the decryption process.

Reproduce Error

  1. Download the sample.pdf file.

  2. Encrypt the sample file twice. Each time with a different permission bit in order to simulate a succeeding and failing decrypting use case using the following commands:

gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile="Encrypted-8.pdf" -sOwnerPassword="123" -dPermissions=-8 -dEncryptionR=3 "Sample.pdf" -c quit

gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile="Encrypted-16.pdf" -sOwnerPassword="123" -dPermissions=-16 -dEncryptionR=3 "Sample.pdf" -c quit

  1. Now try to decrypt each with the same command:

gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile="Decrypted-8.pdf" -sPDFPassword="123" "Encrypted-8.pdf" -c quit

gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile="Decrypted-16.pdf" -sPDFPassword="123" "Encrypted-16.pdf" -c quit

  1. The 8-bit PDF will error. The 16bit PDF will succeed.

Failure:
image

Success:
image

This may be different for different PDF files. Please let me know if you need any further details.
Thank you in advance for your help.