1

I'm having an issue with PDF box flattening a PDF generated by Adobe Acrobat DC.

The Adobe Acrobat text field I created is absolutely the default text field.

In my example below, I have a PatientName field with the text value "Douglas McDouggelman".

When I flatten the PDF, here's what it looks like:

Shows a weird looking spacing

Anyone know what's up with this bizarre spacing?

It appears that the space + next character are combined. This is what it looks like when you try to select that character.

enter image description here

Code:

try (PDDocument document = PDDocument.load(pdfFormInputStream)) {
  PDDocumentCatalog catalog = document.getDocumentCatalog();

  PDAcroForm acroForm = catalog.getAcroForm();

  acroForm.getField("PatientName").setValue("Douglas McDouggelman");
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  if (flattenPdfs) {                    
      acroForm.flatten();
  }
  document.save(byteArrayOutputStream);
}
Nicholas DiPiazza
  • 10,029
  • 11
  • 83
  • 152
  • 2
    Please share the pdf form. – mkl Feb 06 '19 at 18:12
  • Can't send it. security blah blah blah. Can't even make a sample one and upload it due to my local security rules. and I can't make it from an unsecured computer because I do not have adobe acrobat DC on that environment. i'll try to find a way. – Nicholas DiPiazza Feb 06 '19 at 19:15
  • You can download a 30 day trial of adobe acrobat on "that environment" .... (https://acrobat.adobe.com/ua/en/free-trial-download.html) – Lonzak Feb 07 '19 at 10:51
  • Another thing to try: Assuming that it is a PDTextField, please cast and do txtfield.getDefaultAppearance() and output that one. Lets say that the font name is F5 (as in "/F5 12 Tf"). Remember that name and visit https://issues.apache.org/jira/browse/PDFBOX-4233 and see the code lines to replace a font in the default resources. – Tilman Hausherr Feb 08 '19 at 20:14
  • `/Helv 0 Tf 0 g` – Nicholas DiPiazza Feb 08 '19 at 20:36
  • Then try to replace that one with the Arial font, which is very similar - just to see what happens. But it is weird, usually /Helv is a standard 14 font and shouldn't make troubles. – Tilman Hausherr Feb 08 '19 at 21:06
  • ok that did not work at all but it gave me the idea that i got it to work with – Nicholas DiPiazza Feb 08 '19 at 21:18

1 Answers1

1

I realized this PDF was from some other group who made it and who knows what they did. So I found the source word document, repeated the creation of the form from Adobe DC, added the fields back to the document, then it was totally fine.

PDF box was not the problem... it was some unknown incorrect step that the person who originally prepared the pdf did.

Nicholas DiPiazza
  • 10,029
  • 11
  • 83
  • 152