将打印方向设置为横向

时间:2013-10-02 12:21:40

标签: c# winforms printing

我已经可以创建一个打印来打印我的Windows窗体中的文件。但是,每当我添加此代码时:

printDialog.PrinterSettings.DefaultPageSettings.Landscape = true;

我看不到页面的Orientation成为LandScape,它仍然是Portrait。

如何将LandScape设为默认值?因此,每当我单击PrintPreview或PrintFile时,页面的方向将变为LandScape,而不是Portrait。

以下是代码:

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

2 个答案:

答案 0 :(得分:16)

尝试按如下方式设置PrintDocument的Landscape

printDocument1.DefaultPageSettings.Landscape = true;

答案 1 :(得分:0)

pdfprinting.net库非常适合实现打印功能并提高工作效率。以下是将打印方向设置为横向的简单代码段(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);