c#从文件中读取文本,带有二进制内容
我想将PDF文件读为字符串。
我正在使用file.readallText(path)
,但结果以二进制数据的第一个流结束。
我认为它将流的某些部分视为文件的末尾和停止。
有什么想法解决这个问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法将PDF文件读为字符串,因为PDF文件包含其他数据以外的其他数据。每当您在PDF文件中遇到流对象时,将文件读为
byte
数组或解析它在读取文本和二进制数据之间切换。一些语言(例如PHP)将字符串和字节阵列视为可互换的。在C#中不是这种情况。
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#.