【问题标题】:open pdf from stream using pdfclown in c#在 C# 中使用 pdfclown 从流中打开 pdf
【发布时间】:2023-03-29 13:30:01
【问题描述】:

我真的很喜欢 c# 中的 pdfclown,但我想从 byte[] 数组或文件流中打开一个 pdf。我还没有找到任何关于 pdfclown 的例子。有人可以帮忙吗?

一个例子是这样的:

使用 (org.pdfclown.files.File 文件 = 新的 org.pdfclown.bytes.IInputStream(bytes)) {

... }

谢谢

【问题讨论】:

    标签: byte filestream pdfclown


    【解决方案1】:

    这是从字节数组中打开文件的正确方法:

    var bytes = . . .;
    using (var file = new org.pdfclown.files.File(new org.pdfclown.bytes.Buffer(bytes)))
    {
    }
    

    如果你check out PDF Clown from its repository(0.1.2.1 或更高版本)或下载下一个版本,你甚至可以使用这个超简单的构造函数:

    byte[] bytes = . . .;
    using (var file = new org.pdfclown.files.File(bytes))
    {
    }
    

    或者,对于 System.IO.Stream:

    System.IO.Stream stream = . . .;
    using (var file = new org.pdfclown.files.File(stream))
    {
    }
    

    如果你有一个普通的文件系统路径,这是你的构造函数:

    string filename = . . .;
    using (var file = new org.pdfclown.files.File(filename))
    {
    }
    

    【讨论】:

      【解决方案2】:

      我使用 pdfclow 论坛找到了这个问题的答案。我已经根据我的需要对其进行了调整。 enter link description here

      byte[] bytes = io.File.ReadAllBytes(@filename);
      
      using (var ms = new io.MemoryStream(bytes))
      {
          using (org.pdfclown.bytes.IInputStream i = new org.pdfclown.bytes.Stream(ms))
          {
              using (org.pdfclown.files.File file = new org.pdfclown.files.File(i))
              {
      
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2013-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-20
        • 1970-01-01
        • 2014-03-26
        • 2012-11-01
        • 2013-10-11
        相关资源
        最近更新 更多