• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

iText and setExtraMargin

Community Beginner ,
Jul 20, 2007 Jul 20, 2007

Copy link to clipboard

Copied

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--

TOPICS
Advanced techniques

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Jul 23, 2007 Jul 23, 2007
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!

Votes

Translate

Translate
LEGEND ,
Jul 20, 2007 Jul 20, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 20, 2007 Jul 20, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 20, 2007 Jul 20, 2007

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 20, 2007 Jul 20, 2007

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 20, 2007 Jul 20, 2007

Copy link to clipboard

Copied

> 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);
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 20, 2007 Jul 20, 2007

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 20, 2007 Jul 20, 2007

Copy link to clipboard

Copied

Here is the complete code I have, altho it does not detect the multiline fields properly.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 21, 2007 Jul 21, 2007

Copy link to clipboard

Copied

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


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 23, 2007 Jul 23, 2007

Copy link to clipboard

Copied

LATEST
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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation