0

我使用 abcpdf 从 html 字符串创建 pdf。以下代码段显示了我的操作方式:

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

2 回答 2

0

我可以向您保证,您的插入电话将产生影响。尝试在每个页面上调用 FrameRect,您应该能够看到这一点。

那么,为什么您没有看到您期望的效果呢?

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

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

If in your 'inset' pages you reduce the width of the area then things become more difficult. The width is fixed so it can't be changed. Instead ABCpdf will scale the page down so that it does fit.

So if you reduce the width from say 600 points to 580 points then the scale factor for this content would be 580/600 = 97%.

Most likely this is what is happening but because the scale factor is small you are not noticing it.

I work on ABCpdf and my replies may contain concepts based around ABCpdf. It's what I know. :-)

于 2013-06-18T10:16:27.490 回答
0

Comment #1 from SwissCoder was right. AddImageHtml already adds the first page. After also contacting the WebSuperGoo support, they recommend me to use 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);
}

The other solution would be to adjust the index to count unto required pagenumber - 1 as ÀddImageHtml already adds the first page to the document.

于 2013-06-18T10:41:38.447 回答