Setting the paper size

后端 未结 5 731
灰色年华
灰色年华 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:00

    Constructor for paper size is PaperSize(String, Int32, Int32)

    5.0 (5) X 5.0 (5) is too little,,, Unless "Custom Size" is your string.. or 420 x 594 for A2...

    and also try enumerating foreach PaperSize size in printer.PaperSizes and check whether A2 is there.. or not..

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

    0 讨论(0)
  • 2021-02-14 04:06

    Try this. I think this code will help you to solve this problem.

    Private Sub bt_Save_Click(sender As Object, e As EventArgs) Handles bt_Save.Click
        MsgBox("Saved", MsgBoxStyle.Information)
        If MsgBox("you want to print now?", MsgBoxStyle.Question + vbOKCancel, "Printing") = MsgBoxResult.Ok Then
            Try
                PrintPreviewDialog1.Document = ImportBillPrintDocument
                ImportBillPrintDocument.PrinterSettings.DefaultPageSettings.PaperSize = pkCustomSize1
                ImportBillPrintDocument.DefaultPageSettings.PaperSize = pkCustomSize1
    
                PrintPreviewDialog1.WindowState = FormWindowState.Maximized
                PrintPreviewDialog1.ShowDialog()
            Catch ex As Exception
    
            End Try
    
        End If
    End Sub
    
    0 讨论(0)
  • 2021-02-14 04:10

    You can use as follws and user can set the page size within the setting 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 讨论(0)
  • 2021-02-14 04:21

    I am using Visual Basic, with this code I can get the form to show it all in printpreview, still print a slitely cut page on 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 讨论(0)
  • 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<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();
    

    Hope it works.

    0 讨论(0)
提交回复
热议问题