1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Drawing.Printing;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
- namespace EmisTerminal
- {
- public class ImagePrintDocument : PrintDocument
- {
- private int m_currentPage;
- private List<Image> m_pages = new List<Image>();
- public ImagePrintDocument(IList<Image> imageList)
- {
- m_pages = imageList.ToList();
- }
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (disposing)
- {
- foreach (Image s in m_pages)
- {
- s.Dispose();
- }
- m_pages.Clear();
- }
- }
- protected override void OnBeginPrint(PrintEventArgs e)
- {
- base.OnBeginPrint(e);
- m_currentPage = 0;
- }
- protected override void OnPrintPage(PrintPageEventArgs e)
- {
- base.OnPrintPage(e);
- using (Image pageToPrint = m_pages[m_currentPage])
- {
- Rectangle adjustedRect = new Rectangle(
- e.PageBounds.Left - (int)e.PageSettings.HardMarginX,
- e.PageBounds.Top - (int)e.PageSettings.HardMarginY,
- e.PageBounds.Width,
- e.PageBounds.Height);
- // Draw a white background for the report
- e.Graphics.FillRectangle(Brushes.White, adjustedRect);
- // Draw the report content
- e.Graphics.DrawImage(pageToPrint, adjustedRect);
- // Prepare for next page. Make sure we haven't hit the end.
- m_currentPage++;
- e.HasMorePages = m_currentPage < m_pages.Count;
- }
- }
- }
- }
|