首页 > 解决方案 > 在 SQL Server 中将 Varbinary 转换为 PDF

问题描述

我有一个带有 varbinary 类型列的 SQL 表,并在其中存储了 PDF 文件。这是文件在数据库中的外观:

0x4D007900500044004600460069006C0065002E00700064006600

如何转换它以便我可以看到 PDF 文件的内容?

例如:在同一列中,我存储了 XML 文件,我可以使用CONVERT()以下函数查看 XML 文件内容:

SELECT *, CONVERT(XML,(CONVERT(varbinary(max),[fileColumn]))) from table

标签: sqlsql-serverpdf

解决方案


It doesn't need converting as such - the data is already PDF data, as you stated yourself. You just need to put it somewhere where a program which knows how to display PDF data can read and understand it.

As the above comment notes, the easiest way to achieve that is by putting it into a file. Then you can open it in Adobe Reader or other PDF program of your choice.

SQL itself (or to be precise, any SQL Server client software that I know of) cannot render PDFs to the screen directly, if that's what you're asking.


P.S. The key difference between that and your XML example is that XML is a text-based format (whereas PDF is binary), and also SQL Server has a built-in understanding of XML already, so it's easy for a) SQL to parse the data using its built-in functions, and b) a SQL client to display it, because it's already able to display text.


推荐阅读