8

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

printDialog.PrinterSettings.DefaultPageSettings.Landscape = true;

我看不到页面的方向变成风景,它仍然是肖像。

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

这是代码:

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

2 回答 2

24

尝试Landscape如下设置 PrintDocument ,

printDocument1.DefaultPageSettings.Landscape = true;
于 2013-10-02T13:03:24.787 回答
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);
于 2018-03-22T01:25:30.240 回答