如何MigraDoc图书馆设置文档方向(所有页面)? [英] How to Set Document Orientation (for All Pages) in MigraDoc Library?

查看:345
本文介绍了如何MigraDoc图书馆设置文档方向(所有页面)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 MigraDoc 以编程方式生成的文字,图片和表格的PDF文件。



我需要设置文件 定位(适用于所有页面)在文档对象到风景



所以我尝试以下。

  document.DefaultPageSetup.Orientation = Orientation.Landscape; 



但我得到以下调试断言错误。

  --------------------------- 
断言失败:中止=退出,重试=调试,忽略=继续
---------------------------

DefaultPageSetup切不可修改

如果我点击忽略,它通过与方向确实风景



不过,我要确保我这个做了正确的道路。



所以,问题是,我怎么设置文档定位为一个文件使用MigraDoc库中的所有页面?



下面是代码的其余部分(所以它可以帮助你获得上下文)

 使用System.Runtime.Remoting.Messaging; 
使用MigraDoc.DocumentObjectModel;

命名空间MyNamespace.PdfReports
{
类文件
{
公共静态文件CreateDocument()
{
//创建新MigraDoc文件
文档的文档=新的文件();
document.Info.Title =称号;
document.Info.Subject =课题;
document.Info.Author =湿婆;
document.DefaultPageSetup.Orientation = Orientation.Landscape;



非常感谢!结果
-Shiva



更新:



解决方案:这里的工作代码的基础上的托马斯的回答如下(为别人谁可能寻找这种解决方案的好处)。

  //创建一个新文档MigraDoc 
文档的文档=新的文件();
// ...
// ......
PAGESETUP PAGESETUP = document.DefaultPageSetup.Clone();
//设置方向
pageSetup.Orientation = Orientation.Landscape;
// ...设置其他页面设置你想在这里...


解决方案

分配 DefaultPageSetup.Clone()来的部分,并修改了的PageFormat



然后修改默认设置的副本并没有断言将失败。



通过你的方法,所有的文件将默认为景观 - 不仅仅是文件将它设置为



这答案适用于<大骨节病> MigraDoc 仅作为唯一的<大骨节病> MigraDoc < /骨节病>使用 DefaultPageSetup



请参阅的这个帖子在PDFsharp论坛其中克隆()用于创建的副本在 DefaultPageSetup


I'm using MigraDoc to programatically generate a PDF file with text, images and tables.

I need to set Document Orientation (for all pages) in the document object to Landscape.

So I tried the following.

document.DefaultPageSetup.Orientation = Orientation.Landscape;

But I get the following debug assertion error.

---------------------------
Assertion Failed: Abort=Quit, Retry=Debug, Ignore=Continue
---------------------------

DefaultPageSetup must not be modified

If I click Ignore, it goes through and the Orientation is indeed Landscape.

However, I want to make sure I am doing this the right way.

So the question is, how do I set the document orientation for all pages in a Document using the MigraDoc library?

Here's the rest of the code (so it helps you get the context)

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;

Many thanks!
-Shiva

UPDATE:

SOLUTION: Here's the working code, based on Thomas' answer below (for the benefit of others who maybe looking for this solution).

// 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...

解决方案

Assign DefaultPageSetup.Clone() to the PageFormat of your section and modify that.

Then you modify a copy of the default settings and no assertion will fail.

With your approach, all documents would default to landscape - not just the document you set it for.

This answer applies to MigraDoc only as only MigraDoc uses DefaultPageSetup.

See this post in the PDFsharp forum where Clone() is used to create a copy of the DefaultPageSetup:

这篇关于如何MigraDoc图书馆设置文档方向(所有页面)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆