【问题标题】:Change the inset of a specific page with abcpdf使用 abcpdf 更改特定页面的插图
【发布时间】:2013-04-08 09:17:57
【问题描述】:

我使用 abcpdf 从 html 字符串创建 pdf。以下 sn-p 显示了我的做法:

var pdfDocument = new Doc();
pdfDocument.Page = pdfDocument.AddPage();

pdfDocument.Font = pdfDocument.AddFont("Times-Roman");
pdfDocument.FontSize = 12;

var documentId = pdfDocument.AddImageHtml(innerHtml);
var counter = 0;

while (true)
{
    counter++;
    if (!pdfDocument.Chainable(documentId))
    {
        break;
    }


    pdfDocument.Page = pdfDocument.AddPage();

    // how to add a inset of 20, 0 on every page after the second? The following 2lines don't affect the pdf pages
    if (counter >= 3)
        pdfDocument.Rect.Inset(20, 0);                

    documentId = pdfDocument.AddImageToChain(documentId);
}

在 AddPage 之后,我想为每个 pagenumber > 2 的页面添加一个新的插图

提前致谢

【问题讨论】:

  • 实际上您对计数器的检查只会影响添加的第 4 页,而不是第 3 页,因为在您调用 AddImageHtml 时已经添加了第一页

标签: c# asp.net .net abcpdf


【解决方案1】:

我可以向您保证,您的 inset 调用将会产生效果。尝试在每个页面上调用 FrameRect,您应该能够看到这一点。

那么为什么没有看到预期的效果呢?

您的 HTML 在您调用 AddImageUrl/HTML 时具有固定宽度。对 AddImageToChain 的每个后续调用都使用此固定宽度。

如果在“插入”页面中降低页面区域的高度,则页面的下一部分将被截断到该高度。

如果在“插入”页面中减小区域的宽度,事情就会变得更加困难。宽度是固定的,因此无法更改。相反,ABCpdf 将缩小页面以使其适合。

因此,如果您将宽度从 600 点减少到 580 点,则此内容的比例因子将为 580/600 = 97%。

这很可能是正在发生的事情,但由于比例因子很小,您不会注意到它。

我从事 ABCpdf 工作,我的回复可能包含基于 ABCpdf 的概念。这是我所知道的。 :-)

【讨论】:

  • 很抱歉放弃这个话题。正如 SwissCoder 所写,我的逻辑只影响具有 PageNumber 4 及以上的页面。我的错误是the first page is already added when you call AddImageHtml
【解决方案2】:

SwissCoder 的第 1 条评论是正确的。 AddImageHtml 已经添加了第一页。在联系了 WebSuperGoo 支持后,他们建议我使用 PageCountof class Doc

while (true)
{
    if (!pdfDocument.Chainable(documentId))
    {
        break;
    }

    pdfDocument.Page = pdfDocument.AddPage();

    if (pdfDocument.PageCount >= 3)
        pdfDocument.Rect.Inset(0, 20);
    documentId = pdfDocument.AddImageToChain(documentId);
}

另一种解决方案是调整索引以计数到 required pagenumber - 1,因为 ÀddImageHtml 已经将第一页添加到文档中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-03
    • 2012-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-17
    • 2013-09-16
    相关资源
    最近更新 更多