如何从Byte []创建PDF文件以加载PDF阅读器 [英] How to Create PDF file from Byte[ ] to load on PDF reader

查看:195
本文介绍了如何从Byte []创建PDF文件以加载PDF阅读器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道...如何编写从sql数据库加载或打开pdf查看器上的pdf文件。

我的代码是



I would like to know ...how to write for loading or opening pdf file on pdf viewer from sql database.
my code is

byte[] img5 = (byte[])resultTable.Rows[0]["image5"];

                   if (img5.Length != 0)
                   {
                       axAcroPDF1.Refresh();
                       string path1 = AppDomain.CurrentDomain.BaseDirectory;
                       string spathfile = path1 + "sample.pdf";
                       System.IO.File.WriteAllBytes(spathfile, img5);
                       this.axAcroPDF1.LoadFile(spathfile);

                   }









我有此代码中的错误如'访问路径'C:\Program Files(x86)\ Project \ sample.pdf'被拒绝。

谢谢。





I got the error on this code like 'Access to path 'C:\Program Files(x86)\Project\sample.pdf' is denied.
Thanks.

推荐答案

您不应该写入Program Files。改为使用临时文件:

You should not write to Program Files. Use a temporary file instead:
var path = Path.GetTempFileName();
File.WriteAllBytes(path, img5);
File.Move(path, path + ".pdf"); // if .pdf extension is required rename the file



您可能希望在Acrobat Reader存在后删除该文件。


You may want to delete the file after Acrobat Reader exists.


这是安全问题。标准用户无权在程序文件下创建文件。将文件保存在您拥有权限的其他位置,或者使用具有admin或权限的用户运行应用程序。
This is security issue. Standard user does not have rights to create files under program files. Save the file somewhere else where you do have rights or run the application with user having admin or privileges.


这篇关于如何从Byte []创建PDF文件以加载PDF阅读器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆