public override void OnEndPage(PrintDocument document, PrintPageEventArgs e) { base.OnEndPage(document, e); // Get the current Metafile PreviewPageInfo[] ppia = GetPreviewPageInfo(); PreviewPageInfo ppi = ppia[ppia.Length - 1]; Image image = ppi.Image; _Metafile = (Metafile)image; // using ( _Metafile ) { if (_Format == ImageFormat.Emf) { _Metafile.Save(PagePath, _Format); return; } if (_Format == ImageFormat.Wmf) { _Metafile.Save(PagePath, _Format); return; } // _Metafile.Save( PagePath, _Format ); SaveViaBitmap(document, e); } }
/// <summary> /// OnEndPage事件获取每一张页面保存到image对象 /// </summary> /// <param name="document"></param> /// <param name="e"></param> public override void OnEndPage(PrintDocument document, PrintPageEventArgs e) { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; base.OnEndPage(document, e); // Get the current Metafile PreviewPageInfo[] ppia = GetPreviewPageInfo(); PreviewPageInfo ppi = ppia[ppia.Length - 1]; Image image = ppi.Image; ArlImage1.Add(image); _Metafile = ( Metafile )image; //生成文件 if (blnToFile) { if (_Format == ImageFormat.Emf) { _Metafile.Save(PagePath, _Format); return; } if (_Format == ImageFormat.Wmf) { _Metafile.Save(PagePath, _Format); return; } SaveViaBitmap(document, e); } }
private void drawPreviewPage() { if (rezimRada == RezimRada.MyPreviewDraw) { izvestaj.TimeOfPrint = DateTime.Now; bitmapGraphics.Clear(Color.White); drawPage(bitmapGraphics, previewPage); pictureBox1.Image = bitmap; return; } else if (rezimRada == RezimRada.PageSizeTooSmall) { bitmapGraphics.Clear(Color.White); pictureBox1.Image = bitmap; return; } PrintController oldControler = printDocument1.PrintController; PreviewPrintController prevControler = new PreviewPrintController(); printDocument1.PrintController = prevControler; page = previewPage; lastPageToPrint = previewPage; printDocument1.Print(); printDocument1.PrintController = oldControler; PreviewPageInfo pageInfo = prevControler.GetPreviewPageInfo()[0]; // PhysicalSize is in 0.01 inch pictureBox1.ClientSize = pageToScreen(new SizeF( pageInfo.PhysicalSize.Width / 100f, pageInfo.PhysicalSize.Height / 100f)); pictureBox1.Image = pageInfo.Image; // Metafile }
/// <summary> /// Raises the <see cref="Control.Paint"/> event. /// </summary> /// <param name="e">A <see cref="PaintEventArgs"/> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { Rectangle clientRect = this.ClientRectangle; using (Brush brush = new SolidBrush(this.BackColor)) { e.Graphics.FillRectangle(brush, clientRect); } if (!m_backgroundPaintedOnce) { m_backgroundPaintedOnce = true; this.Invalidate(); return; } this.UpdateLayout(); PreviewPageInfo previewPage = this.CurrentPreviewPage; if (previewPage != null) { Debug.Assert(!m_pageRectangle.IsEmpty, "The page rectangle should not be empty when there is a CurrentPreviewPage. It should have been calculated in UpdateLayout()."); Rectangle shadowRectangle = m_pageRectangle; shadowRectangle.Offset(ShadowThickness, ShadowThickness); Rectangle borderRectangle = m_pageRectangle; borderRectangle.Width -= 1; // Need to remove 1 pixel from the width and height for DrawRectangle to work borderRectangle.Height -= 1; // Draw the shadow e.Graphics.FillRectangle(Brushes.Black, shadowRectangle); // Draw the page e.Graphics.FillRectangle(Brushes.White, m_pageRectangle); //TODO: Ne pas dessiner si rectangle plus petit que 2x2 // Draw the page contents e.Graphics.DrawImage(previewPage.Image, m_pageRectangle); // Draw the page border e.Graphics.DrawRectangle(Pens.Black, borderRectangle); } else { using (Brush brush = new SolidBrush(this.ForeColor)) { using (StringFormat stringFormat = new StringFormat()) { stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; e.Graphics.DrawString("No Report", this.Font, brush, clientRect, stringFormat); } } } base.OnPaint(e); }
private void UpdateLayout() { if (m_layoutValid) { return; } this.ResetLayout(); PreviewPageInfo previewPage = this.CurrentPreviewPage; if (previewPage != null) { Rectangle clientRectangle = this.ClientRectangle; clientRectangle.Width -= ShadowThickness; clientRectangle.Height -= ShadowThickness; float scale = Math.Min( ( float )clientRectangle.Width / previewPage.PhysicalSize.Width, ( float )clientRectangle.Height / previewPage.PhysicalSize.Height); int pageWidth = ( int )(previewPage.PhysicalSize.Width * scale); int pageHeight = ( int )(previewPage.PhysicalSize.Height * scale); m_pageRectangle = new Rectangle( ( int )((clientRectangle.Width - pageWidth) / 2), ( int )((clientRectangle.Height - pageHeight) / 2), pageWidth, pageHeight); } m_layoutValid = true; }
public override Graphics OnStartPage(PrintDocument document, PrintPageEventArgs e) { Image image = new Bitmap(e.PageSettings.PaperSize.Width, e.PageSettings.PaperSize.Height); PreviewPageInfo info = new PreviewPageInfo(image, new Size(e.PageSettings.PaperSize.Width, e.PageSettings.PaperSize.Height)); _list.Add(info); Graphics g = Graphics.FromImage(info.Image); g.FillRectangle(new SolidBrush(Color.White), new Rectangle(new Point(0, 0), new Size(image.Width, image.Height))); return(g); }
public PrintPreviewPageViewModel(PreviewPageInfo pageInfo) { _pageInfo = pageInfo; _image = new Lazy <Bitmap>(LoadImage); }