1

I'm having hard times with this issue. I've a PDF File with fields so the user can fill them.

I'm using iTextSharp (on vb.net) to open the PDF file, read the fields and write the data back (and show it to the user).

Doc is not locked nor does it have any security measure.

I read it as follows:

Dim readerPDF As New PdfReader(Application.StartupPath & "\PDF\" & filename)
Dim pathTemp = IO.Path.GetTempFileName & ".pdf"
Dim stamperPDF As New PdfStamper(readerPDF, New IO.FileStream(pathTemp, IO.FileMode.Create))
Dim pdfFormFields As AcroFields = stamperPDF.AcroFields 

then I simply loop pdfFormFields (I already have the key for each field saved in the database.

For each f as field_keys 
    pdfFormFields.SetField(f, "dummy text")
Next

This works great for every text input, no problems there. When I have a multiline field this thing goes nasty.

Filling using this approach gives me:

Wrong field

But If I open the original PDF file with Adobe Reader and I write the same I get:

enter image description here

So... I don't even know how to look this up on the internet. Is iTextSharp not supporting this or am I missing something?

EDIT: Link to PDF

EDIT: The itext dll was outdated. Download the lastest one and the problem still occurs.

Esselans
  • 1,540
  • 2
  • 24
  • 44

2 Answers2

0

The issue is likely with the properties of the multi-line field. One issue could be you have a fixed font and that would clip the text on screen when the field overflows. If the font is Auto it shrinks the font as the control fills up.

rheitzman
  • 2,247
  • 3
  • 20
  • 36
0

One thing to understand is that in PDF, the value of a field and the visual appearance of a field are two very different things. The field appearance is there to display the field in cases where the PDF viewer doesn't know what a field or it's value is. I believe the reason you're seeing What you're seeing is that there are some minor... and major... differences between how Adobe Reader generates appearances and how iText generates appearances. To test my theory, simply edit the field in Adobe Reader and see if the problem corrects itself. If it does, the the appearance generator in iText is the problem.

joelgeraci
  • 4,606
  • 1
  • 12
  • 19
  • The same PDF filled with Adobe Reader works fine. The line has a "height" and every new line is written correctly. Using iText somehow miss that and continues writing just below.... I don't find any way to set a line height whatsoever and printing breaklines does not work. – Esselans Nov 10 '16 at 16:29
  • Try using something like stamper.AcroFields.Xfa.FillXfaForm(sourceXml); That will allow Acrobat to format the field using just the data. – joelgeraci Nov 10 '16 at 21:54