C# 将打印方向设置为横向
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19136763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set print orientation to landscape
提问by Kaoru
i already can create a print to print a file in my windows forms. However, whenever i add this code:
我已经可以创建一个打印件来打印我的 Windows 窗体中的文件。但是,每当我添加此代码时:
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.
如何将其设为默认景观?因此,每当我单击 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();
}
}
采纳答案by Kurubaran
try setting the Landscape
of PrintDocument as follows,
尝试设置Landscape
PrintDocument 如下,
printDocument1.DefaultPageSettings.Landscape = true;
回答by Sunil Vishnu Raskar
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;)
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);