怎么才能在Winform中显示PDF文件,我原来用的WebBrowser方法显示webBrowser1.Url = new Uri(path);这种方式在Win7下面不显示,其它系统正常显示,后来在网上找了好多种方法,包括http://hi.baidu.com/yashua839/blog/item/b155a0dd1fadb2e677c63842.html,都试了,但还是没有解决,有没有类似的DLL,不能是适用版的
调试欢乐多
http://www.foolabs.com/xpdf/ 开源免费的
@="C:\\Program Files\\Adobe\\Reader 9.0\\Reader\\AcroRd32.exe" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\acrobat\shell] [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\acrobat\shell\open] [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\acrobat\shell\open\command]
@="C:\\Program Files\\Adobe\\Reader 9.0\\Reader\\AcroRd32.exe /u \"%1\"" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SOFTWARE\Adobe\Acrobat\Exe]
@="\"C:\\Program Files\\Adobe\\Reader 9.0\\Reader\\AcroRd32.exe\"" 保存为reg格式的文件,双击打开看看能行不。
能行的话再想法把上头这些值搞到win7系统里去。
C#显示PDF文件,winform打开PDF文件并在窗体中显示
1.在工具箱中添加Adobe提供的ActiveX控件
选择com组件,Adobe PDF Reader
打勾点确定,在控件工具栏就有了Adobe PDF Reader控件,拖一个Adobe PDF Reader控件到窗体上,双击窗体,在窗体加载时,弹出对话框,加载PDF文件:
string fileName = MyOpenFileDialog();
axAcroPDF1.LoadFile(fileName);
MyOpenFileDialog()函数为:
string MyOpenFileDialog()
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "PDF文档(*.pdf)|*.pdf";
if (ofd.ShowDialog() == DialogResult.OK)
{
return ofd.FileName;
}
else
{
return null;
}
}
也可以用代码创建Adobe PDF Reader组件:
string fileName = MyOpenFileDialog();
AxAcroPDFLib.AxAcroPDF axAcroPDF = new AxAcroPDFLib.AxAcroPDF();
axAcroPDF.Location = new System.Drawing.Point(0, 24);
axAcroPDF.Size = new System.Drawing.Size(292, 242);
axAcroPDF.Dock = DockStyle.Fill;
Controls.Add(axAcroPDF);
axAcroPDF.LoadFile(fileName);
不过要注意,在我们把Adobe PDF Reader组件拖到窗体上的时候,它会自动引用2个dll:AcroPDFLib和AcroPDFLib,如图:在编译的时候,VS会Adobe PDF Reader ActiveX组件转换为2个.net组件:AxInterop.AcroPDFLib.dll和Interop.AcroPDFLib.dll
API 地址
http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Acrobat9_HTMLHelp&file=IAC_API_OLE_Objects.103.167.html