Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used the GhostScript API to convert PostScript files individually, but the latest version 9.06 of Ghostscript permits "server mode" which means that the GS interpreter can be loaded once, perform multiple conversions and finally exit the GS Interpreter at the end. Before this "server mode", the GS Interpreter had to be loaded and unloaded for each file conversion.
Do you know how to implement "server mode" for the GhsotScript API using VB or C# ?
Thanks for any clues on how to do this.
Jaime
Posted
Comments
ZurdoDev 5-Sep-12 16:25pm    
I don't know how but the first place I would look is in the documentation for GS. Have you gone through that?
JamesArc 6-Sep-12 16:03pm    
Hi Ryan:
Yes Ryan I´ve already read it. The GS documentation only has this feature announcement:
Version 9.06 (2012-08-08)
This is the sixth full release in the stable 9.x series.
Highlights in this release include:
pdfwrite "Server mode" - pdfwrite can now be run in "server mode" which allows the device to be closed without closing the interpreter. This means it is no longer necessary to terminate GS before starting a new PDF conversion.
Thanks,
Jaime

1 solution

I think this 'server mode' means only, that the pdfwrite device now supports the
%d flag in the -sOutputFile <outputfilename>%d.pdf parameter.

That means the pdfwrite device is closed internally after a conversion, so that you can convert a multi-page ps/pdf document and save single pages.

I don't think this 'server mode' allows you to convert more than one multi-page ps/pdf to pdf, but I'm not sure.

The doc states:
pdfwrite "Server mode" - pdfwrite can now be run in "server mode" which allows the device to be closed without closing the interpreter. This means it is no longer necessary to terminate GS before starting a new PDF conversion. This leads on to:

pdfwrite now supports the "%d" format in the OutputFile switch. If this is set then pdfwrite will output each page of input to an individual file.

Bye,

Thomas.
 
Share this answer
 
Comments
JamesArc 12-Sep-12 10:53am    
Hi Thomas:

Thanks for your comment.

I was able to convert several PS files with this server mode, but the interpreter generates an error after processing a certain number of files with the gsapi.vb (VB.NET) program.

To do this I created a function:

Public Function LoadGSserver() As Boolean
'### Load Ghostscript and get the instance handle (_intptrGSInstanceHandle)
intReturn = CreateGSAPIInstance(_intptrGSInstanceHandle, callerHandle)
...
End Function

(Note: I also created an UnloadGSServer Function to be called after ending all the conversions)

And in a loop called:

gsapi32.ConvertFile("ps2pdf", "-dNOPAUSE", "-dBATCH", "-dSAFER", "-r300", "-sDEVICE=pdfwrite", "-sOutputFile=" & "C:\PDFs\PDF%03d.pdf", "-c", ".setpdfwrite", "-f", sPSFile)

This creates PDF files in folder C:\PDFs with names PDF001.pdf, PDF002.pdf, PDF003.pdf, etc.

After a certain number (about 80 files) of converted files I get a CallbackOnCollectedDelegate error.

Any suggestions.
Thanks,
Jaime
Thomas Duwe 13-Sep-12 5:04am    
Where is this exception generated/where is the origin of the exception?
Post a stacktrace of the exception.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900