请帮助我如何在C#代码中设置纸张尺寸。我正在使用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”等类型设置纸张尺寸的方法
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;
这是设置自定义纸张尺寸的另一种方法
recordDoc.DefaultPageSettings.PaperSize = new PaperSize("210 x 297 mm", 800, 800);
PrintPreviewDialog ppvw = new PrintPreviewDialog();
ppvw .Document = recordDoc;
ppvw.ShowDialog();
希望它能工作。
关于c# - 设定纸张尺寸,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/684801/