简体   繁体   English

将打印方向设置为横向

[英]Set print orientation to landscape

i already can create a print to print a file in my windows forms. 我已经可以创建一个打印来打印我的Windows窗体中的文件。 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. 我看不到页面的Orientation成为LandScape,它仍然是Portrait。

How do I make it LandScape as default? 如何将LandScape设为默认值? So, whenever i click PrintPreview or PrintFile, the Orientation of the page will become LandScape, not Portrait. 因此,每当我单击PrintPreview或PrintFile时,页面的方向将变为LandScape,而不是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();
    }
}

尝试设置PrintDocument的Landscape ,如下所示,

printDocument1.DefaultPageSettings.Landscape = true;

The pdfprinting.net library is excellent for implementing the print functionality and be productive. pdfprinting.net库非常适合实现打印功能并提高工作效率。 Here is the simple code snippet to set print orientation to landscape(pdfPrint.IsLandscape = true;) 以下是将打印方向设置为横向的简单代码片段(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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM