9

i already can create a print to print a file in my windows forms. However, whenever i add this code:

printDialog.PrinterSettings.DefaultPageSettings.Landscape = true;

I can't see the Orientation of the page become LandScape, it is still Portrait.

How do I make it LandScape as default? So, whenever i click PrintPreview or PrintFile, the Orientation of the page will become LandScape, not Portrait.

Here is the code:

private void PrintPreview(object sender, EventArgs e)
{
    PrintPreviewDialog _PrintPreview = new PrintPreviewDialog();
    _PrintPreview.Document = printDocument1;
    ((Form)_PrintPreview).WindowState = FormWindowState.Maximized;
    _PrintPreview.ShowDialog();
}

private void PrintFile(object sender, EventArgs e)
{
    PrintDialog printDialog = new PrintDialog();
    printDialog.Document = printDocument1;
    printDialog.UseEXDialog = true;

    if (DialogResult.OK == printDialog.ShowDialog())
    {
        printDocument1.DocumentName = "Test Page Print";
        printDocument1.Print();
    }
}
Andre Lombaard
  • 6,985
  • 13
  • 55
  • 96
Kaoru
  • 2,853
  • 14
  • 34
  • 68

2 Answers2

27

try setting the Landscape of PrintDocument as follows,

printDocument1.DefaultPageSettings.Landscape = true;
Flot2011
  • 4,601
  • 3
  • 44
  • 61
Kurubaran
  • 8,696
  • 5
  • 43
  • 65
  • and, what is the `page` sir? – Kaoru Oct 02 '13 at 13:04
  • 3
    This is good. Be advised that `printDocument1.PrinterSettings.DefaultPageSettings.Landscape = true;` did not work. Make sure you have just like the answer and not with `PrinterSettings`. – dev1998 May 01 '19 at 17:07
0

The pdfprinting.net library is excellent for implementing the print functionality and be productive. Here is the simple code snippet to set print orientation to landscape(pdfPrint.IsLandscape = true;)

var pdfPrint = new PdfPrint("demoCompany", "demoKey");
string pdfFile = @"c:\test\test.pdf";
pdfPrint.IsLandscape = true;

int numberOfPages = pdfPrint.GetNumberOfPages(pdfFile);
var status = pdfPrint.Print(pdfFile);
if (status == PdfPrint.Status.OK) { 
     // check the result status of the Print method
     // your code here
}
// if you have pdf document in byte array that is also supported
byte[] pdfContent = YourCustomMethodWhichReturnsPdfDocumentAsByteArray();
status = pdfPrint.Print(pdfFile);