I have written an application to programatically fill out a form in a PDF template from a database and save the result to disk. Everything is working correctly apart from any multi-line text fields which are not rendering as expected. They should be top, left aligned with no gaps between lines.
The result I get is here :
However, when I click into the form field using any PDF reader, the field corrects itself to what I would expect. See :
The code I am using is pretty boiler plate stuff.
PdfStamper stamper = new PdfStamper(reader, ms, '\0', false);
AcroFields form = stamper.AcroFields;
List<DocumentField> fields = GetData(id);
foreach (DocumentField field in fields)
{
form.SetField(field.FieldName, field.Value);
}
stamper.FormFlattening = true;
stamper.Close();
reader.Close();
I am using System.Environment.NewLine
to add the carraige returns. Does anyone know what might be causing this behaviour and the solution to make the top left aligned without the large gaps. Thanks.
Update with solution
I removed the field and re-added it and it behaved as expected. What actually seems to be the problem is that I was using a font called 'Cambria' which if I set the field back to using that font, the behaviour returned.