This project is read-only.

Converting from PS to PDF format using memorystream data c#

Jun 13, 2014 at 1:09 AM
Edited Jun 13, 2014 at 1:19 AM
Hi,

I have requirement where i am getting the data from printer in a PS format, and i want that to be converted to pdf.
data is in the form of bytearray, what is the best way to accomplish this using Ghostlibrary.
i am using right now latest version of gs
1.1.8.
OS is windows 8, 64 bit.
gs installed is 9.09

i tried using different classes of gs but nothing worked.

using (var rasterizer = new GhostscriptRasterizer())
                                using (var memoryStream = new MemoryStream(bytes))
                                {
                                    memoryStream.Seek(0, SeekOrigin.Begin);
                                    GhostscriptVersionInfo gv = GhostscriptVersionInfo.GetLastInstalledVersion();
                                    rasterizer.Open(memoryStream, gv, false);
}

this fails with error "Stream format is not valid! Please make sure it's PDF, PS or EPS."

whatever data i get from print command i am passing to above method, and that is not working.

I am directly using binaries without any gs code integration, and my application is running in 32 bit mode.

and if i use gs api's it converts gs sample ps->pdf files successfully, but ps files created from printtofile option in printer always gives error. nothing worked so far.

Is there any best reference i get to make this work.?

Regards
Roshan sullad
Jun 18, 2014 at 11:02 AM
Hi,

Sorry for the late response.

You need to make sure that the MemoryStream you want to convert to PDF has a valid postscript signature.

If you open that postscript in notepad, does it start with '%!' ?

You can take a look how Stream file type recognition is done here: https://github.com/jhabjan/Ghostscript.NET/blob/master/Ghostscript.NET/Helpers/StreamHelper.cs

Cheers,
Josip