Paper Size Setting

Please help me set the paper size in C # code. I am using api printDocument .. my code

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(); 
+4
source share
4 answers
 PrinterSettings ps = new PrinterSettings(); PrintDocument recordDoc = new PrintDocument(); recordDoc.PrinterSettings = ps; 

here you can set the paper size to "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 is another way to set the size of custom paper

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

Hope this works.

+9
source

Constructor for Paper Size - PaperSize (String, Int32, Int32)

5.0 (5) X 5.0 (5) is too small, If "Custom size" is your line .. or 420 x 594 for A2 ...

and also try listing the size of PaperSize foreach in the printer.PaperSizes file and check if A2 .. or not ..

By default, it sets Rawkind to custom, you also need to install Rawkind, as indicated in http://msdn.microsoft.com/en-us/library/system.drawing.printing.papersize.rawkind.aspx

0
source

I use Visual Basic, with this code I can get a form to show it all in printpreview, still print the page with a cutaway cut to the right.

 PrintForm1.Form = Me PrintForm1.PrinterSettings.DefaultPageSettings.Landscape = True PrintForm1.PrinterSettings.DefaultPageSettings.PaperSize = New Printing.PaperSize("Custom", Me.Height, (Me.Width + 47)) PrintForm1.PrinterSettings.DefaultPageSettings.Margins = New Printing.Margins(3, 3, 3, 3) PrintForm1.PrinterSettings.DefaultPageSettings.PaperSize.RawKind = Printing.PaperKind.A4Small PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview 'PrintForm1.PrintAction = Printing.PrintAction.PrintToPrinter PrintForm1.Print() 'PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable) ' 
0
source

You can use as described below, and the user can set the page size in the settings form.

  private void button1_Click(object sender, EventArgs e) { PrintDialog printdg = new PrintDialog(); if (printdg.ShowDialog() == DialogResult.OK) { PrintDocument pd = new PrintDocument(); pd.PrinterSettings = printdg.PrinterSettings; pd.PrintPage += PrintPage; pd.Print(); pd.Dispose(); } } private void PrintPage(object o, PrintPageEventArgs e) { // Printng logic } 
0
source

All Articles