c#从文件中读取文本,带有二进制内容

发布于 2025-01-31 16:39:32 字数 133 浏览 5 评论 0原文

我想将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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情话难免假 2025-02-07 16:39:32

您无法将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#.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文