private void FitWidth() { if (_pdfDoc != null && _pdfDoc.CurrentPage > 0) { using (PictureBox p = new PictureBox()) { p.Width = pageViewControl1.ClientSize.Width; _pdfDoc.FitToWidth(p.Handle); } _pdfDoc.RenderFinished -= new RenderFinishedHandler(_pdfDoc_RenderFinished); _pdfDoc.RenderFinished += new RenderFinishedHandler(_pdfDoc_RenderFinished); _pdfDoc.RenderPageThread(pageViewControl1.Handle, true); } }
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); } }
void FitWidght() { using (PictureBox box = new PictureBox()) { box.Width = pageViewer1.ClientSize.Width; doc.FitToWidth(box.Handle); } doc.RenderPage(pageViewer1.Handle, true); RenderFinish(); }
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"); } }
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"); } }