Setting the paper size

后端 未结 5 723
灰色年华
灰色年华 2021-02-14 03:49

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

Below is my code:

 ppvw = new PrintPreviewDialog();
 ppvw.Docume         


        
5条回答
  •  情深已故
    2021-02-14 04:24

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

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

    IEnumerable paperSizes = ps.PaperSizes.Cast();
    PaperSize sizeA4 = paperSizes.First(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();
    

    Hope it works.

提交回复
热议问题