0

I have created a PDF template to format passed string data fields into java function containing itext code (below). One of the strings passed (F13 in example) is to be used in paragraph contained in template. I think because is a text field in the template the paragraph is not being wrapped correctly. See this example with highlighted sentence for results>>>

PDF document created using template and string where paragraph should be:

PDF document created using template and string where paragraph should be.

The paragraph should instead appear as following: "The result can be seen below, which shows the text having been written to the document but it looks a mess. Chunks have no concept of how to force a new line when the length exceeds the available width in the document. Really, all they should be used for is to change or set the style of a word or phrase inline. "

public class ABC_PDF_CreateAndFill4 {

public static final String SRC = 
  "C:\\Users\\XXX\\Documents\\iTextPDF\\Template\\PDFtest_062320_v3.pdf";
  public static final String DEST = // 
 "C:\\Users\\XXXX\\Documents\\iTextPDF\\PDFtest_11.pdf";
 .
 .
 .
// manipulatePDF called from external routine passing parms.   

public void manipulatePdf(String S1, String D1, String F1, String F2, 
String F3, String F4, String F5, String F6, String F7, String F8, String 
F9, String F10, String F11, String F12, String F13, String F14, String 
F15, String F16, String F17, String F18, String F19, String F20, String 
F21  ) 
               throws IOException, DocumentException {
               PdfStamper stamper;
               int i = 0;
                       
               PdfReader reader = new PdfReader(S1);           
               AcroFields form = reader.getAcroFields();       
               AcroFields fields = reader.getAcroFields();
       
               stamper = new PdfStamper(reader, new FileOutputStream(D1));
                          
               fill(stamper.getAcroFields(), F1, F2, F3, F4, F5, F6, F7, 
      F8, F9, F10, F11, F12, F13, F14, F15, F16, F17, F18, F19, F20, F21 );
      
               stamper.setFormFlattening(true);
               stamper.close();
       }
         
       
        public static void fill( AcroFields form, String F1, String F2, 
        String F3, String F4, String F5, String F6, String F7, String F8, 
        String F9, String F10, String F11, String F12, String F13, String 
        F14, String F15, String F16, String F17, String F18, String F19, 
        String F20, String F21  )
             throws IOException, DocumentException {         
                    
           
             form.setField("F02_RO_Address_Line1", F1); // 1
             form.setField("F03_RO_Address_Line2", F2); // 2
             form.setField("F22_Addressee", F3); // 3
             form.setField("F23_Adress_Line1", F4); // 4
             form.setField("F24_Address_Line2", F5); // 5
             form.setField("F25_Address_Line3", F6); // 6
             form.setField("F26_Address_Line4", F7); // 7
             form.setField("F01_Notice_Date", F8); // 8
             form.setField("F04_Company_Name_Line1", F9); // 9
             form.setField("F05_Company_Name_Line2", F10); // 10
             form.setField("F08_RO_Postal_Address_Line1", F11); // 11
             form.setField("F09_RO_Postal_Address_Line2", F12); // 12
             form.setField("RTField", F13);  // Text field paragraph
             form.setField("F111_Emc2_Indicator", F14); // 14
             form.setField("F238_Enclosure", F15); // 15
             form.setField("Enclosure", F16); // 16
             form.setField("F11_Agents_Name_Copy", F17); // 17
             form.setField("F12_Agent_Phone", F18); // 18
             form.setField("F06_Requester_ID", F19); // 19;
             form.setField("ShortForm", F20); // 20;
             form.setField("Display_Agent_Code", F21); // 21;        
            

This article is close to what I may need to do. How to format text in pdf template with iText

mkl
  • 90,588
  • 15
  • 125
  • 265
  • Hi, wellcome to SO. sorry, I can t understand what you are trying to do. Please, elaborate your answer with something we can reproduce, and try to format the code better. Thank you. – aironman Sep 03 '20 at 19:23
  • I cleaned up a bit hope it helps if need to do more let me know. – William Campbell Sep 04 '20 at 14:57
  • 1
    You don't share the template PDF, so we have to guess. Have you probably forgotten to set the **Multiline** flag of the field you expect to contain text in multiple lines? – mkl Sep 04 '20 at 16:35
  • Thanks I checked the open office odt field used for this and to create a multi-line field a text box is to be selected and a text type of multi-line or multi-line with formatting can be selected. – William Campbell Sep 21 '20 at 21:41

0 Answers0