【问题标题】:Can I return byte[] with GhostscriptProcessor?我可以用 GhostscriptProcessor 返回 byte[] 吗?
【发布时间】:2014-08-11 09:50:57
【问题描述】:

是否可以使用 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 并从其内容中返回一个 byte[]?

【问题讨论】:

  • GhostscriptProcessor 可以创建 PDF/A 文档吗?
  • 好的,结果文件发送/存储/写入到哪里?到磁盘?
  • 对磁盘是的,因为我不知道是否可以将流与 GhostscriptProcessor 一起使用。
  • 是的,看看 Ghostscript.NET 示例中的 GhostscriptPipedOutput 示例。这样,您将在内存中获得字节数组输出。

标签: c# pdfa ghostscript.net


【解决方案1】:

有可能:

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;
            }
        }
    }
}

【讨论】:

  • processor.Processprocessor.StartProcessing有什么区别?我想验证后者是异步的,这不适用于我的特定结果。
  • StartProcessing 在单独的线程中运行,您可以随时调用 StopProcessing。
猜你喜欢
  • 2013-02-06
  • 2011-12-18
  • 1970-01-01
  • 2013-05-20
  • 2010-09-28
  • 1970-01-01
  • 2011-01-15
  • 2012-01-02
  • 2015-10-21
相关资源
最近更新 更多