Share via


convert a pdf file into byte array and pass it to a service and from byte array to pdf

Question

Thursday, March 16, 2017 2:44 PM

hello

i am using spire.pdf dll.

i have a winform in which i read a pdf file from a folder.

i want to convert it to a byte array(or to a better option???) and pass it as variable to a WCF service(which i have)

in the WCF service i want to save this byte array as PDF.

i am getting an "index was out of bounds of an array" when i am trying to open a new pdf document with this byte array:

the size of the array is 910200 bytes

PdfDocument doc = new PdfDocument();

doc.LoadFromBytes(byteArray);> Here i get the Exception

doc.SaveToFile(.......)

All replies (5)

Thursday, March 16, 2017 5:11 PM

These forums are for MS products only. If you need assistance with a third party library then you'll need to post your question in their forums.

But if all you need to do is send a PDF across the wire then you don't need any third party library at all. Just read the bytes in using File.ReadAllBytes. That gives you the byte array you need. To save the file back out use File.WriteAllBytes. The fact that it is a PDF doesn't matter until you actually try to read/write the PDF-specific contents.

Also note that if the PDF is large then you may run into binding size limits in WCF. You'll likely need to increase the message sizes in your bindings if your files are going to be large (25+ MB).

Michael Taylor
http://www.michaeltaylorp3.net


Friday, March 17, 2017 3:13 AM

Hi Tom,

There can be many reasons that cause this problem. I would suggest you try the newest version first. If the issue still exists, you'd better describe your issue in details and enclose the source PDF document on the Spire.PDF Forum, that will help their specialist to reproduce your issue and work out a solution for you as soon as possible.

Regards,

Michael 


Sunday, March 19, 2017 5:59 AM

Hey Michael.

I first tried using Read and Write all bytes. the pdf file was created BUT i couldn't it .

it said that it was unable to open file.


Sunday, March 19, 2017 9:33 PM

Please post the code you are using. It could simply be an issue with not closing the stream before trying to read it.


Saturday, March 2, 2019 5:13 AM

Hey tom_herman,

Open visual studio as Administrator,

Regards,

Sushobhan