bool pageViewer1_PreviousPage(object sender) { if (doc.CurrentPage > 1) { doc.PreviousPage(); doc.RenderPage(pageViewer1.Handle, true); RenderFinish(); return(true); } return(false); }
public override void Render(int page, Graphics graphics, float dpiX, float dpiY, Rectangle bounds) { _document.CurrentPage = page + 1; _document.RenderDPI = dpiX; _document.ClientBounds = bounds; _document.CurrentX = -bounds.Left; _document.CurrentY = -bounds.Top; var hdc = graphics.GetHdc(); try { // xPDF uses the control to get sizing information. We use // a dummy control to satisfy this requirement. _dummyControl.Size = new Size(bounds.Width, 1); _document.FitToWidth(_dummyControl.Handle); _document.RenderPage(_dummyControl.Handle); _document.DrawPageHDC(hdc); } finally { graphics.ReleaseHdc(hdc); } }
public static Image RenderPage(PDFWrapper doc, int page) { doc.CurrentPage = page + 1; doc.CurrentX = 0; doc.CurrentY = 0; doc.RenderPage(IntPtr.Zero); // create an image to draw the page into var buffer = new Bitmap(doc.PageWidth, doc.PageHeight); doc.ClientBounds = new Rectangle(0, 0, doc.PageWidth, doc.PageHeight); using (var g = Graphics.FromImage(buffer)) { var hdc = g.GetHdc(); try { doc.DrawPageHDC(hdc); } finally { g.ReleaseHdc(); } } return(buffer); }
private void tsbOpen_Click(object sender, EventArgs e) { try { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Portable Document Format (*.pdf)|*.pdf"; if (dlg.ShowDialog() == DialogResult.OK) { if (_pdfDoc != null) { _pdfDoc.Dispose(); _pdfDoc = null; } //if (_pdfDoc == null) //{ _pdfDoc = new PDFWrapper(); _pdfDoc.RenderNotifyFinished += new RenderNotifyFinishedHandler(_pdfDoc_RenderNotifyFinished); _pdfDoc.PDFLoadCompeted += new PDFLoadCompletedHandler(_pdfDoc_PDFLoadCompeted); _pdfDoc.PDFLoadBegin += new PDFLoadBeginHandler(_pdfDoc_PDFLoadBegin); _pdfDoc.UseMuPDF = tsbUseMuPDF.Checked; //} //xPDFParams.ErrorQuiet =true; //xPDFParams.ErrorFile = "C:\\stderr.log"; //} int ts = Environment.TickCount; using (StatusBusy sb = new StatusBusy(Resources.UIStrings.StatusLoadingFile)) { if (LoadFile(dlg.FileName, _pdfDoc)) { Text = string.Format(Resources.UIStrings.StatusFormCaption, _pdfDoc.Author, _pdfDoc.Title); FillTree(); _pdfDoc.CurrentPage = 1; UpdateText(); _pdfDoc.FitToWidth(pageViewControl1.Handle); _pdfDoc.RenderPage(pageViewControl1.Handle); Render(); PDFPage pg = _pdfDoc.Pages[1]; listView2.TileSize = new Size(134, (int)(128 * pg.Height / pg.Width) + 10); listView2.BeginUpdate(); listView2.Clear(); for (int i = 0; i < _pdfDoc.PageCount; ++i) listView2.Items.Add((i + 1).ToString()); listView2.EndUpdate(); //pg.LoadThumbnail(128, (int)(128 * pg.Height / pg.Width)); } } } } catch (System.IO.IOException ex) { MessageBox.Show(ex.Message, "IOException"); } catch (System.Security.SecurityException ex) { MessageBox.Show(ex.Message, "SecurityException"); } catch (System.IO.InvalidDataException ex) { MessageBox.Show(ex.Message, "InvalidDataException"); } }
protected Bitmap GetBitmapBase(double Resolution, bool Transparent = true) { if (mypdfDoc != null && mypdfDoc.PageCount > 0) { double dpi = 72 * Resolution / Consts.ptspertikzunit; PDFPage p = mypdfDoc.Pages[1]; double pwidth = p.Width, pheight = p.Height; // the following lines are as in the PDFPage.GetBitmap() function int width = Convert.ToInt32(pwidth * dpi / 254); int height = Convert.ToInt32(pheight * dpi / 254); int safetymargin = 0; // >0 => hack to prevent cropping near boundary // if we'd need too much memory -> don't proceed if (width * height > 20e6) { GlobalUI.UI.AddStatusLine(this, "Pdf rendering aborted: it's too big!", true); return(null); } //Stopwatch s = new Stopwatch(); //s.Start(); mypdfDoc.RenderDPI = 72 * Resolution / Consts.ptspertikzunit; //System.Windows.Forms.PictureBox pic = new System.Windows.Forms.PictureBox(); mypdfDoc.CurrentPage = 1; /*Added since 1.0.6.2*/ mypdfDoc.CurrentX = 0; mypdfDoc.CurrentY = 0; mypdfDoc.ClientBounds = new System.Drawing.Rectangle(0, 0, width + safetymargin, height + safetymargin); //new Rectangle(0, 0, mypdfDoc.PageWidth, mypdfDoc.PageHeight); mypdfDoc.RenderPage(IntPtr.Zero, true); ////pic.Handle); // it works with zero, very strange!!! //Bitmap bbb = mypdfDoc.Pages[1].GetBitmap(72 * Resolution / Consts.ptspertikzunit, false); //System.Drawing.Image I = mypdfDoc.Pages[1].GetImage(1); //System.Drawing.Image I2 = mypdfDoc.Pages[1].GetImage(0); //if (mypdfDoc.PageWidth * mypdfDoc.PageHeight == 0) if (height * width == 0) { return(null); } Bitmap _backbuffer = new System.Drawing.Bitmap(width + safetymargin, height + safetymargin); //new Bitmap(mypdfDoc.PageWidth, mypdfDoc.PageHeight); using (Graphics g = Graphics.FromImage(_backbuffer)) { /*New thread safe method*/ mypdfDoc.DrawPageHDC(g.GetHdc()); g.ReleaseHdc(); } //s.Stop(); //MainWindow.AddStatusLine("DrawpageHdc took " + s.ElapsedMilliseconds + " ms"); //pic.Dispose(); if (Transparent) { _backbuffer.MakeTransparent(System.Drawing.Color.White); _backbuffer.MakeTransparent(System.Drawing.Color.FromArgb(255, 253, 253, 253)); _backbuffer.MakeTransparent(System.Drawing.Color.FromArgb(255, 254, 254, 254)); } // test //_backbuffer.Save(@"C:\temp\temp.bmp"); //mypdfDoc.ExportJpg(@"C:\temp\temp.jpg",1,1,75,100,9000); return(_backbuffer); } else { return(null); } }
private void tsbOpen_Click(object sender, EventArgs e) { try { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "Portable Document Format (*.pdf)|*.pdf"; if (dlg.ShowDialog() == DialogResult.OK) { if (_pdfDoc != null) { _pdfDoc.Dispose(); _pdfDoc = null; } //if (_pdfDoc == null) //{ _pdfDoc = new PDFWrapper(); _pdfDoc.RenderNotifyFinished += new RenderNotifyFinishedHandler(_pdfDoc_RenderNotifyFinished); _pdfDoc.PDFLoadCompeted += new PDFLoadCompletedHandler(_pdfDoc_PDFLoadCompeted); _pdfDoc.PDFLoadBegin += new PDFLoadBeginHandler(_pdfDoc_PDFLoadBegin); //} //xPDFParams.ErrorQuiet =true; //xPDFParams.ErrorFile = "C:\\stderr.log"; //} int ts = Environment.TickCount; using (StatusBusy sb = new StatusBusy(Resources.UIStrings.StatusLoadingFile)) { if (LoadFile(dlg.FileName, _pdfDoc)) { Text = string.Format(Resources.UIStrings.StatusFormCaption, _pdfDoc.Author, _pdfDoc.Title); FillTree(); _pdfDoc.CurrentPage = 1; UpdateText(); _pdfDoc.FitToWidth(pageViewControl1.Handle); _pdfDoc.RenderPage(pageViewControl1.Handle); Render(); PDFPage pg = _pdfDoc.Pages[1]; listView2.TileSize = new Size(134, (int)(128 * pg.Height / pg.Width) + 10); listView2.BeginUpdate(); listView2.Clear(); for (int i = 0; i < _pdfDoc.PageCount; ++i) { listView2.Items.Add((i + 1).ToString()); } listView2.EndUpdate(); //pg.LoadThumbnail(128, (int)(128 * pg.Height / pg.Width)); } } } } catch (System.IO.IOException ex) { MessageBox.Show(ex.Message, "IOException"); } catch (System.Security.SecurityException ex) { MessageBox.Show(ex.Message, "SecurityException"); } catch (System.IO.InvalidDataException ex) { MessageBox.Show(ex.Message, "InvalidDataException"); } }
void HookManager_MouseDown(object sender, MouseEventArgs e) { Point pos = pageViewControl1.PointToClient(e.Location); if (_pdfDoc != null && MouseInPage(pos) && e.Button == MouseButtons.Left) { PDFLibNet.PageLink link = SearchLink(e.Location); if (link != null) { switch (link.Action.Kind) { case LinkActionKind.actionGoTo: PDFLibNet.PageLinkGoTo plgo = (link.Action as PDFLibNet.PageLinkGoTo); if (plgo.Destination != null) { _pdfDoc.CurrentPage = plgo.Destination.Page; PointF loc = _pdfDoc.PointUserToDev(new PointF((float)plgo.Destination.Left, (float)plgo.Destination.Top)); if (plgo.Destination.ChangeTop) { ScrolltoTop((int)loc.Y); } else { ScrolltoTop(0); } _pdfDoc.RenderPage(pageViewControl1.Handle); Render(); } else if (plgo.DestinationName != null) { } break; case LinkActionKind.actionURI: PDFLibNet.PageLinkURI uri = (link.Action as PDFLibNet.PageLinkURI); if (MessageBox.Show("Ejecutar aplicación externa?" + Environment.NewLine + uri.URL, Text, MessageBoxButtons.OKCancel) == DialogResult.OK) { System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = GetDefaultBrowserPath(); p.StartInfo.Arguments = uri.URL; p.Start(); } break; } } else { _pointCurrent = e.Location; _pointStart = e.Location; _bMouseCaptured = true; } } }