简体   繁体   English

将后记转换为jpeg

[英]Convert postscript to jpeg

I have the ghostscript dll (gsdll32.dll) which I have wrapped into my c# application. 我有包裹在我的C#应用​​程序中的ghostscript dll(gsdll32.dll)。 I tried various way to convert postscript to jpeg but it's not happening. 我尝试了多种将Postscript转换为jpeg的方法,但没有发生。 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? 可能是什么原因?

  1. I have the postscript location at hand in the string "psFilePath". 我在字符串“ psFilePath”中有手记位置。
  2. "outfile" represents the location and file name of the output. “ outfile”代表输出的位置和文件名。

[I have used the same stuff and converted the postcript to PDF and PNG as following]. [我使用了相同的东西,并将后记转换为PDF和PNG,如下所示]。

To PDF WORKED 转换为PDF

            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: 转换为PNG代码:

            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. 编辑I已生成后记,并且应用程序将继续运行直到退出。 But no jpeg file is found. 但是找不到jpeg文件。

The postscript is generated by a postscript printer provided with the ghostscript. 该后记是由配备了ghostscript的后记打印机生成的。 Once this postscript is generated the control is transferred to the application that converts this PS. 生成此后记后,控件将转移到转换此PS的应用程序。

I managed to get the output with the following arguments: 我设法通过以下参数获取输出:

            PDFPrinter.WGhostScript gs = new PDFPrinter.WGhostScript();
            gs.AddParam("-q");
            gs.AddParam("-dNOPAUSE");
            gs.AddParam("-dBATCH");
            gs.AddParam("-sDEVICE=jpeg");
            gs.AddParam(@"-sOutputFile=<full oytput file path>%i.jpg");
            gs.AddParam(<psFilePath>);

I had to add in the "-q" to get it done. 我必须添加“ -q”来完成它。

' -q to prevent Ghostscript from writing messages to standard output which become mixed with the intended output stream. ' -q防止Ghostscript将消息写入标准输出,该消息与预期的输出流混合在一起。 '

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM