设定纸张尺寸 [英] Setting the paper size

查看:95
本文介绍了设定纸张尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我如何使用c#代码设置纸张尺寸。我正在使用API​​ printDocument。

Please help me on how to set my paper size in c# code. I am using the API printDocument.

下面是我的代码:

 ppvw = new PrintPreviewDialog();
 ppvw.Document = printDoc;
 ppvw.PrintPreviewControl.StartPage = 0;
 ppvw.PrintPreviewControl.Zoom = 1.0;
 ppvw.PrintPreviewControl.Columns = 10;


 // Showing the Print Preview Page
 printDoc.BeginPrint += new System.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);
 printDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);


 if (ppvw.ShowDialog() != DialogResult.OK)
 {
     printDoc.BeginPrint -= new System.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);
     printDoc.PrintPage -= new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
 }


 printDoc.PrinterSettings.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("a2", 5.0,5.0);
 printDoc.Print();


推荐答案

PrinterSettings ps = new PrinterSettings();
PrintDocument recordDoc = new PrintDocument();
recordDoc.PrinterSettings = ps;

这是一种按 A4之类的纸张尺寸设置方法

here's a way to set the paper size by kind like 'A4' for example

IEnumerable<PaperSize> paperSizes = ps.PaperSizes.Cast<PaperSize>();
PaperSize sizeA4 = paperSizes.First<PaperSize>(size => size.Kind == PaperKind.A4); // setting paper size to A4 size
recordDoc.DefaultPageSettings.PaperSize = sizeA4;

这是设置自定义纸张尺寸的另一种方式

and here's another way to set a custom paper size

recordDoc.DefaultPageSettings.PaperSize = new PaperSize("210 x 297 mm", 800, 800);
PrintPreviewDialog ppvw = new PrintPreviewDialog();
ppvw .Document = recordDoc;
ppvw.ShowDialog();

希望它能起作用。

这篇关于设定纸张尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆