如何在c#中将位图图像垂直打印到多个页面

时间:2015-11-12 15:36:49

标签: c# printing bitmap system.drawing

位图图像高度可能大于页面高度。在这种情况下,它应该打印成多页。

我尝试使用下面的代码来处理小型单页图像,但在行

处得到了OutOfMemoryException
s.end() + 1

使用

在ASP.NET MVC4控制器到服务器打印机中完成打印
    e.Graphics.DrawImage(bm.Clone(new Rectangle(0, 
       pageHeight * (pageno - 1), bm.Width, 
       pageHeight),
        System.Drawing.Imaging.PixelFormat.DontCare),
        0, 0);

如何将图像打印到多个页面? using System.Drawing.Printing; using System.Drawing; using System.IO; byte[] bmp = bmp image created by wkhtmltoimage var doc = new PrintDocument(); doc.PrinterSettings.PrinterName = "myprinter"; doc.PrintPage += new PrintPageEventHandler(ProvideContent); pageHeight = doc.DefaultPageSettings.PaperSize.Height; using (bm = new Bitmap(new MemoryStream(bmp))) { var lehti = (int)Math.Ceiling((double)(bm.Height / pageHeight)); doc.PrinterSettings.FromPage = 1; doc.PrinterSettings.ToPage = lehti; doc.PrinterSettings.MaximumPage = 1; doc.PrinterSettings.MinimumPage = lehti; pageno = 1; doc.Print(); } } int pageno; int pageHeight; Bitmap bm; void ProvideContent(object sender, PrintPageEventArgs e) { e.Graphics.DrawImage(bm.Clone(new Rectangle(0, pageHeight * (pageno - 1), bm.Width, pageHeight), System.Drawing.Imaging.PixelFormat.DontCare), 0, 0); } 有效,但只打印图像的上半部分。

0 个答案:

没有答案