open pdf from stream using pdfclown in c#

别等时光非礼了梦想. 提交于 2019-12-11 02:34:01

问题


I am really liking pdfclown in c# but I would like to open a pdf from a byte[] array or filestream. I have not found any examples of this for pdfclown. Could anyone help?

An example would be something like:

using (org.pdfclown.files.File file = new org.pdfclown.bytes.IInputStream(bytes)) {

... }

Thanks


回答1:


This is the right way to open a file from a byte array:

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

If you check out PDF Clown from its repository (version 0.1.2.1 or later) or download the next release, you can even use this ultra-simple constructor:

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

or, in case of System.IO.Stream:

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

If you have a plain file system path, this is your constructor:

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



回答2:


I found the answer to this question using the pdfclown forum. I've adapted it for my need. 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))
        {

        }
    }
}


来源:https://stackoverflow.com/questions/28822403/open-pdf-from-stream-using-pdfclown-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!