0

I have installed the latest version of ghostscript on windows 7 (gswin64). I am trying to convert PDF from older version to a new version. I need to run the command from the 'CMD' window. I tried running this gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=new-pdf1.5.pdf C:\folder\original.pdf and also tried putting the file path into double quotes like "C:\folder\original.pdf".

It does not work. Can you tell me what I am doing wrong?

Ruruboy
  • 626
  • 3
  • 12
  • 36

2 Answers2

1

In what way 'does not work' ? Please state the entire command line, including the input file, the order is important.

Did you get an error ? If so what error ? Did you get anything at all in the back channel ?

Why are you using -dQUIET when trying to debug a problem ? You want all the information Ghostscript can give you about the problem, so drop that.

Please note that Ghostscript does not 'convert' PDF files, and that setting the CompatibilityLevel to 1.5 doesn't really do much. It simply limits the features the pdfwrite device has available to it.

If the input doesn't require higher level features, then the pdfwrite device won't use them. Since your input is a lower version of PDF, it won't use those features and so although the version in the header will be 1.5 the actual content will consist of the lower version features.

You could get the same effect by using a binary-capable editor to change the version in the original PDF file to 1.5.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • Hi Ken, Thanks for your reply. Are you telling me that Ghostscript will not convert a PDF from a lower version to the same PDF in a higher version? – Ruruboy Jun 15 '18 at 17:14
  • Do you know if there is an API I can use to convert lower version to higher version and vice versa? – Ruruboy Jun 15 '18 at 17:23
  • The reason why the want to convert a lower version of pdf to a new version is they have a virus scanning gateway that does not allow lower versions of pdf documents uploaded through. So we want a free API that we can use to check the version of PDF being uploaded using c# code and pass it through the API that will convert it to the next higher version of PDF, and then we send it through our existing route. So I am looking for a way to convert the PDF from lower to higher version. I just wanted to give you the detail. Please let me know. – Ruruboy Jun 15 '18 at 19:28
  • There is nothing for Ghostscript to 'convert'. It can stick a higher version number on the new file, but since the only features within the file will be from the old file, there is nothing there that can be 'new'. You can use this to **down**grade a PDF file, but not to upgrade. – KenS Jun 15 '18 at 19:28
  • The easy way to do this is simply to change the version number in the header, eg from %PDF-1.0 to %PDF-1.5. That won't chnage the content though, there's no reason to, PDF is upwardly compatible. – KenS Jun 15 '18 at 19:30
  • And how do we change the version in the header? – Ruruboy Jun 15 '18 at 19:32
  • How do you stick a higher version in a PDF using ghostscript? – Ruruboy Jun 15 '18 at 19:38
  • To answer your first question, open the file, find the number, change it, save the file. Its not rocket science. As to your second, set -dPDFCompatibilityLevel. But it won't produce content containing PDF 1.5 features, if the input is from a lower version, that's all I'm saying. – KenS Jun 15 '18 at 19:47
  • To use this: -dPDFCompatibilityLevel - can you give me the command line parameters I would need for this. For example : gs -sDEVICE=pdfwrite....? As I plan to write a console appication in C# to run the command as a proof of concept. Please let me know Ken. – Ruruboy Jun 15 '18 at 21:23
  • I'm currently travelling, so no I'm afraid I can't just give you a prepared answer. It **is** documented however, and you can find it in the documentation at www.ghostscipt.com. Look for VectorDevices.htm (on Linux the documentation forms part of the installation). You already have it in the body of your question I see. You still haven't said what your actual problem is. – KenS Jun 16 '18 at 09:04
1

I have posted the command I used. Thank you for help KenS in initiating my research. I cannot post the PDF's as it is proprietary content. But it did upgrade the PDF.

gswin64.exe -sDEVICE=pdfwrite -dCompatibilityLevel=1.3 -dNOPAUSE \
    -dBATCH -sOutputFile=C:\folder\new.pdf C:\folder\old.pdf

Next issue which I need to figure out: How do I call this process in C# .NET? I need to do the following:

Upload a file using the Upload control (thats simple) Take the stream of the uploaded file and pass the binary stream through ghostscript which will convert the version of the PDF. --> How do I pass a stream through ghostscript? Since Ghostscript needs a file saved on the hard drive and will write it back to the hard drive? It has to be done in the memory stream upon uploading the File?

DevSolar
  • 67,862
  • 21
  • 134
  • 209
Ruruboy
  • 626
  • 3
  • 12
  • 36