这是如何在不使用 web 控件的情况下显示 PDF,而是使用 Adobe Reader:
从http://www.adobe.com/devnet/acrobat/downloads.html下载 Acrobat SDK
在您的项目中添加对来自 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();
}