Update:
After some discussion, we decided to go with TeX, specifically the windows compatible MiKTeX. We realised that even if we could get the dynamic lengthed table formatted by micromanaging the layout (which doesn't seem possible or is as tedious as calculating row height for each row), there are other dynamic controls like large text boxes that we would also need to micromanage so we decided to generate the whole doc on the fly. With that in mind, going to TeX was the obvious choice because of it's power and our prior experience with it and now after a week, I'm glad we went that way because all our reports are dynamically generated and the code behind is clean and minimal.
Original:
I've got a pdf form template generated using LiveCycle and I want to fill it in (pdfstamper) and add some tables (pdfptable), however it's proven to be more difficult than I initially thought.
I open a pdf and use pdfstamper to edit the static fields:
using (var outputPDF1 = new MemoryStream())
{
var pdfReader = new PdfReader(pdf);
var pdfStamper = new PdfStamper(pdfReader, outputPDF1);
var pdfFields = pdfStamper.AcroFields;
pdfFields.SetField("Field1", "Value1");
This is straight forward and clear.
Then I attempt to add a table that will go from a set location over several pages. There is an attempt of this here that is 3 years old with a much older version of itextsharp and it's very manual.
The crux of that code is to use GetOverContent to insert a ColumnText with the generated table however this requires knowing the table height and manually cutting the table to size
var cb = pdfStamper.GetOverContent(1);
var ct = new ColumnText(cb);
ct.Alignment = Element.ALIGN_CENTER;
ct.SetSimpleColumn(36, 36, PageSize.A4.Width-36, PageSize.A4.Height-300);
ct.AddElement(table);
ct.Go();
There is another answer Itextsharp: Adjust 2 elements on exactly one page which is limited to a single page table. It can be extendable but it seems like you'd have to calculate headers/footers as well on subsequent pages.
And various unanswered questions in the same general direction:
adding a dynamic Table to an pdf template
itextsharp place Pdfptable at desired position
So my question is, what is the current best way to statically create a pdf using a WYSIWYG editor and modify it to add dynamic sized content such as a table or arbitrary lengthed text? I don't want to generate one from scratch if we can use a WYSIWYG LiveCycle to get the template working, but if getting a table formatted for a pdf template takes more effort than generating the whole thing on the fly, then i'd rather generate the whole pdf on the fly using itextsharp.