【问题标题】:ABCPdf change orientation of a specific pageABCPdf 改变特定页面的方向
【发布时间】:2018-03-14 09:18:44
【问题描述】:

下面的代码创建一个横向的新 PDF。它使用 ABCPdf 组件。

static void Main(string[] args)
{
    var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "da.pdf");

    var theDoc = new Doc();
    //theDoc.Read(filePath);

    // apply a rotation transform
    theDoc.MediaBox.String = "Legal";
    double w = theDoc.MediaBox.Width;
    double h = theDoc.MediaBox.Height;
    double l = theDoc.MediaBox.Left;
    double b = theDoc.MediaBox.Bottom;
    theDoc.Transform.Rotate(90, l, b);
    theDoc.Transform.Translate(w, 0);

    // rotate our rectangle
    theDoc.Rect.Width = h;
    theDoc.Rect.Height = w;

    // add some text
    theDoc.Rect.Inset(50, 50);
    theDoc.FontSize = 96;
    theDoc.AddText("Landscape Orientation");
    theDoc.AddPage();
    theDoc.PageNumber = theDoc.PageCount;
    theDoc.AddText("Page 2");

    // adjust the default rotation and save
    int theID = theDoc.GetInfoInt(theDoc.Root, "Pages");
    theDoc.SetInfo(theID, "/Rotate", "90");
    theDoc.Save(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "out.pdf"));
    theDoc.Clear();
}

我想打开一个现有的 PDF 并使用 ABCPdf 将特定页面的方向更改为横向,而不是创建新的 pdf。比如第一页是纵向的,第二页是横向的。

谢谢

【问题讨论】:

    标签: c# abcpdf


    【解决方案1】:

    您可以这样做,或者使用“AddImageDoc”方法,插入修改后的页面...

    但是

    Abcpdf 不允许覆盖源文件。来自“保存方法文档”:

    ABCpdf 运行智能即时对象加载方案 确保只加载那些需要的对象 进入记忆。这意味着如果您正在修改大型文档,那么 服务器负载将保持在最低限度。原始 PDF 文件必须 只要 Doc 对象被使用,就可以使用。

    因此您无法在读取 PDF 文件时对其进行修改或覆盖 放入一个 Doc 对象。您需要将 PDF 保存到另一个位置 然后在 Doc 对象使用 PDF 结束(调用 Clear、Dispose 或 Read with another PDF 文件)。

    所以你总是需要一个“新的 pdf”。

    【讨论】:

    • 没关系。更改完成后,我不介意将文件另存为新的 pdf。我会试试 AddImageDoc,很快就会回来。
    猜你喜欢
    • 1970-01-01
    • 2020-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 2015-01-13
    相关资源
    最近更新 更多