请帮我说说如何用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();
希望它有效.