问题
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