我有以下文本二进制表示:“0x255044462D312E340D0A25FFFFFFF ...”我知道这是一个pdf。我知道这是来自 sql server 列(图像数据类型)的文本表示。
但是我不知道如何将这个二进制文件保存到我的磁盘上的 pdf 文件并查看内容。
也许有人可以提示我正确的方向。
提前致以最诚挚的问候和感谢
你是对的,它是一个 PDF 文件(至少它伪装成这样。你有十六进制编码的字节;第一次阅读:
255044462D312E340D0A
%PDF-1.4<CR><LF>
所以你似乎有一个 PDF 1.4 字符串。
只需从字符串中取出两个字符,将它们视为十六进制,将它们转换为正确的字节并将它们写入文件。编写二进制,而不是文本(您不想在其中添加额外的换行符,PDF 太二进制,无法让它工作。
(我使用这个网站进行了转换:http: //www.dolcevie.com/js/converter.html)
I'm not sure what database you are working with or how you are getting your string that you have above.
Many databases allow you to save binary data as a blob
or some other byte array type. I believe in MSSQL this is called an "image" but I am not 100% on that. I would start by looking into the two following links in order. The first link talks about how to pull byte array data from a database. The example is in Visual Basic but should be easily changed to C# if that is what you are using.
The second link contains an example of how to save that byte array data to the file system.
I would also suggest posting some of the code you have tried as well so that the community may comment and point out areas you possibly had misunderstandings on.
1.) http://support.microsoft.com/kb/308042
2.) Save and load MemoryStream to/from a file
http://www.pdfsharp.com/PDFsharp/可以读取二进制数据,您可以调用 .Save() ,它将为您将 PDF 文件保存到磁盘。