9 Replies Latest reply on Jul 23, 2007 10:16 AM by Racine

    iText and setExtraMargin

    Racine
      I've been going around and around on trying to get a properly formatted flat pdf created with my data. I have to say that Adobe's ability to actually format a multi-line field as it was presented when it was editable is frustrating. CFMX8, pdfTK and iText all have the same problem of aligning the data in a multi-line field to the top when the pdf is flattened. activePDF is the only app i've found that does the formatting correctly, but they have SO many other issues with correctly populating a complex form that I'm back to trying to make something like iText work correct.
      I found this function for iText called setExtraMargin(); and it works perfect with the values 0, 6 to jog the text down. Now my problem is how to set this dynamicly based on if the the field is multi-line or not.

      I found this bit of code, but I'm not able to figure out how to convert this to <cfscript>. I need to be able to loop over something like this for each form key/value pair I'm inserting back into the pdf template.

      Any help would be great.

      I'm currently testing on MX8 if it makes a difference. Altho i will eventually trying to make this work on a cf4.5.1 server.

      --Dennis--

        • 1. Re: iText and setExtraMagin
          Level 7
          Racine wrote:
          > I'm currently testing on MX8 if it makes a difference. Altho i will eventually
          > trying to make this work on a cf4.5.1 server.

          cf4.5? can't recall, does it do java cfx tags? if not, forget it.

          in any case, first thing is to make sure that code works w/the iText version
          that comes w/cf. what version is that snippet from? if it's very modern then
          you'll probably need to use mark mandel's javaLoader to load the newer jar.

          • 2. Re: iText and setExtraMagin
            Racine Level 1
            My main issue is how to get the multiline attribute out of the field name (PdfFormField.FF_MULTILINE doesn't work in cfscript)
            If I can find out how to get that value the rest of the logic is easy.
            • 3. Re: iText and setExtraMagin
              cf_dev2 Level 1
              Its a static property of the PdfFormField class. Use createObject then you can reference the property.

              <cfscript>
              PdfFormField = createObject("java", "com.lowagie.text.pdf.PdfFormField");
              WriteOutput("The value of PdfFormField.FF_MULTILINE = "& PdfFormField.FF_MULTILINE);
              </cfscript>
              • 4. Re: iText and setExtraMagin
                Racine Level 1
                cool that's what I need. Now how would i request the value of a certain form field? (ie. i have a list of names that I can loop through but need to chk each field for the FF_Multiline value for that field)
                • 5. Re: iText and setExtraMagin
                  cf_dev2 Level 1
                  > but need to chk each field for the FF_Multiline value for that field

                  No. I think PdfFormField.FF_MULTILINE is a constant value used to represent that a field is multi-line.

                  Looks like you extract the field's setting into a variable named "n" here:
                  PdfNumber n = (PdfNumber)merged.get(PdfName.FF);

                  The value is then compared to the constant PdfFormField.FF_MULTILINE. If the values are equal it means the field is multiline.

                  if (n != null && (n.intValue() & PdfFormField.FF_MULTILINE) !=0)
                  af.setExtraMargin(0, 6);
                  }
                  • 6. Re: iText and setExtraMagin
                    Racine Level 1
                    I guess I'm still missing something. Shouldn't I be able to get a value that tells me that a specific field is multiline? I thought the FF_Multiline was specific to a given field?
                    • 7. Re: iText and setExtraMagin
                      Racine Level 1
                      Here is the complete code I have, altho it does not detect the multiline fields properly.

                      • 8. Re: iText and setExtraMagin
                        cf_dev2 Level 1
                        Try this code, maybe it will clarify things. I'm assuming you're using a version of iText that supports setExtraMargin(). MX7 does not.

                        Create a PDFName object before the loop:
                        PdfName = createObject("java","com.lowagie.text.pdf.PdfName");

                        Change the FOR loop to


                        • 9. Re: iText and setExtraMagin
                          Racine Level 1
                          Perfect!

                          For the record, I did have to the alter the code slightly but it works. Too bad this isn't the default. Altho I guess from what i heard this is a acrobat issue of some sort.

                          Thanks again for all the help!