1

When I try to convert PDF to PDF/A using GhostScript.NET and I start debuging the project brings this exception:

"Additional information: An error occured when call to 'gsapi_init_with_args' is made: -100"

My code is:

Public Sub Start()
    Dim gv As GhostscriptVersionInfo = New GhostscriptVersionInfo("C:\Program Files\gs\gs9.18\bin\gsdll64.dll")
    Dim proc As GhostscriptProcessor = New GhostscriptProcessor(gv)
    Dim switches As List(Of String) = New List(Of String)()

    switches.Add("-dPDFA=1")
    switches.Add("-dNoCancel")
    switches.Add("-dNOPAUSE")
    switches.Add("-dNOOUTERSAVE")
    switches.Add("-sProcessColorModel=DeviceRGB")
    switches.Add("-sDEVICE=pdfwrite")
    switches.Add("-sOutputFile=pdfa.pdf")
    switches.Add("C:\Program Files\gs\gs9.18\bin\PDFA_def.ps")
    switches.Add("-dPDFACompatibilityPolicy=1")
    switches.Add("C:\Program Files\gs\gs9.18\bin\teste.pdf")
    proc.StartProcessing(switches.ToArray, Nothing)
    MsgBox("ok")

End Sub

If I run the code to convert PDF to PDF / A through CMD, it works perfectly.

gswin64 -q -dPDFA=1 -dNoCancel -dNOPAUSE -dNOOUTERSAVE -sProcessColorModel=DeviceRGB -sDEVICE=pdfwrite -sOutputFile=pdfa.pdf PDFA_def.ps -dPDFACompatibilityPolicy=1 teste.pdf

However, running with the above code brings this error.

If I change the parameters to convert PDF to image, it works well with the code below.

switches.Add("-dSAFER")
switches.Add("-dBATCH")
switches.Add("-dNOPAUSE")
switches.Add("-sDEVICE=jpeg")
switches.Add("-sOutputFile=figure.jpg")
switches.Add("teste.pdf")

So it seems that there is some problem in the parameters, at the same time that through the CMD these parameters are working perfectly.

Any suggestions for making the code work?

The problem of running CMD directly is that it opens a GhostScript popup.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • Since it works from the command line, this isn't a Ghostscript problem. – KenS Dec 20 '18 at 19:23
  • Oh, and don't use -dNOOUTERSAVE – KenS Dec 20 '18 at 19:24
  • Yes, I know it's not a Ghostscript problem. Maybe in the wrapper (for this kind of conversion). Don't you know a way to use gsdll32.dll into .Net project to convert PDF to PDF/A? Thanks for the information about -dNOOUTERSAVE. – Jorge Pereira Dec 20 '18 at 21:25
  • No, I don't know anything about .NET. You could try using Ghostscript.NET instead of ghostscriptsharp. I don't know anything much about either of them though. – KenS Dec 20 '18 at 21:41
  • I have a file that has 251Kb. When I use **gswin64**, it opens the Ghostscript window it generates a file with 253 kb, which stays that size until I close the Ghostscript window. Then its final size is 277 Kb and completes the conversion correctly. However if I use **gswin64c** it generates a file with 253 Kb and corrupted. When I close the prompt, nothing happens and the size remains 253 Kb. Any ideia about this error? – Jorge Pereira Dec 21 '18 at 13:48
  • Well, no, how could I possibly comment? I haven't seen your file, you haven't given me the transcript of the back channel and you haven't told me which version of Ghostscript you are using. There is no functional difference between gswin64 and gswin64c, the DLL is identical and the executable is little more than a thin layer over the DLL. One runs in the command shell, the other opens a 'real' Win32 window, there is no other difference. Its pretty hard to see how one could work and one not. This doesn't seem to be related to your original question, you shouldn't ask new ones in the comments. – KenS Dec 21 '18 at 14:11
  • If you think you've found a bug then you should report it as such to https://bugs.ghostscript.com – KenS Dec 21 '18 at 14:13

0 Answers0