You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Rajeev Menon <ra...@gmail.com> on 2014/10/14 21:07:43 UTC

Multi-line text or wrap to next line Issue

Hello,

I am using PDFBox to populate data on a PDF form (AcroForm). Here is a
sample code that I am using to fill the data on to the PDF.

    public void fillPDF(HashMap<String, String> mpData) {
        try {
            PDDocumentCatalog docCatalog = pdfDoc.getDocumentCatalog();
            PDAcroForm acroForm = docCatalog.getAcroForm();

            Iterator<Entry<String, String>> itrData =
mpData.entrySet().iterator();
            while (itrData.hasNext()) {
                Entry<String, String> entryData = itrData.next();
                PDField fldPD = acroForm.getField(entryData.getKey());
                if (fldPD!=null) {
                    fldPD.setValue(entryData.getValue());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


If one of the strings is "First line \n Second line \n Third line", how do
I populate this text to the PDF so that each piece of text will be on a new
line in the field. Please advise.

Thanks.
Reevs.

Re: Multi-line text or wrap to next line Issue

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
yes, you need to figure out where to insert the „\n“.

BTW we are working on getting the forms functionality enhanced in PDFBox 2.0 - and this is an area I’m looking into. 

BR

Maruan Sahyoun

Am 21.10.2014 um 17:50 schrieb Rajeev Menon <ra...@gmail.com>:

> Hi Maruan,
> 
> Are you saying, I need to insert "\n" where it needs to wrap and the steps
> you mentioned earlier was to figure out where to insert the "\n"?
> 
> Or, the steps you mentioned is to enable auto wrapping of lines (like the
> pdf will do on it's own)?
> 
> Thanks,
> Rajeev.
> 
> On Wed, Oct 15, 2014 at 9:11 AM, Maruan Sahyoun <sa...@fileaffairs.de>
> wrote:
> 
>> Hi,
>> 
>> when you look at the field the presentation is determined by the fields
>> appearance. When you click into the field the PDF Viewing application takes
>> over and uses the fields value.
>> 
>> When you fill a field using PDFBox (or any other PDF lib/tool) the value
>> is taken and from that the appearance is generated. PDFBox doesn't
>> currently support automatic line wrapping (but we are working on it for the
>> 2.0 release).
>> 
>> As a workaround you can regenerate the appearance after the value has been
>> set and the (insufficient) appearance has been generated.
>> 
>> In principal for that you need to
>> 
>> # get the field
>> # get the field appearance
>> # get the fields bounding box
>> # add some padding
>> # calculate additional line breaks by using  -> float width =
>> font.getStringWidth(text.substring(start,i)) / 1000 * fontSize;
>> # set the annotation
>> 
>> BR
>> Maruan
>> 
>> Am 15.10.2014 um 14:57 schrieb Rajeev Menon <ra...@gmail.com>:
>> 
>>> I tried the string with the "\n" and it successfully inserted new lines
>> in
>>> the multi-line field in the PDF Form.
>>> 
>>> However, the text in a line that is too long doesn't automatically wrap
>> to
>>> next line. When I click in the field, the text wraps to next line and if
>> I
>>> click outside the field, the text shows as single line (cutting off the
>>> content that cannot fit in the field).
>>> 
>>> Is there anyway to fix this issue?
>>> 
>>> On Tue, Oct 14, 2014 at 7:55 PM, Rajeev Menon <ra...@gmail.com>
>>> wrote:
>>> 
>>>> Thx Mauran. I didn't know that approach will work. I will try it.
>>>> 
>>>> 
>>>> On Tuesday, October 14, 2014, Maruan Sahyoun <sa...@fileaffairs.de>
>>>> wrote:
>>>> 
>>>>> Hi,
>>>>> 
>>>>> just pass it with the line breaks within the string and make sure the
>>>>> multiline property for the field is set.
>>>>> 
>>>>> Maruan
>>>>> 
>>>>> Am 14.10.2014 um 21:07 schrieb Rajeev Menon <ra...@gmail.com>:
>>>>> 
>>>>>> Hello,
>>>>>> 
>>>>>> I am using PDFBox to populate data on a PDF form (AcroForm). Here is a
>>>>>> sample code that I am using to fill the data on to the PDF.
>>>>>> 
>>>>>>  public void fillPDF(HashMap<String, String> mpData) {
>>>>>>      try {
>>>>>>          PDDocumentCatalog docCatalog = pdfDoc.getDocumentCatalog();
>>>>>>          PDAcroForm acroForm = docCatalog.getAcroForm();
>>>>>> 
>>>>>>          Iterator<Entry<String, String>> itrData =
>>>>>> mpData.entrySet().iterator();
>>>>>>          while (itrData.hasNext()) {
>>>>>>              Entry<String, String> entryData = itrData.next();
>>>>>>              PDField fldPD = acroForm.getField(entryData.getKey());
>>>>>>              if (fldPD!=null) {
>>>>>>                  fldPD.setValue(entryData.getValue());
>>>>>>              }
>>>>>>          }
>>>>>>      } catch (Exception e) {
>>>>>>          e.printStackTrace();
>>>>>>      }
>>>>>> 
>>>>>>  }
>>>>>> 
>>>>>> 
>>>>>> If one of the strings is "First line \n Second line \n Third line",
>> how
>>>>> do
>>>>>> I populate this text to the PDF so that each piece of text will be on
>> a
>>>>> new
>>>>>> line in the field. Please advise.
>>>>>> 
>>>>>> Thanks.
>>>>>> Reevs.
>>>>> 
>>>>> 
>> 
>> 


Re: Multi-line text or wrap to next line Issue

Posted by Rajeev Menon <ra...@gmail.com>.
Hi Maruan,

Are you saying, I need to insert "\n" where it needs to wrap and the steps
you mentioned earlier was to figure out where to insert the "\n"?

Or, the steps you mentioned is to enable auto wrapping of lines (like the
pdf will do on it's own)?

Thanks,
Rajeev.

On Wed, Oct 15, 2014 at 9:11 AM, Maruan Sahyoun <sa...@fileaffairs.de>
wrote:

> Hi,
>
> when you look at the field the presentation is determined by the fields
> appearance. When you click into the field the PDF Viewing application takes
> over and uses the fields value.
>
> When you fill a field using PDFBox (or any other PDF lib/tool) the value
> is taken and from that the appearance is generated. PDFBox doesn't
> currently support automatic line wrapping (but we are working on it for the
> 2.0 release).
>
> As a workaround you can regenerate the appearance after the value has been
> set and the (insufficient) appearance has been generated.
>
> In principal for that you need to
>
> # get the field
> # get the field appearance
> # get the fields bounding box
> # add some padding
> # calculate additional line breaks by using  -> float width =
> font.getStringWidth(text.substring(start,i)) / 1000 * fontSize;
> # set the annotation
>
> BR
> Maruan
>
> Am 15.10.2014 um 14:57 schrieb Rajeev Menon <ra...@gmail.com>:
>
> > I tried the string with the "\n" and it successfully inserted new lines
> in
> > the multi-line field in the PDF Form.
> >
> > However, the text in a line that is too long doesn't automatically wrap
> to
> > next line. When I click in the field, the text wraps to next line and if
> I
> > click outside the field, the text shows as single line (cutting off the
> > content that cannot fit in the field).
> >
> > Is there anyway to fix this issue?
> >
> > On Tue, Oct 14, 2014 at 7:55 PM, Rajeev Menon <ra...@gmail.com>
> > wrote:
> >
> >> Thx Mauran. I didn't know that approach will work. I will try it.
> >>
> >>
> >> On Tuesday, October 14, 2014, Maruan Sahyoun <sa...@fileaffairs.de>
> >> wrote:
> >>
> >>> Hi,
> >>>
> >>> just pass it with the line breaks within the string and make sure the
> >>> multiline property for the field is set.
> >>>
> >>> Maruan
> >>>
> >>> Am 14.10.2014 um 21:07 schrieb Rajeev Menon <ra...@gmail.com>:
> >>>
> >>>> Hello,
> >>>>
> >>>> I am using PDFBox to populate data on a PDF form (AcroForm). Here is a
> >>>> sample code that I am using to fill the data on to the PDF.
> >>>>
> >>>>   public void fillPDF(HashMap<String, String> mpData) {
> >>>>       try {
> >>>>           PDDocumentCatalog docCatalog = pdfDoc.getDocumentCatalog();
> >>>>           PDAcroForm acroForm = docCatalog.getAcroForm();
> >>>>
> >>>>           Iterator<Entry<String, String>> itrData =
> >>>> mpData.entrySet().iterator();
> >>>>           while (itrData.hasNext()) {
> >>>>               Entry<String, String> entryData = itrData.next();
> >>>>               PDField fldPD = acroForm.getField(entryData.getKey());
> >>>>               if (fldPD!=null) {
> >>>>                   fldPD.setValue(entryData.getValue());
> >>>>               }
> >>>>           }
> >>>>       } catch (Exception e) {
> >>>>           e.printStackTrace();
> >>>>       }
> >>>>
> >>>>   }
> >>>>
> >>>>
> >>>> If one of the strings is "First line \n Second line \n Third line",
> how
> >>> do
> >>>> I populate this text to the PDF so that each piece of text will be on
> a
> >>> new
> >>>> line in the field. Please advise.
> >>>>
> >>>> Thanks.
> >>>> Reevs.
> >>>
> >>>
>
>

Re: Multi-line text or wrap to next line Issue

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
you can take a look at the source of 

org/apache/pdfbox/pdmodel/interactive/form/PDAppearance.java for the current version or 
org/apache/pdfbox/pdmodel/interactive/form/PDAppearanceString.java if you are working with trunk


BR
Maruan

Am 15.10.2014 um 17:03 schrieb Rajeev Menon <ra...@gmail.com>:

> I did a lot of search, couldn't find any sample code. The closest I can get
> is the following.
> 
> fldPD.getWidget().getAppearance()
> 
> Please share any code sample you  have.
> 
> I got the following code that makes the font color red, but again until I
> click the field the text isn't showing.
> 
>                        COSDictionary dict = fldPD.getDictionary();
>                        COSString defaultAppearance = (COSString)
> dict.getDictionaryObject(COSName.DA);
>                        if (defaultAppearance != null)
>                            dict.setString(COSName.DA,
> defaultAppearance.getString() + " 1 0 0 rg ");
> 
> 
> Thanks, Reevs.
> 
> On Wed, Oct 15, 2014 at 9:11 AM, Maruan Sahyoun <sa...@fileaffairs.de>
> wrote:
> 
>> Hi,
>> 
>> when you look at the field the presentation is determined by the fields
>> appearance. When you click into the field the PDF Viewing application takes
>> over and uses the fields value.
>> 
>> When you fill a field using PDFBox (or any other PDF lib/tool) the value
>> is taken and from that the appearance is generated. PDFBox doesn't
>> currently support automatic line wrapping (but we are working on it for the
>> 2.0 release).
>> 
>> As a workaround you can regenerate the appearance after the value has been
>> set and the (insufficient) appearance has been generated.
>> 
>> In principal for that you need to
>> 
>> # get the field
>> # get the field appearance
>> # get the fields bounding box
>> # add some padding
>> # calculate additional line breaks by using  -> float width =
>> font.getStringWidth(text.substring(start,i)) / 1000 * fontSize;
>> # set the annotation
>> 
>> BR
>> Maruan
>> 
>> Am 15.10.2014 um 14:57 schrieb Rajeev Menon <ra...@gmail.com>:
>> 
>>> I tried the string with the "\n" and it successfully inserted new lines
>> in
>>> the multi-line field in the PDF Form.
>>> 
>>> However, the text in a line that is too long doesn't automatically wrap
>> to
>>> next line. When I click in the field, the text wraps to next line and if
>> I
>>> click outside the field, the text shows as single line (cutting off the
>>> content that cannot fit in the field).
>>> 
>>> Is there anyway to fix this issue?
>>> 
>>> On Tue, Oct 14, 2014 at 7:55 PM, Rajeev Menon <ra...@gmail.com>
>>> wrote:
>>> 
>>>> Thx Mauran. I didn't know that approach will work. I will try it.
>>>> 
>>>> 
>>>> On Tuesday, October 14, 2014, Maruan Sahyoun <sa...@fileaffairs.de>
>>>> wrote:
>>>> 
>>>>> Hi,
>>>>> 
>>>>> just pass it with the line breaks within the string and make sure the
>>>>> multiline property for the field is set.
>>>>> 
>>>>> Maruan
>>>>> 
>>>>> Am 14.10.2014 um 21:07 schrieb Rajeev Menon <ra...@gmail.com>:
>>>>> 
>>>>>> Hello,
>>>>>> 
>>>>>> I am using PDFBox to populate data on a PDF form (AcroForm). Here is a
>>>>>> sample code that I am using to fill the data on to the PDF.
>>>>>> 
>>>>>>  public void fillPDF(HashMap<String, String> mpData) {
>>>>>>      try {
>>>>>>          PDDocumentCatalog docCatalog = pdfDoc.getDocumentCatalog();
>>>>>>          PDAcroForm acroForm = docCatalog.getAcroForm();
>>>>>> 
>>>>>>          Iterator<Entry<String, String>> itrData =
>>>>>> mpData.entrySet().iterator();
>>>>>>          while (itrData.hasNext()) {
>>>>>>              Entry<String, String> entryData = itrData.next();
>>>>>>              PDField fldPD = acroForm.getField(entryData.getKey());
>>>>>>              if (fldPD!=null) {
>>>>>>                  fldPD.setValue(entryData.getValue());
>>>>>>              }
>>>>>>          }
>>>>>>      } catch (Exception e) {
>>>>>>          e.printStackTrace();
>>>>>>      }
>>>>>> 
>>>>>>  }
>>>>>> 
>>>>>> 
>>>>>> If one of the strings is "First line \n Second line \n Third line",
>> how
>>>>> do
>>>>>> I populate this text to the PDF so that each piece of text will be on
>> a
>>>>> new
>>>>>> line in the field. Please advise.
>>>>>> 
>>>>>> Thanks.
>>>>>> Reevs.
>>>>> 
>>>>> 
>> 
>> 


Re: Multi-line text or wrap to next line Issue

Posted by Rajeev Menon <ra...@gmail.com>.
I did a lot of search, couldn't find any sample code. The closest I can get
is the following.

fldPD.getWidget().getAppearance()

Please share any code sample you  have.

I got the following code that makes the font color red, but again until I
click the field the text isn't showing.

                        COSDictionary dict = fldPD.getDictionary();
                        COSString defaultAppearance = (COSString)
dict.getDictionaryObject(COSName.DA);
                        if (defaultAppearance != null)
                            dict.setString(COSName.DA,
defaultAppearance.getString() + " 1 0 0 rg ");


Thanks, Reevs.

On Wed, Oct 15, 2014 at 9:11 AM, Maruan Sahyoun <sa...@fileaffairs.de>
wrote:

> Hi,
>
> when you look at the field the presentation is determined by the fields
> appearance. When you click into the field the PDF Viewing application takes
> over and uses the fields value.
>
> When you fill a field using PDFBox (or any other PDF lib/tool) the value
> is taken and from that the appearance is generated. PDFBox doesn't
> currently support automatic line wrapping (but we are working on it for the
> 2.0 release).
>
> As a workaround you can regenerate the appearance after the value has been
> set and the (insufficient) appearance has been generated.
>
> In principal for that you need to
>
> # get the field
> # get the field appearance
> # get the fields bounding box
> # add some padding
> # calculate additional line breaks by using  -> float width =
> font.getStringWidth(text.substring(start,i)) / 1000 * fontSize;
> # set the annotation
>
> BR
> Maruan
>
> Am 15.10.2014 um 14:57 schrieb Rajeev Menon <ra...@gmail.com>:
>
> > I tried the string with the "\n" and it successfully inserted new lines
> in
> > the multi-line field in the PDF Form.
> >
> > However, the text in a line that is too long doesn't automatically wrap
> to
> > next line. When I click in the field, the text wraps to next line and if
> I
> > click outside the field, the text shows as single line (cutting off the
> > content that cannot fit in the field).
> >
> > Is there anyway to fix this issue?
> >
> > On Tue, Oct 14, 2014 at 7:55 PM, Rajeev Menon <ra...@gmail.com>
> > wrote:
> >
> >> Thx Mauran. I didn't know that approach will work. I will try it.
> >>
> >>
> >> On Tuesday, October 14, 2014, Maruan Sahyoun <sa...@fileaffairs.de>
> >> wrote:
> >>
> >>> Hi,
> >>>
> >>> just pass it with the line breaks within the string and make sure the
> >>> multiline property for the field is set.
> >>>
> >>> Maruan
> >>>
> >>> Am 14.10.2014 um 21:07 schrieb Rajeev Menon <ra...@gmail.com>:
> >>>
> >>>> Hello,
> >>>>
> >>>> I am using PDFBox to populate data on a PDF form (AcroForm). Here is a
> >>>> sample code that I am using to fill the data on to the PDF.
> >>>>
> >>>>   public void fillPDF(HashMap<String, String> mpData) {
> >>>>       try {
> >>>>           PDDocumentCatalog docCatalog = pdfDoc.getDocumentCatalog();
> >>>>           PDAcroForm acroForm = docCatalog.getAcroForm();
> >>>>
> >>>>           Iterator<Entry<String, String>> itrData =
> >>>> mpData.entrySet().iterator();
> >>>>           while (itrData.hasNext()) {
> >>>>               Entry<String, String> entryData = itrData.next();
> >>>>               PDField fldPD = acroForm.getField(entryData.getKey());
> >>>>               if (fldPD!=null) {
> >>>>                   fldPD.setValue(entryData.getValue());
> >>>>               }
> >>>>           }
> >>>>       } catch (Exception e) {
> >>>>           e.printStackTrace();
> >>>>       }
> >>>>
> >>>>   }
> >>>>
> >>>>
> >>>> If one of the strings is "First line \n Second line \n Third line",
> how
> >>> do
> >>>> I populate this text to the PDF so that each piece of text will be on
> a
> >>> new
> >>>> line in the field. Please advise.
> >>>>
> >>>> Thanks.
> >>>> Reevs.
> >>>
> >>>
>
>

Re: Multi-line text or wrap to next line Issue

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,

when you look at the field the presentation is determined by the fields appearance. When you click into the field the PDF Viewing application takes over and uses the fields value.

When you fill a field using PDFBox (or any other PDF lib/tool) the value is taken and from that the appearance is generated. PDFBox doesn’t currently support automatic line wrapping (but we are working on it for the 2.0 release).

As a workaround you can regenerate the appearance after the value has been set and the (insufficient) appearance has been generated.

In principal for that you need to 

# get the field
# get the field appearance 
# get the fields bounding box
# add some padding
# calculate additional line breaks by using  -> float width = font.getStringWidth(text.substring(start,i)) / 1000 * fontSize;
# set the annotation

BR
Maruan

Am 15.10.2014 um 14:57 schrieb Rajeev Menon <ra...@gmail.com>:

> I tried the string with the "\n" and it successfully inserted new lines in
> the multi-line field in the PDF Form.
> 
> However, the text in a line that is too long doesn't automatically wrap to
> next line. When I click in the field, the text wraps to next line and if I
> click outside the field, the text shows as single line (cutting off the
> content that cannot fit in the field).
> 
> Is there anyway to fix this issue?
> 
> On Tue, Oct 14, 2014 at 7:55 PM, Rajeev Menon <ra...@gmail.com>
> wrote:
> 
>> Thx Mauran. I didn't know that approach will work. I will try it.
>> 
>> 
>> On Tuesday, October 14, 2014, Maruan Sahyoun <sa...@fileaffairs.de>
>> wrote:
>> 
>>> Hi,
>>> 
>>> just pass it with the line breaks within the string and make sure the
>>> multiline property for the field is set.
>>> 
>>> Maruan
>>> 
>>> Am 14.10.2014 um 21:07 schrieb Rajeev Menon <ra...@gmail.com>:
>>> 
>>>> Hello,
>>>> 
>>>> I am using PDFBox to populate data on a PDF form (AcroForm). Here is a
>>>> sample code that I am using to fill the data on to the PDF.
>>>> 
>>>>   public void fillPDF(HashMap<String, String> mpData) {
>>>>       try {
>>>>           PDDocumentCatalog docCatalog = pdfDoc.getDocumentCatalog();
>>>>           PDAcroForm acroForm = docCatalog.getAcroForm();
>>>> 
>>>>           Iterator<Entry<String, String>> itrData =
>>>> mpData.entrySet().iterator();
>>>>           while (itrData.hasNext()) {
>>>>               Entry<String, String> entryData = itrData.next();
>>>>               PDField fldPD = acroForm.getField(entryData.getKey());
>>>>               if (fldPD!=null) {
>>>>                   fldPD.setValue(entryData.getValue());
>>>>               }
>>>>           }
>>>>       } catch (Exception e) {
>>>>           e.printStackTrace();
>>>>       }
>>>> 
>>>>   }
>>>> 
>>>> 
>>>> If one of the strings is "First line \n Second line \n Third line", how
>>> do
>>>> I populate this text to the PDF so that each piece of text will be on a
>>> new
>>>> line in the field. Please advise.
>>>> 
>>>> Thanks.
>>>> Reevs.
>>> 
>>> 


Re: Multi-line text or wrap to next line Issue

Posted by Rajeev Menon <ra...@gmail.com>.
I tried the string with the "\n" and it successfully inserted new lines in
the multi-line field in the PDF Form.

However, the text in a line that is too long doesn't automatically wrap to
next line. When I click in the field, the text wraps to next line and if I
click outside the field, the text shows as single line (cutting off the
content that cannot fit in the field).

Is there anyway to fix this issue?

On Tue, Oct 14, 2014 at 7:55 PM, Rajeev Menon <ra...@gmail.com>
wrote:

> Thx Mauran. I didn't know that approach will work. I will try it.
>
>
> On Tuesday, October 14, 2014, Maruan Sahyoun <sa...@fileaffairs.de>
> wrote:
>
>> Hi,
>>
>> just pass it with the line breaks within the string and make sure the
>> multiline property for the field is set.
>>
>> Maruan
>>
>> Am 14.10.2014 um 21:07 schrieb Rajeev Menon <ra...@gmail.com>:
>>
>> > Hello,
>> >
>> > I am using PDFBox to populate data on a PDF form (AcroForm). Here is a
>> > sample code that I am using to fill the data on to the PDF.
>> >
>> >    public void fillPDF(HashMap<String, String> mpData) {
>> >        try {
>> >            PDDocumentCatalog docCatalog = pdfDoc.getDocumentCatalog();
>> >            PDAcroForm acroForm = docCatalog.getAcroForm();
>> >
>> >            Iterator<Entry<String, String>> itrData =
>> > mpData.entrySet().iterator();
>> >            while (itrData.hasNext()) {
>> >                Entry<String, String> entryData = itrData.next();
>> >                PDField fldPD = acroForm.getField(entryData.getKey());
>> >                if (fldPD!=null) {
>> >                    fldPD.setValue(entryData.getValue());
>> >                }
>> >            }
>> >        } catch (Exception e) {
>> >            e.printStackTrace();
>> >        }
>> >
>> >    }
>> >
>> >
>> > If one of the strings is "First line \n Second line \n Third line", how
>> do
>> > I populate this text to the PDF so that each piece of text will be on a
>> new
>> > line in the field. Please advise.
>> >
>> > Thanks.
>> > Reevs.
>>
>>

Re: Multi-line text or wrap to next line Issue

Posted by Rajeev Menon <ra...@gmail.com>.
Thx Mauran. I didn't know that approach will work. I will try it.

On Tuesday, October 14, 2014, Maruan Sahyoun <sa...@fileaffairs.de> wrote:

> Hi,
>
> just pass it with the line breaks within the string and make sure the
> multiline property for the field is set.
>
> Maruan
>
> Am 14.10.2014 um 21:07 schrieb Rajeev Menon <rajeevrmenong@gmail.com
> <javascript:;>>:
>
> > Hello,
> >
> > I am using PDFBox to populate data on a PDF form (AcroForm). Here is a
> > sample code that I am using to fill the data on to the PDF.
> >
> >    public void fillPDF(HashMap<String, String> mpData) {
> >        try {
> >            PDDocumentCatalog docCatalog = pdfDoc.getDocumentCatalog();
> >            PDAcroForm acroForm = docCatalog.getAcroForm();
> >
> >            Iterator<Entry<String, String>> itrData =
> > mpData.entrySet().iterator();
> >            while (itrData.hasNext()) {
> >                Entry<String, String> entryData = itrData.next();
> >                PDField fldPD = acroForm.getField(entryData.getKey());
> >                if (fldPD!=null) {
> >                    fldPD.setValue(entryData.getValue());
> >                }
> >            }
> >        } catch (Exception e) {
> >            e.printStackTrace();
> >        }
> >
> >    }
> >
> >
> > If one of the strings is "First line \n Second line \n Third line", how
> do
> > I populate this text to the PDF so that each piece of text will be on a
> new
> > line in the field. Please advise.
> >
> > Thanks.
> > Reevs.
>
>

Re: Multi-line text or wrap to next line Issue

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,

just pass it with the line breaks within the string and make sure the multiline property for the field is set.

Maruan

Am 14.10.2014 um 21:07 schrieb Rajeev Menon <ra...@gmail.com>:

> Hello,
> 
> I am using PDFBox to populate data on a PDF form (AcroForm). Here is a
> sample code that I am using to fill the data on to the PDF.
> 
>    public void fillPDF(HashMap<String, String> mpData) {
>        try {
>            PDDocumentCatalog docCatalog = pdfDoc.getDocumentCatalog();
>            PDAcroForm acroForm = docCatalog.getAcroForm();
> 
>            Iterator<Entry<String, String>> itrData =
> mpData.entrySet().iterator();
>            while (itrData.hasNext()) {
>                Entry<String, String> entryData = itrData.next();
>                PDField fldPD = acroForm.getField(entryData.getKey());
>                if (fldPD!=null) {
>                    fldPD.setValue(entryData.getValue());
>                }
>            }
>        } catch (Exception e) {
>            e.printStackTrace();
>        }
> 
>    }
> 
> 
> If one of the strings is "First line \n Second line \n Third line", how do
> I populate this text to the PDF so that each piece of text will be on a new
> line in the field. Please advise.
> 
> Thanks.
> Reevs.