简体   繁体   English

如何从数据库中的阅读器中显示pdf文件

[英]How to display pdf file in reader from database

Hello I am working in windows application "winforms" in this I have successfully save pdf file in database now I want to display that in adobe reader which i have been added from toolbox what should I need to do, thats why I can able to view pdf in adobe reader. 您好,我正在Windows应用程序“ winforms”中工作,我现在已成功将pdf文件保存在数据库中,我想在Adobe Reader中显示该信息,这是我从工具箱中添加的,该怎么办,这就是为什么我可以查看pdf在Adobe Reader中。 I already try to display pdf file to reader but nothing display. 我已经尝试将pdf文件显示给阅读器,但没有任何显示。

Here is my code: 这是我的代码:

{
        con.Open();
        SqlCommand command1 = new SqlCommand("select PDFFILE from help ;", con);
        DataTable dt = new DataTable();
        byte[] img = (byte[])command1.ExecuteScalar();
        MemoryStream ms = new MemoryStream(img);
        string s = System.Text.Encoding.UTF8.GetString(img);

        axAcroPDF1.LoadFile(s);
        con.Close();         
}

If the adobe control only takes a filename, you will need to save the pdf as a file first. 如果adobe控件仅采用文件名,则需要先将pdf另存为文件。 System.IO.Path will get you a temporary path. System.IO.Path将为您提供一个临时路径。 Using a guid will also prove useful for random names. 使用guid还将对随机名称有用。

If you don't want that, you may use the PdfiumViewer , which is Googles Pdfium wrapped as a .NET control. 如果您不希望这样做,可以使用PdfiumViewer ,它是Google的Pdfium包装为.NET控件。 Works fine, takes streams as load parameter and is easy to use. 工作正常,将流作为负载参数,并且易于使用。 You can get both the PdfiumViewer and the required Pdfium-DLLs via NuGet. 您可以通过NuGet获取PdfiumViewer和所需的Pdfium-DLL。 Plus, you won't be dependent on the installed adobe version any more. 另外,您将不再依赖于已安装的Adobe版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM