使用PrintDocument打印多个页面 [英] Print multiple pages using PrintDocument
本文介绍了使用PrintDocument打印多个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用以下代码打印多个页面时遇到问题。它始终只打印最后一页。你能帮助我吗?
使用( var rasterizer = new PdfRasterizer( new Foxit.PDF。 Rasterizer.InputPdf(pdfData)))
{
// 创建一个JpegImageFormat对象。
var jpegImageFormat = new JpegImageFormat( 100 跨度>);
// 创建一个具有所需宽度和高度的FixedImageSize对象。
var imageSize = new PercentageImageSize( 400 );
// 保存图片。
var imageDataPage1 = rasterizer.Draw(jpegImageFormat,imageSize);
使用( var pd = new PrintDocument())
{
var marginins = new 边距( 0 , 40 , 0 , 40 );
pd.DefaultPageSettings.Margins = margin;
pd.DefaultPageSettings.Color = true ;
pd.DefaultPageSettings.Landscape = false ;
pd.PrintPage + =(sender,args)= > PrintPage(text1,text2,imageDataPage1,args);
pd.Print();
}
}
private static int counter = 0 跨度>;
私有 静态 void PrintPage ( string text1, string text2, byte [] [] imageData,PrintPageEventArgs args)
{
foreach ( var b in imageData)
{
using ( var stream = new MemoryStream(b))
{
var i = Image.FromStream(stream);
CreateNotApprovedWatermark(i,text1,text2);
if (args.PageSettings.PrinterSettings.CanDuplex)
{
args.PageSettings.PrinterSettings.Duplex = Duplex .Horizontal;
}
var m = args.MarginBounds;
if (i.Width /( double )i.Height > m.Width /( double )m.Height) / / 图像更宽
{
m.Height =( int )(i.Height /( double )i.Width * m.Width);
}
else
{
m.Width =( int )(i.Width /( double )i .Height * m.Height);
}
args.Graphics.DrawImage(i,m);
if (counter < = 2 )
{
counter ++;
args.HasMorePages = true ;
}
else
{
args.HasMorePages = false 跨度>;
}
}
}
}
解决方案
< blockquote>我遇到了同样的情况,不幸的是没有找到解决方案,经过这么多的努力,我已经解决了问题。
以下链接一定会帮助您解决问题。
http://technet.weblineindia.com/web/print-multiple-different-formats-of-文件一键式在asp-net / [ ^ ]
如果有反馈请发表您的反馈意见它对你有帮助。
I have an issue regarding printing multiple pages using the code below. It always prints only the last page. Can you guys please help me?
using (var rasterizer = new PdfRasterizer(new Foxit.PDF.Rasterizer.InputPdf(pdfData)))
{
// Create a JpegImageFormat object.
var jpegImageFormat = new JpegImageFormat(100);
// Create a FixedImageSize object with required width and height.
var imageSize = new PercentageImageSize(400);
// Save the image.
var imageDataPage1 = rasterizer.Draw(jpegImageFormat, imageSize);
using (var pd = new PrintDocument())
{
var margins = new Margins(0, 40, 0, 40);
pd.DefaultPageSettings.Margins = margins;
pd.DefaultPageSettings.Color = true;
pd.DefaultPageSettings.Landscape = false;
pd.PrintPage += (sender, args) => PrintPage(text1, text2, imageDataPage1, args);
pd.Print();
}
}
private static int counter = 0;
private static void PrintPage(string text1, string text2, byte[][] imageData, PrintPageEventArgs args)
{
foreach (var b in imageData)
{
using (var stream = new MemoryStream(b))
{
var i = Image.FromStream(stream);
CreateNotApprovedWatermark(i, text1, text2);
if (args.PageSettings.PrinterSettings.CanDuplex)
{
args.PageSettings.PrinterSettings.Duplex = Duplex.Horizontal;
}
var m = args.MarginBounds;
if (i.Width / (double)i.Height > m.Width / (double)m.Height) // image is wider
{
m.Height = (int)(i.Height / (double)i.Width * m.Width);
}
else
{
m.Width = (int)(i.Width / (double)i.Height * m.Height);
}
args.Graphics.DrawImage(i, m);
if (counter <= 2)
{
counter++;
args.HasMorePages = true;
}
else
{
args.HasMorePages = false;
}
}
}
}
解决方案
I have came across the same situation and unfortunatly not found solutions, after so much struggle I have solved issue.
Following link will sure help you to solve your trouble.
http://technet.weblineindia.com/web/print-multiple-different-formats-of-files-in-one-click-in-asp-net/[^]
Please post your feedback if it's helps you.
这篇关于使用PrintDocument打印多个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文