这是如何显示PDF而不使用三夏,使用Adobe阅读器来代替:
从下载Acrobat的SDK http://www.adobe.com/devnet/acrobat/downloads.html
在你的项目的引用从SDK添加到两个DLL - AxInterop.AcroPDFLib.dll和Interop.AcroPDFLib.dll
在您的窗体的构造函数中添加的Adobe预览控制:
// Check if the user has Adobe Reader installed, if not you could show a link to Adobe Reader installer
if (Type.GetTypeFromProgID("AcroPDF.PDF") == null)
{
pnlGetAdobe.Visible = pnlGetAdobe.Enabled = true;
}
else
{
try
{
// Initialize the Adobe control
axAcroPDF1 = new AxAcroPDF();
axAcroPDF1.Dock = DockStyle.Fill;
axAcroPDF1.Enabled = true;
axAcroPDF1.Location = new Point(0, 25);
axAcroPDF1.Name = "axAcroPDF1";
axAcroPDF1.OcxState = (AxHost.State)new ComponentResourceManager(typeof(JasperPdfReport)).GetObject("axAcroPDF1.OcxState");
axAcroPDF1.Size = new Size(634, 393);
axAcroPDF1.TabIndex = 1;
pnlCenter.Controls.Add(axAcroPDF1); // Add it to a container or instead directly to your form with this.Controls.Add(axAcroPDF1)
axAcroPDF1.BringToFront();
}
catch (COMException cex)
{
axAcroPDF1.Dispose();
axAcroPDF1 = null;
MessageBox.Show(cex.ToString());
}
catch (Exception ex)
{
axAcroPDF1.Dispose();
axAcroPDF1 = null;
MessageBox.Show(ex.ToString());
}
}
最后PDF文件加载到控制:
if (axAcroPDF1 != null && File.Exists(pdfFilename))
{
axAcroPDF1.setShowToolbar(false);
axAcroPDF1.setView("FitH");
axAcroPDF1.setLayoutMode("SinglePage");
// Load the PDF into the control
axAcroPDF1.LoadFile(pdfFilename);
axAcroPDF1.src = pdfFilename;
// Show it
axAcroPDF1.Show();
axAcroPDF1.Refresh();
}
如果你只显示PDF,您可以使用Adobe的预览控件,而不是webbrowsercontrol的。 – Vedran 2013-03-04 08:17:29
你能否指点我正确的方向?我在哪里可以找到这样的阅读和代码示例?或者,我应该谷歌? – 2013-03-04 08:39:56
@Vedran明白了,谢谢你的提示! – 2013-03-04 09:10:24