I have the ghostscript dll (gsdll32.dll) which I have wrapped into my c# application. I tried various way to convert postscript to jpeg but it’s not happening. The code is as follows:
PDFPrinter.WGhostScript gs = new PDFPrinter.WGhostScript();
gs.AddParam("-sDEVICE=jpeg");
gs.AddParam("-dJPEGQ=100");
gs.AddParam("-dNOPAUSE");
gs.AddParam("-dBATCH");
gs.AddParam("-dSAFER");
gs.AddParam("-r300");
string outfile = txtOutFolderLoc.Text + txtFileName.Text + ".jpg";
gs.AddParam(@"-sOutputFile=" + outfile);
gs.AddParam(psFilePath);
gs.Execute();
Application.Exit();
What might be the reasons?
- I have the postscript location at hand in the string “psFilePath”.
- “outfile” represents the location and file name of the output.
[I have used the same stuff and converted the postcript to PDF and PNG as following].
To PDF WORKED
gs.AddParam("-dBATCH");
gs.AddParam("-dNOPAUSE");
gs.AddParam("-sDEVICE=pdfwrite");
gs.AddParam("-sPAPERSIZE=a4");
gs.AddParam("-sProcessColorModel=DeviceGray");
gs.AddParam("-sPDFPassword=password");
string outfile = txtOutFolderLoc.Text + txtFileName.Text + ".pdf";
gs.AddParam(@"-sOutputFile=" + outfile);
gs.AddParam(psFilePath);
gs.Execute();
Application.Exit();
TO PNG CODE:
gs.AddParam("-dSAFER");
gs.AddParam("-dBATCH");
gs.AddParam("-dNOPAUSE");
gs.AddParam("-sDEVICE=png16m");
gs.AddParam("-dGraphicsAlphaBits=4");
gs.AddParam(@"-sOutputFile=" + txtOutFolderLoc.Text + txtFileName.Text + "%i.png");
gs.AddParam(psFilePath);
gs.Execute();
Application.Exit();
EDIT I
The postscript is being generated and the application continues till it exits. But no jpeg file is found.
The postscript is generated by a postscript printer provided with the ghostscript. Once this postscript is generated the control is transferred to the application that converts this PS.
I managed to get the output with the following arguments:
I had to add in the “-q” to get it done.
‘-q to prevent Ghostscript from writing messages to standard output which become mixed with the intended output stream.‘