void IDisplayPane.DisplayResource(IResource resource) { if (resource == null) { throw new ArgumentNullException("resource", "PDFPlugin -- Input resource is NULL in DisplayResource."); } try // Trap general failures, and report to background exception collector { try // Filter out some known and expectd errors, and avoid from showing them to the end user { string fileName = Core.FileResourceManager.GetSourceFile(resource); if (fileName == null) { throw new ApplicationException("PDFPlugin — Can not restore PDF file from resource."); } _axPdf.LoadFile(fileName); } catch (COMException ex) { if (ex.ErrorCode == (int)HResults.E_FAIL) // E_FAIL (?) an integer representation for 0x80004005 { Trace.WriteLine("The Acro7 Control has told us that shit happens.", "PDF"); } else { throw; // Let it be processed the usual way } } } catch (Exception exc) { Core.ReportBackgroundException(exc); } }
/// <summary> /// 打印PDF文件 /// </summary> /// <param name="printer_name"></param> /// <param name="file_path"></param> /// <param name="ax_acropdfunit"></param> /// <returns></returns> public static string print(string printer_name, string file_path, AxAcroPDF ax_acropdfunit) { try { if (!printer_name.isNull()) { string default_printer = PrintUtil.defaultPrinter(); if (default_printer != printer_name) { PrintUtil.setDefaultPrinter(printer_name); while (PrintUtil.defaultPrinter() != printer_name) { Thread.Sleep(50); } Thread.Sleep(1000); } } ax_acropdfunit.LoadFile(file_path); ax_acropdfunit.printAllFit(true); return(""); } catch (Exception ex) { return(ex.ToString()); } }
private void OpenFile(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); openFileDialog.Filter = "PDF File (*.pdf)|*.pdf|Image File (*.bmp,*.jpg,*.jpeg,*.png,*.tif,*.tiff,*.ico,*.TIF)|*.bmp;*.jpg;*.jpeg;*.png;*.tif;*.tiff;*.ico;*.TIF"; if (openFileDialog.ShowDialog(this) == DialogResult.OK) { Form ReaderForm = new Form(); ReaderForm.MdiParent = this; FileInfo fileInfo = new FileInfo(openFileDialog.FileName); switch (fileInfo.Extension) { case ".pdf": { toolStripStatusLabel.Text = "Openning PDF Reader..."; //statusBarToolStripMenuItem.Invalidate(); AxAcroPDF pdfReader = new AxAcroPDF(); ((ISupportInitialize)(pdfReader)).BeginInit(); pdfReader.CreateControl(); pdfReader.Enabled = true; pdfReader.Dock = DockStyle.Fill; pdfReader.Name = "AxAcroPDFReader"; pdfReader.Visible = true; pdfReader.LoadFile(fileInfo.FullName); ReaderForm.Controls.Add(pdfReader); pdfReader.Show(); ((ISupportInitialize)(pdfReader)).EndInit(); ReaderForm.Text = "PDF Reader"; toolStripStatusLabel.Text = "PDF Reader Opened"; //statusBarToolStripMenuItem.Invalidate(); } break; case ".jpg": case ".png": case ".ico": case ".tiff": case ".TIF": case ".bmp": case ".jpeg": case ".tif": { toolStripStatusLabel.Text = "Openning Image Reader..."; //statusBarToolStripMenuItem.Invalidate(); PictureBox pictureBox = new PictureBox(); pictureBox.ImageLocation = fileInfo.FullName; pictureBox.SizeMode = PictureBoxSizeMode.AutoSize; pictureBox.Dock = DockStyle.Fill; pictureBox.Visible = true; pictureBox.Enabled = true; ReaderForm.Controls.Add(pictureBox); pictureBox.Show(); ReaderForm.Text = "Image Reader"; toolStripStatusLabel.Text = "Image Reader Opened"; //statusBarToolStripMenuItem.Invalidate(); } break; } ReaderForm.Show(); } }