Domanda

I am trying to insert a table into a PDF template. It is successful when the table fits on the page. However, if it is too big then we lose data. I basically just want it to paste what is left of the ColumnText to a next page which looks like page # 5.

Here is my current code, it is creating a blank white page in front of page #4 and it is writing the remaining ColumnText data over where it already pasted the first time.

PdfImportedPage templatePage = stamper.GetImportedPage(pdfReader, 5);

int pageNum = 5;

while (true)
{
      ct.SetSimpleColumn(-75, 50, PageSize.A4.Height + 25, PageSize.A4.Width - 200);
      if (!ColumnText.HasMoreText(ct.Go()))
            break;
      pageNum++;
      stamper.InsertPage(pageNum, new Rectangle(792f, 612f));
      stamper.GetOverContent(pageNum).AddTemplate(templatePage, 0, 0);

} 
È stato utile?

Soluzione

I've created a small code sample named AddLongTable that you can use to complete your code. The reason why all the content is added to the same page is simple. You forgot this line:

ct.setCanvas(stamper.getOverContent(pageNum));

Note that my example is written in Java, but I'm sure you'll know how to adapt it to C#. If you post your fix in a comment, I'll update my answer, adding the C# version of the solution.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top