我可以返回字节[]与GhostscriptProcessor
本文关键字:GhostscriptProcessor 返回 字节 我可以 | 更新日期: 2023-09-27 18:17:30
是否可以使用GhostscriptProcessor返回byte[] ?例如:
public static byte[] ConvertToPDFA(byte[] pdfData)
{
GhostscriptProcessor gsproc = new GhostscriptProcessor(Properties.Resources.gsdll32);
//return byte[] from the created PDF/A
方法StartProcessing是一个void方法,但是是否有其他方法可以从PDF文件创建PDF/a并从其内容返回字节[]?
这是可能的:
public class PipedOutputSample
{
public void Start()
{
string inputFile = @"E:'gss_test'test_postscript.ps";
GhostscriptPipedOutput gsPipedOutput = new GhostscriptPipedOutput();
// pipe handle format: %handle%hexvalue
string outputPipeHandle = "%handle%" + int.Parse(gsPipedOutput.ClientHandle).ToString("X2");
using (GhostscriptProcessor processor = new GhostscriptProcessor())
{
List<string> switches = new List<string>();
switches.Add("-empty");
switches.Add("-dQUIET");
switches.Add("-dSAFER");
switches.Add("-dBATCH");
switches.Add("-dNOPAUSE");
switches.Add("-dNOPROMPT");
switches.Add("-sDEVICE=pdfwrite");
switches.Add("-o" + outputPipeHandle);
switches.Add("-q");
switches.Add("-f");
switches.Add(inputFile);
try
{
processor.StartProcessing(switches.ToArray(), null);
byte[] rawDocumentData = gsPipedOutput.Data;
//if (writeToDatabase)
//{
// Database.ExecSP("add_document", rawDocumentData);
//}
//else if (writeToDisk)
//{
// File.WriteAllBytes(@"E:'gss_test'output'test_piped_output.pdf", rawDocumentData);
//}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
gsPipedOutput.Dispose();
gsPipedOutput = null;
}
}
}
}