Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read a pdf file from url to to byte array

Tags:

arrays

c#

.net

pdf

In an XML WebResponse I get a URL tag which has a link to a PDF file. Example of the URL value is: https://www.member-data.com/files/hb/c8955fc4d6160ec0fd87f4879c6496d3.pdf). I have to convert this PDF to a byte array, how do I do this in C#?

like image 953
user228777 Avatar asked Oct 10 '11 15:10

user228777


People also ask

How do I read a PDF in byte array?

You can read data from a PDF file using the read() method of the FileInputStream class this method requires a byte array as a parameter.

What is a Bytearray?

A consecutive sequence of variables of the data type byte, in computer programming, is known as a byte array. An array is one of the most basic data structures, and a byte is the smallest standard scalar type in most programming languages.

How do I convert an image to a Bytearray?

Read the image using the read() method of the ImageIO class. Create a ByteArrayOutputStream object. Write the image to the ByteArrayOutputStream object created above using the write() method of the ImageIO class. Finally convert the contents of the ByteArrayOutputStream to a byte array using the toByteArray() method.

Can we convert byte array to file in Java?

Convert byte[] array to File using Java In order to convert a byte array to a file, we will be using a method named the getBytes() method of String class. Implementation: Convert a String into a byte array and write it in a file.


2 Answers

You can use WebClient.DownloadData, which has a default return value of a byte array. e.g.

byte[] bytes = myClient.DownloadData("https://www.member-data.com/files/hb/c8955fc4d6160ec0fd87f4879c6496d3.pdf");

Also, this assumes that you want the actual file in a byte array, not the content (text) of the PDF. That's a whole other ball of wax.

like image 132
George Johnston Avatar answered Oct 07 '22 00:10

George Johnston


You can use WebClient.DownloadData().

like image 20
svick Avatar answered Oct 07 '22 00:10

svick