Question

I use abcpdf to create a pdf from a html string. The following snippet shows the way I do it:

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);
}

After the AddPage I want to add a new inset for every page with pagenumber > 2

Thanks in advance

Was it helpful?

Solution 2

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.

OTHER TIPS

I can assure you that your inset call will be having an effect. Try calling FrameRect on each page and you shuld be able to see this.

So why is it that you are not seeing the effect you are expecting?

Well your HTML has a fixed width at the point you call AddImageUrl/HTML. Each subsequent call to AddImageToChain utilizes this fixed width.

If in your 'inset' pages you reduce the height of the area on the page you will get the next chunk of the page truncated to that height.

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. :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top