Carlo_Mava
Carlo_Mava

Reputation: 15

C# Reading text from file with binary content

I want to read a PDF file as a string.
I'm using File.ReadAllText(path), but the result ends on the first stream of binary data.
I think it recognizes some part of the stream as the end of file and stops.

Any idea how to solve this?

Upvotes: 0

Views: 474

Answers (1)

Christof Wollenhaupt
Christof Wollenhaupt

Reputation: 561

You cannot read a PDF file as a string, because a PDF file contains other data than just characters. Read the file into a byte array or parse it switching between reading text and binary data whenever you encounter a stream object in the PDF file.

Some languages like PHP treat strings and byte arrays as interchangeable. That is not the case in C#.

Upvotes: 1

Related Questions