【发布时间】:2014-05-05 15:27:39
【问题描述】:
我正在使用MigraDoc 以编程方式生成包含文本、图像和表格的 PDF 文件。
我需要将文档对象中的DocumentOrientation(适用于所有页面)设置为Landscape。
所以我尝试了以下方法。
document.DefaultPageSetup.Orientation = Orientation.Landscape;
但我得到以下调试断言错误。
---------------------------
Assertion Failed: Abort=Quit, Retry=Debug, Ignore=Continue
---------------------------
DefaultPageSetup must not be modified
如果我点击忽略,它就会通过,Orientation 确实是Landscape。
但是,我想确保我这样做是正确的。
所以问题是,如何使用 MigraDoc 库为 Document 中的所有页面设置文档方向?
这是其余的代码(因此它可以帮助您获取上下文)
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...
【问题讨论】:
-
DefaultPageSetup 适用于 MigraDoc。实际上这是一个 MigraDoc 问题,而不是 PDFsharp 问题。
-
嗨,Shiva,你刚刚为我解决了我的问题。谢谢你:-) 虽然您的解决方案不包含将修改后的 pageSetup 分配给 section 对象所需的信息。但无论如何:谢谢你:-)
标签: c# pdf-generation migradoc