sql - 在 SQL Server 中将 Varbinary 转换为 PDF
问题描述
我有一个带有 varbinary 类型列的 SQL 表,并在其中存储了 PDF 文件。这是文件在数据库中的外观:
0x4D007900500044004600460069006C0065002E00700064006600
如何转换它以便我可以看到 PDF 文件的内容?
例如:在同一列中,我存储了 XML 文件,我可以使用CONVERT()
以下函数查看 XML 文件内容:
SELECT *, CONVERT(XML,(CONVERT(varbinary(max),[fileColumn]))) from table
解决方案
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.
推荐阅读
- php - 如何修复phpunit致命错误必须兼容?
- git - git clone 默认保存目录
- c++ - 与 Code::Blocks 一起使用时,使用 winbgi 库的应用程序崩溃
- angular - 如何在Angular中以反应形式上传图像?
- mysql - 与没有 auto_increment 相比,拥有 auto_increment ID 会降低性能吗?
- c++ - 来自大括号的初始值设定项列表中的简短 C++ 类构造函数
- slurm - 如何找出已完成的 SLURM 作业的“命令”(批处理脚本文件名)?
- ibm-cloud - 我们能否使用 IPSEC-VPN 连接 IBM-Cloud 中不同位置的两个特定节点?
- python - 生成两个数字之间的随机范围
- flutter - Flutter:我可以在 BLoC 架构中使用 setState() 吗?