這是如何顯示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