从MS sqlc阅读PDF doc到axacropdf# [英] Read PDF doc to axacropdf from MS sqlc#

查看:73
本文介绍了从MS sqlc阅读PDF doc到axacropdf#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I need to read from ms sql file to adobe PDF reader
Error is line 8
 
Error CS0029 Cannot implicitly convert type 'System.IO.MemoryStream' to 'string'
 
Some help?





我尝试过:





What I have tried:

try  
                {  
                    if (documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value != null)  
                    {  
                        byte[] ap = (byte[])documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value;  
                        MemoryStream ms = new MemoryStream(ap);  
                       
                        axAcroPDF1.src = ms;  //here is error
  
  
                          
                    }  
                    else {  
                        axAcroPDF1.src = null;  
                    }  
                }  
                catch  
                {  
                    axAcroPDF1.src = null;  
                }  

推荐答案

正如Gerry所说,您使用的控件不支持从流中加载文件。您必须先将它们保存到磁盘。

As Gerry said, the control you're using doesn't support loading files from a stream. You have to save them to disk first.
byte[] ap = (byte[])documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value;
string tempName = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".pdf");
File.WriteAllBytes(tempName, ap);
axAcroPDF1.src = tempName;

注意:当您完成临时文件或应用程序关闭时,您需要一些代码来删除临时文件。



如果你想要一个支持直接从流加载的控件,试试 PdfiumViewer [ ^ ],使用Google的Pdfium库 [ ^ 。如果您通过NuGet安装它,请注意安装说明 [ ^ ] - 您需要一个或多个其他软件包来安装本机Pdfium库。

NB: You'll need some code to delete the temporary file when you've finished with it, or when your application closes.

If you want a control that supports loading directly from the stream, try PdfiumViewer[^], which uses Google's Pdfium library[^]. If you install it via NuGet, pay attention to the installation instructions[^] - you'll need one or more additional packages to install the native Pdfium library.


它(可能)要求PDF文件的路径(而不是流);



将流复制到磁盘文件,并提供文件路径字符串(您收到错误的地方)。
It's (probably) asking for the "path to a PDF file" (and not a "stream");

Copy the stream to a disk file, and supply the "file path" string (where you got your error).


这篇关于从MS sqlc阅读PDF doc到axacropdf#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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