Set print orientation to landscape

ぐ巨炮叔叔 提交于 2020-02-14 05:41:49

问题


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();
    }
}

回答1:


try setting the Landscape of PrintDocument as follows,

printDocument1.DefaultPageSettings.Landscape = true;



回答2:


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);


来源:https://stackoverflow.com/questions/19136763/set-print-orientation-to-landscape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!