我正在使用MigraDoc以编程方式生成包含文本、图像和表格的 PDF 文件。
我需要将文档对象中的Document
方向(所有页面)设置为Landscape
.
所以我尝试了以下方法。
document.DefaultPageSetup.Orientation = Orientation.Landscape;
但我收到以下调试断言错误。
---------------------------
Assertion Failed: Abort=Quit, Retry=Debug, Ignore=Continue
---------------------------
DefaultPageSetup must not be modified
如果我单击Ignore,它会通过并且Orientation
确实是Landscape
。
但是,我想确保我以正确的方式执行此操作。
所以问题是,如何Document
使用 MigraDoc 库为所有页面设置文档方向?
这是其余的代码(因此它可以帮助您获取上下文)
using System.Runtime.Remoting.Messaging;
using MigraDoc.DocumentObjectModel;
namespace MyNamespace.PdfReports
{
class Documents
{
public static Document CreateDocument()
{
// Create a new MigraDoc document
Document document = new Document();
document.Info.Title = "The Title";
document.Info.Subject = "The Subject";
document.Info.Author = "Shiva";
document.DefaultPageSetup.Orientation = Orientation.Landscape;
非常感谢!
-湿婆
更新:
解决方案:这是工作代码,基于Thomas在下面的回答(为了其他可能正在寻找此解决方案的人的利益)。
// Create a new MigraDoc document
Document document = new Document();
//...
//......
PageSetup pageSetup = document.DefaultPageSetup.Clone();
// set orientation
pageSetup.Orientation = Orientation.Landscape;
// ... set other page setting you want here...