Search code examples
bytefilestreampdfclown

open pdf from stream using pdfclown in c#


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


Solution

  • 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))
    {
    }