简体   繁体   中英

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?

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#.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM