You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Damaji Kalunge <da...@technogise.com> on 2022/08/25 06:47:18 UTC

Check the PDF box based on its value. by using COSDictionary

Hi Team,
I am ticking the checkbox using below code, *still the checkbox is not
checked in the filled PDF.*
  Could you please help out ? I have attached the sample image of PDF.
  try {

    PDDocument pDDocument = Loader.loadPDF(new
File("src/main/resources", "80.pdf"));
    if (pDDocument.isEncrypted()) {
        try {
            PDAcroForm pDAcroForm =
pDDocument.getDocumentCatalog().getAcroForm();


            COSDictionary cosDictionary3 =
pDAcroForm.getField("ap.sex").getCOSObject();
            cosDictionary3.setString(COSName.V, "male");

               OR

OSDictionary cosDictionary3 = pDAcroForm.getField("ap.sex").getCOSObject();
            cosDictionary3.setString(COSName.V, "Male");



FileOutputStream fileOutputStream = new FileOutputStream(new File(
"src/main/resources", "incrementalSave.pdf"));
Set<COSDictionary> set = new HashSet<>();
set.add(cosDictionary1);
set.add(cosDictionary2);
set.add(cosDictionary3);

pDDocument.saveIncremental(fileOutputStream, set);
pDDocument.close();

}

Re: Check the PDF box based on its value. by using COSDictionary

Posted by Damaji Kalunge <da...@technogise.com>.
Hi Team,

   Please find the link of filled PDF

 [
https://drive.google.com/file/d/1uzjN6fag5a-MT2kOO0ifAVM9ZsMLqUpo/view?usp=sharing
]


On Thu, Aug 25, 2022 at 12:43 PM Damaji Kalunge <da...@technogise.com>
wrote:

> Please find the attached filled PDF where checkbox is not checked.
>  below code snippet to check the checkbox.
>
> COSDictionary  cosDictionary3=pDAcroForm.getField("ap.sex").getCOSObject();
> cosDictionary3.setString(COSName.V ,"female");
>
>
> On Thu, Aug 25, 2022 at 12:31 PM Tilman Hausherr <TH...@t-online.de>
> wrote:
>
>> You may also have to add the appearance stream dictionaries to the
>> update list.
>>
>> field.getWidgets().get(0).getAppearanceCharacteristics().getCOSObject()
>>          field.getWidgets().get(0).getAppearance().getCOSObject()
>>
>> field.getWidgets().get(0).getAppearance().getNormalAppearance().getCOSObject()
>>
>> This may be too much or not be complete, the best would be to look at it
>> with PDFDebugger.
>>
>> Tilman
>>
>> Am 25.08.2022 um 08:55 schrieb Tilman Hausherr:
>> > Hi,
>> >
>> > Checkboxes are updated with check() and unCheck().
>> >
>> > If it still doesn't work, please upload the result file somewhere.
>> >
>> > Tilman
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>>

Re: Check the PDF box based on its value. by using COSDictionary

Posted by Damaji Kalunge <da...@technogise.com>.
HI team,
  This issue is blocking me.
Thanks
Damaji


On Thu, Aug 25, 2022 at 12:43 PM Damaji Kalunge <da...@technogise.com>
wrote:

> Please find the attached filled PDF where checkbox is not checked.
>  below code snippet to check the checkbox.
>
> COSDictionary  cosDictionary3=pDAcroForm.getField("ap.sex").getCOSObject();
> cosDictionary3.setString(COSName.V ,"female");
>
>
> On Thu, Aug 25, 2022 at 12:31 PM Tilman Hausherr <TH...@t-online.de>
> wrote:
>
>> You may also have to add the appearance stream dictionaries to the
>> update list.
>>
>> field.getWidgets().get(0).getAppearanceCharacteristics().getCOSObject()
>>          field.getWidgets().get(0).getAppearance().getCOSObject()
>>
>> field.getWidgets().get(0).getAppearance().getNormalAppearance().getCOSObject()
>>
>> This may be too much or not be complete, the best would be to look at it
>> with PDFDebugger.
>>
>> Tilman
>>
>> Am 25.08.2022 um 08:55 schrieb Tilman Hausherr:
>> > Hi,
>> >
>> > Checkboxes are updated with check() and unCheck().
>> >
>> > If it still doesn't work, please upload the result file somewhere.
>> >
>> > Tilman
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>>

Re: Check the PDF box based on its value. by using COSDictionary

Posted by Damaji Kalunge <da...@technogise.com>.
Please find the attached filled PDF where checkbox is not checked.
 below code snippet to check the checkbox.

COSDictionary  cosDictionary3=pDAcroForm.getField("ap.sex").getCOSObject();
cosDictionary3.setString(COSName.V ,"female");


On Thu, Aug 25, 2022 at 12:31 PM Tilman Hausherr <TH...@t-online.de>
wrote:

> You may also have to add the appearance stream dictionaries to the
> update list.
>
> field.getWidgets().get(0).getAppearanceCharacteristics().getCOSObject()
>          field.getWidgets().get(0).getAppearance().getCOSObject()
>
> field.getWidgets().get(0).getAppearance().getNormalAppearance().getCOSObject()
>
> This may be too much or not be complete, the best would be to look at it
> with PDFDebugger.
>
> Tilman
>
> Am 25.08.2022 um 08:55 schrieb Tilman Hausherr:
> > Hi,
> >
> > Checkboxes are updated with check() and unCheck().
> >
> > If it still doesn't work, please upload the result file somewhere.
> >
> > Tilman
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>

Re: Check the PDF box based on its value. by using COSDictionary

Posted by Tilman Hausherr <TH...@t-online.de>.
You may also have to add the appearance stream dictionaries to the 
update list.

field.getWidgets().get(0).getAppearanceCharacteristics().getCOSObject()
         field.getWidgets().get(0).getAppearance().getCOSObject()
field.getWidgets().get(0).getAppearance().getNormalAppearance().getCOSObject()

This may be too much or not be complete, the best would be to look at it 
with PDFDebugger.

Tilman

Am 25.08.2022 um 08:55 schrieb Tilman Hausherr:
> Hi,
>
> Checkboxes are updated with check() and unCheck().
>
> If it still doesn't work, please upload the result file somewhere.
>
> Tilman



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Check the PDF box based on its value. by using COSDictionary

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,

Checkboxes are updated with check() and unCheck().

If it still doesn't work, please upload the result file somewhere.

Tilman

Am 25.08.2022 um 08:47 schrieb Damaji Kalunge:
> Hi Team,
> I am ticking the checkbox using below code,/still the checkbox is not 
> checked in the filled PDF./
>   Could you please help out ? I have attached the sample image of PDF.
> try {
>      PDDocument pDDocument = Loader.loadPDF(new File("src/main/resources", "80.pdf")); if (pDDocument.isEncrypted()) {
>          try {
>              PDAcroForm pDAcroForm = pDDocument.getDocumentCatalog().getAcroForm(); COSDictionary cosDictionary3 = pDAcroForm.getField("ap.sex").getCOSObject(); cosDictionary3.setString(COSName.V, "male");
> OR
> OSDictionary cosDictionary3 = pDAcroForm.getField("ap.sex").getCOSObject(); cosDictionary3.setString(COSName.V, "Male");
>
> FileOutputStream fileOutputStream =new FileOutputStream(new File("src/main/resources", "incrementalSave.pdf")); Set<COSDictionary> set =new HashSet<>(); set.add(cosDictionary1); set.add(cosDictionary2); set.add(cosDictionary3); pDDocument.saveIncremental(fileOutputStream, set); pDDocument.close(); }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail:users-help@pdfbox.apache.org