C# iTextSharp 设置文档横向(横向)A4
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2370427/
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
iTextSharp set document landscape (horizontal) A4
提问by Luca Romagnoli
How can I set an A4 document in landscape (horizontal) format in iTextSharp?
如何在 iTextSharp 中以横向(水平)格式设置 A4 文档?
采纳答案by T.J. Crowder
You can set the page size to a rotated A4. E.g. (assuming PDF, but should apply regardless):
您可以将页面大小设置为旋转的 A4。例如(假设为 PDF,但无论如何都应适用):
iTextSharp.text.Document doc;
// ...initialize 'doc'...
// Set the page size
doc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
I've done this with PDF without trouble, haven't tried it with other doc types.
我已经用 PDF 毫无问题地完成了这项工作,还没有用其他文档类型尝试过。
回答by Alexei Bondarev
You can initialize a new document like that:
您可以像这样初始化一个新文档:
Document doc = new Document(iTextSharp.text.PageSize.A4.Rotate(), 10, 10, 10, 10);
In this mode all pages will be in landscape mode.
在此模式下,所有页面都将处于横向模式。
To change the layout of the page inside the document you can use:
要更改文档内页面的布局,您可以使用:
doc.SetPageSize(iTextSharp.text.PageSize.A4); // for vertical layout
doc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate()); // for horizontal layout