You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Adam Steen <ad...@rmt.com.au> on 2016/01/20 01:26:50 UTC

How do you create a Radio Button Group with PDFBox 2.0?

Hi



I want to create a Radio Button group using PDFBox 2.0, I am able to create 3 Radio Buttons, but I can't figure out how to group them (PDFBox 1.8, used PDRadioCollection<https://pdfbox.apache.org/docs/1.8.10/javadocs/org/apache/pdfbox/pdmodel/interactive/form/PDRadioCollection.html>, but 2.0 doesn't.).



How do you create a Radio Button Group with PDFBox 2.0?

Here is my current code:
        PDDocument document = new PDDocument();
        PDPage page = new PDPage(PDRectangle.A4);
        document.addPage(page);

        PDAcroForm acroForm = new PDAcroForm(document);
        acroForm.setNeedAppearances(true);
        document.getDocumentCatalog().setAcroForm(acroForm);

        PDResources res = new PDResources();
        COSName fontName = res.add(PDTrueTypeFont.load(document, new FileInputStream("C:/Windows/Fonts/arial.ttf"), StandardEncoding.INSTANCE));
        acroForm.setDefaultResources(res);
        acroForm.setDefaultAppearance('/' + fontName.getName() + " 10 Tf 0 g");

        PDPageContentStream contents = new PDPageContentStream(document, page);

        List<String> options = Arrays.asList("a", "b", "c");
        for (int i = 0; i < options.size(); i++) {
            PDRadioButton button = new PDRadioButton(acroForm);
            button.setPartialName("RadioButton" + options.get(i));

            PDAppearanceCharacteristicsDictionary fieldAppearance = new PDAppearanceCharacteristicsDictionary(new COSDictionary());
            fieldAppearance.setBorderColour(new PDColor(new float[]{0, 0, 0}, PDDeviceRGB.INSTANCE));

            PDAnnotationWidget widget = button.getWidgets().get(0);
            widget.setRectangle(new PDRectangle(30, 800 - i * (21), 16, 16));
            widget.setAppearanceCharacteristics(fieldAppearance);

            acroForm.getFields().add(button);
            page.getAnnotations().add(widget);
        }
        contents.close();
        document.save(new FileOutputStream("RadioButtonTest.pdf"));
        document.close();

Cheers
Adam

Re: How do you create a Radio Button Group with PDFBox 2.0?

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 22.01.2016 um 02:29 schrieb Adam Steen:
> I have a working solution to set default values and have acrobat render them. It was pure fluke that I got this result, but wanted to post it so other will know and to close out the solution.

Thanks, this works nicely. You don't need the font and the appearance 
streams contents (but it must exist) anymore, so the shorter code could 
look like this. I've also changed the background. I'll keep that code 
for the next person who asks :-)

     public static void main(String[] args) throws IOException
     {
         String fileName = "C:\\Users\\Tilman 
Hausherr\\Documents\\Java\\PDFBoxPageImageExtraction/RadioButtonsAdam.pdf";
         String selectedValue = "a";
         String name = "Radio";

         PDDocument document = new PDDocument();
         PDPage page = new PDPage(PDRectangle.A4);
         document.addPage(page);

         PDAcroForm acroForm = new PDAcroForm(document);
         acroForm.setNeedAppearances(true);
         document.getDocumentCatalog().setAcroForm(acroForm);

         PDPageContentStream contents = new 
PDPageContentStream(document, page);

         List<String> options = Arrays.asList("a", "b", "c");
         PDRadioButton radioButton = new PDRadioButton(acroForm);
         radioButton.setPartialName("RadioButton");
         List<PDAnnotationWidget> widgets = new ArrayList<>();
         for (int i = 0; i < options.size(); i++)
         {
             PDRadioButton subRadioButton = new PDRadioButton(acroForm);
             subRadioButton.setPartialName(name);

             PDAnnotationWidget widget = subRadioButton.getWidgets().get(0);

             PDAppearanceCharacteristicsDictionary fieldAppearance = new 
PDAppearanceCharacteristicsDictionary(new COSDictionary());
             fieldAppearance.setBorderColour(new PDColor(new float[]{0, 
0, 0}, PDDeviceRGB.INSTANCE));
             fieldAppearance.setBackground(new PDColor(new float[]{1, 1, 
1}, PDDeviceRGB.INSTANCE));

             widget.setRectangle(new PDRectangle(30, 800 - i * (21), 16, 
16));
             widget.setAppearanceCharacteristics(fieldAppearance);
             widget.setPage(page);
             widget.getCOSObject().setItem(COSName.PARENT, radioButton);
             widget.setAnnotationFlags(4);

widget.setAppearanceState(options.get(i).equals(selectedValue) ? 
selectedValue : "Off");
             widget.setHighlightingMode("N");

             PDAppearanceDictionary ap = new PDAppearanceDictionary();

             COSDictionary aeDict = new COSDictionary();

             COSStream off = new COSStream();
             off.setItem(COSName.BBOX, new PDRectangle(0, 0, 16, 16));
             aeDict.setItem("Off", off);

             COSStream on = new COSStream();
             on.setItem(COSName.BBOX, new PDRectangle(0, 0, 16, 16));
             aeDict.setItem(options.get(i), on);

             PDAppearanceEntry ae = new PDAppearanceEntry(aeDict);
             ap.setNormalAppearance(ae);
             widget.setAppearance(ap);

             widgets.add(widget);
             page.getAnnotations().add(widget);
         }
         radioButton.setWidgets(widgets);
         System.out.println(radioButton.getOnValues());
         radioButton.setValue(selectedValue);
         acroForm.getFields().add(radioButton);

         System.out.println(radioButton.getValue());

         //acroForm.refreshAppearances(); // not implemented
         contents.close();
         document.save(new FileOutputStream(fileName));

         document.close();
     }

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


Re: How do you create a Radio Button Group with PDFBox 2.0?

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

> Am 22.01.2016 um 02:29 schrieb Adam Steen <ad...@rmt.com.au>:
> 
> HI Tilman
> 
> Thanks for your help, regarding "pdAcroForm.setNeedAppearances(true);", will pdfbox have a default appearance in the future, so need appearances will not be needed?

we will start working on that after 2.0 is out as we will also need that for PDF 2.0 support which mandates that the appearance stream is generated.

BR
Maruan

> 
> I have a working solution to set default values and have acrobat render them. It was pure fluke that I got this result, but wanted to post it so other will know and to close out the solution.
> 
> Code: 
> package pdfboxtesting;
> 
> import java.io.FileInputStream;
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.io.OutputStream;
> import java.util.ArrayList;
> import java.util.Arrays;
> import java.util.List;
> import org.apache.pdfbox.cos.COSDictionary;
> import org.apache.pdfbox.cos.COSName;
> import org.apache.pdfbox.cos.COSStream;
> import org.apache.pdfbox.pdmodel.PDDocument;
> import org.apache.pdfbox.pdmodel.PDPage;
> import org.apache.pdfbox.pdmodel.PDPageContentStream;
> import org.apache.pdfbox.pdmodel.PDResources;
> import org.apache.pdfbox.pdmodel.common.PDRectangle;
> import org.apache.pdfbox.pdmodel.font.PDFont;
> import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont;
> import org.apache.pdfbox.pdmodel.font.encoding.StandardEncoding;
> import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
> import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
> import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
> import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceCharacteristicsDictionary;
> import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
> import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceEntry;
> import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
> import org.apache.pdfbox.pdmodel.interactive.form.PDRadioButton;
> 
> public class RadioButtonTest
> {
>    private RadioButtonTest() {
>    }
> 
>    public static void main(String[] args) throws IOException
>    {
>        String fileName = "output/Test.pdf";
>        String selectedValue = "a";
>        String name = "Radio";
> 
>        PDDocument document = new PDDocument();
>        PDPage page = new PDPage(PDRectangle.A4);
>        document.addPage(page);
> 
>        PDAcroForm acroForm = new PDAcroForm(document);
>        acroForm.setNeedAppearances(true);
>        document.getDocumentCatalog().setAcroForm(acroForm);
> 
>        PDFont font = PDTrueTypeFont.load(document, new FileInputStream("C:/Windows/Fonts/arial.ttf"), StandardEncoding.INSTANCE);
> 
>        PDResources res = new PDResources();
>        COSName fontName = res.add(font);
>        acroForm.setDefaultResources(res);
>        acroForm.setDefaultAppearance('/' + fontName.getName() + " 0 Tf 0 g");
> 
>        PDPageContentStream contents = new PDPageContentStream(document, page);
> 
>        List<String> options = Arrays.asList("a", "b", "c");
>        PDRadioButton radioButton = new PDRadioButton(acroForm);
>        radioButton.setPartialName("RadioButton");
>        List<PDAnnotationWidget> widgets = new ArrayList<>();
>        for (int i = 0; i < options.size(); i++)
>        {
>            PDRadioButton subRadioButton = new PDRadioButton(acroForm);
>            subRadioButton.setPartialName(name);
> 
>            PDAnnotationWidget widget = subRadioButton.getWidgets().get(0);
> 
>            PDAppearanceCharacteristicsDictionary fieldAppearance = new PDAppearanceCharacteristicsDictionary(new COSDictionary());
>            fieldAppearance.setBorderColour(new PDColor(new float[]{0, 0, 0}, PDDeviceRGB.INSTANCE));
> 
>            widget.setRectangle(new PDRectangle(30, 800 - i * (21), 16, 16));
>            widget.setAppearanceCharacteristics(fieldAppearance);
>            widget.setPage(page);
>            widget.getCOSObject().setItem(COSName.PARENT, radioButton);
>            widget.setAnnotationFlags(4);
> 
>            widget.setAppearanceState(options.get(i).equals(selectedValue) ? selectedValue : "Off");
>            widget.setHighlightingMode("N");
> 
>            PDAppearanceDictionary ap = new PDAppearanceDictionary();
> 
>            COSDictionary aeDict = new COSDictionary();
> 
>            COSStream off = new COSStream();
>            off.setItem(COSName.BBOX, new PDRectangle(0, 0, 16, 16));
>            off.setItem(COSName.RESOURCES, res);
>            OutputStream osOff = off.createOutputStream();
>            osOff.write(("q 0 g /" + fontName.getName() + " 16 Tf BT (O) Tj ET Q").getBytes());
>            osOff.write(("").getBytes());
>            osOff.close();
>            aeDict.setItem("Off", off);
> 
>            COSStream on = new COSStream();
>            on.setItem(COSName.BBOX, new PDRectangle(0, 0, 16, 16));
>            on.setItem(COSName.RESOURCES, res);
>            OutputStream osOn = on.createOutputStream();
>            osOn.write(("q 0 g BT /" + fontName.getName() + " 16 Tf (X) Tj ET Q").getBytes());
>            osOn.write(("").getBytes());
>            osOn.close();
>            aeDict.setItem(options.get(i), on);
> 
>            PDAppearanceEntry ae = new PDAppearanceEntry(aeDict);
>            ap.setNormalAppearance(ae);
>            widget.setAppearance(ap);
> 
>            widgets.add(widget);
>            page.getAnnotations().add(widget);
>        }
>        radioButton.setWidgets(widgets);
>        System.out.println(radioButton.getOnValues());
>        radioButton.setValue(selectedValue);
>        acroForm.getFields().add(radioButton);
> 
>        System.out.println(radioButton.getValue());
> 
>        //acroForm.refreshAppearances(); // not implemented
>        contents.close();
>        document.save(new FileOutputStream(fileName));
> 
>        document.close();
>    }
> }
> 
> Adam
> 
> -----Original Message-----
> From: Tilman Hausherr [mailto:THausherr@t-online.de] 
> Sent: Thursday, 21 January 2016 4:55 PM
> To: users@pdfbox.apache.org
> Subject: Re: How do you create a Radio Button Group with PDFBox 2.0?
> 
> Am 21.01.2016 um 09:41 schrieb Adam Steen:
>> I am now able to create a radio button group with "pdAcroForm.setNeedAppearances(true);", acrobat rendering things nicely for me.
>> 
>> I am also able to create a group of checkboxes with default values also with "pdAcroForm.setNeedAppearances(true);", again acrobat rendering things nicely for me.
>> 
>> My last hurdle is to create a radio button group with "pdAcroForm.setNeedAppearances(true);" and have a default value (or value) be displayed.
>> 
>> Using your code provided earlier Tilman, I was able to set a value or a default value, but acrobat just does not want to render it.
>> 
>> Is " pdAcroForm.setNeedAppearances(true);" a hack? Should I be rendering everything myself?
> 
> Yes, it is a bit of a hack. Good applications should create their own appearance streams. In PDF 2.0 it will be mandatory.
> 
>> 
>> Adam
>> 
>> -----Original Message-----
>> From: Tilman Hausherr [mailto:THausherr@t-online.de]
>> Sent: Thursday, 21 January 2016 4:29 PM
>> To: users@pdfbox.apache.org
>> Subject: Re: How do you create a Radio Button Group with PDFBox 2.0?
>> 
>> Am 21.01.2016 um 06:51 schrieb Adam Steen:
>>> It seems without building an appearance I am unable to set a default value?
>> Indeed. I've been there too and looked through the code.
>> 
>> Tilman
>> 
>>> Does anyone have any ideas?
>>> 
>>> Adam
>>> 
>>> 
>>> -----Original Message-----
>>> From: Adam Steen [mailto:adams@rmt.com.au]
>>> Sent: Thursday, 21 January 2016 8:26 AM
>>> To: users@pdfbox.apache.org
>>> Subject: RE: How do you create a Radio Button Group with PDFBox 2.0?
>>> 
>>> Hi
>>> 
>>> I did manage to get a Radio Group functioning, I have posted the code 
>>> to my question on stack overflow -> 
>>> http://stackoverflow.com/a/34895158/415681
>>> 
>>> The next problem will be getting a default value set.
>>> 
>>> Adam
>>> 
>>> -----Original Message-----
>>> From: Tilman Hausherr [mailto:THausherr@t-online.de]
>>> Sent: Wednesday, 20 January 2016 5:47 PM
>>> To: users@pdfbox.apache.org
>>> Subject: Re: How do you create a Radio Button Group with PDFBox 2.0?
>>> 
>>> Here's the code I did yesterday:
>>> http://justpaste.it/CreateRadioButtons
>>> 
>>> The problem is that Adobe does things on its own even if the appearance streams are set. This seems to be related to the appearance characteristics (/MK). I haven't been able to teach it to "do nothing", or "do it all" when I do nothing (having empty streams).
>>> 
>>> Tilman
>>> 
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


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


RE: How do you create a Radio Button Group with PDFBox 2.0?

Posted by Adam Steen <ad...@rmt.com.au>.
HI Tilman

Thanks for your help, regarding "pdAcroForm.setNeedAppearances(true);", will pdfbox have a default appearance in the future, so need appearances will not be needed?

I have a working solution to set default values and have acrobat render them. It was pure fluke that I got this result, but wanted to post it so other will know and to close out the solution.

Code: 
package pdfboxtesting;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSStream;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.PDResources;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont;
import org.apache.pdfbox.pdmodel.font.encoding.StandardEncoding;
import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceCharacteristicsDictionary;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceEntry;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
import org.apache.pdfbox.pdmodel.interactive.form.PDRadioButton;

public class RadioButtonTest
{
    private RadioButtonTest() {
    }

    public static void main(String[] args) throws IOException
    {
        String fileName = "output/Test.pdf";
        String selectedValue = "a";
        String name = "Radio";

        PDDocument document = new PDDocument();
        PDPage page = new PDPage(PDRectangle.A4);
        document.addPage(page);

        PDAcroForm acroForm = new PDAcroForm(document);
        acroForm.setNeedAppearances(true);
        document.getDocumentCatalog().setAcroForm(acroForm);

        PDFont font = PDTrueTypeFont.load(document, new FileInputStream("C:/Windows/Fonts/arial.ttf"), StandardEncoding.INSTANCE);

        PDResources res = new PDResources();
        COSName fontName = res.add(font);
        acroForm.setDefaultResources(res);
        acroForm.setDefaultAppearance('/' + fontName.getName() + " 0 Tf 0 g");

        PDPageContentStream contents = new PDPageContentStream(document, page);

        List<String> options = Arrays.asList("a", "b", "c");
        PDRadioButton radioButton = new PDRadioButton(acroForm);
        radioButton.setPartialName("RadioButton");
        List<PDAnnotationWidget> widgets = new ArrayList<>();
        for (int i = 0; i < options.size(); i++)
        {
            PDRadioButton subRadioButton = new PDRadioButton(acroForm);
            subRadioButton.setPartialName(name);

            PDAnnotationWidget widget = subRadioButton.getWidgets().get(0);

            PDAppearanceCharacteristicsDictionary fieldAppearance = new PDAppearanceCharacteristicsDictionary(new COSDictionary());
            fieldAppearance.setBorderColour(new PDColor(new float[]{0, 0, 0}, PDDeviceRGB.INSTANCE));

            widget.setRectangle(new PDRectangle(30, 800 - i * (21), 16, 16));
            widget.setAppearanceCharacteristics(fieldAppearance);
            widget.setPage(page);
            widget.getCOSObject().setItem(COSName.PARENT, radioButton);
            widget.setAnnotationFlags(4);

            widget.setAppearanceState(options.get(i).equals(selectedValue) ? selectedValue : "Off");
            widget.setHighlightingMode("N");

            PDAppearanceDictionary ap = new PDAppearanceDictionary();

            COSDictionary aeDict = new COSDictionary();

            COSStream off = new COSStream();
            off.setItem(COSName.BBOX, new PDRectangle(0, 0, 16, 16));
            off.setItem(COSName.RESOURCES, res);
            OutputStream osOff = off.createOutputStream();
            osOff.write(("q 0 g /" + fontName.getName() + " 16 Tf BT (O) Tj ET Q").getBytes());
            osOff.write(("").getBytes());
            osOff.close();
            aeDict.setItem("Off", off);

            COSStream on = new COSStream();
            on.setItem(COSName.BBOX, new PDRectangle(0, 0, 16, 16));
            on.setItem(COSName.RESOURCES, res);
            OutputStream osOn = on.createOutputStream();
            osOn.write(("q 0 g BT /" + fontName.getName() + " 16 Tf (X) Tj ET Q").getBytes());
            osOn.write(("").getBytes());
            osOn.close();
            aeDict.setItem(options.get(i), on);

            PDAppearanceEntry ae = new PDAppearanceEntry(aeDict);
            ap.setNormalAppearance(ae);
            widget.setAppearance(ap);

            widgets.add(widget);
            page.getAnnotations().add(widget);
        }
        radioButton.setWidgets(widgets);
        System.out.println(radioButton.getOnValues());
        radioButton.setValue(selectedValue);
        acroForm.getFields().add(radioButton);

        System.out.println(radioButton.getValue());

        //acroForm.refreshAppearances(); // not implemented
        contents.close();
        document.save(new FileOutputStream(fileName));

        document.close();
    }
}

Adam

-----Original Message-----
From: Tilman Hausherr [mailto:THausherr@t-online.de] 
Sent: Thursday, 21 January 2016 4:55 PM
To: users@pdfbox.apache.org
Subject: Re: How do you create a Radio Button Group with PDFBox 2.0?

Am 21.01.2016 um 09:41 schrieb Adam Steen:
> I am now able to create a radio button group with "pdAcroForm.setNeedAppearances(true);", acrobat rendering things nicely for me.
>
> I am also able to create a group of checkboxes with default values also with "pdAcroForm.setNeedAppearances(true);", again acrobat rendering things nicely for me.
>
> My last hurdle is to create a radio button group with "pdAcroForm.setNeedAppearances(true);" and have a default value (or value) be displayed.
>
> Using your code provided earlier Tilman, I was able to set a value or a default value, but acrobat just does not want to render it.
>
> Is " pdAcroForm.setNeedAppearances(true);" a hack? Should I be rendering everything myself?

Yes, it is a bit of a hack. Good applications should create their own appearance streams. In PDF 2.0 it will be mandatory.

>
> Adam
>
> -----Original Message-----
> From: Tilman Hausherr [mailto:THausherr@t-online.de]
> Sent: Thursday, 21 January 2016 4:29 PM
> To: users@pdfbox.apache.org
> Subject: Re: How do you create a Radio Button Group with PDFBox 2.0?
>
> Am 21.01.2016 um 06:51 schrieb Adam Steen:
>> It seems without building an appearance I am unable to set a default value?
> Indeed. I've been there too and looked through the code.
>
> Tilman
>
>> Does anyone have any ideas?
>>
>> Adam
>>
>>
>> -----Original Message-----
>> From: Adam Steen [mailto:adams@rmt.com.au]
>> Sent: Thursday, 21 January 2016 8:26 AM
>> To: users@pdfbox.apache.org
>> Subject: RE: How do you create a Radio Button Group with PDFBox 2.0?
>>
>> Hi
>>
>> I did manage to get a Radio Group functioning, I have posted the code 
>> to my question on stack overflow -> 
>> http://stackoverflow.com/a/34895158/415681
>>
>> The next problem will be getting a default value set.
>>
>> Adam
>>
>> -----Original Message-----
>> From: Tilman Hausherr [mailto:THausherr@t-online.de]
>> Sent: Wednesday, 20 January 2016 5:47 PM
>> To: users@pdfbox.apache.org
>> Subject: Re: How do you create a Radio Button Group with PDFBox 2.0?
>>
>> Here's the code I did yesterday:
>> http://justpaste.it/CreateRadioButtons
>>
>> The problem is that Adobe does things on its own even if the appearance streams are set. This seems to be related to the appearance characteristics (/MK). I haven't been able to teach it to "do nothing", or "do it all" when I do nothing (having empty streams).
>>
>> Tilman
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


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


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


Re: How do you create a Radio Button Group with PDFBox 2.0?

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 21.01.2016 um 09:41 schrieb Adam Steen:
> I am now able to create a radio button group with "pdAcroForm.setNeedAppearances(true);", acrobat rendering things nicely for me.
>
> I am also able to create a group of checkboxes with default values also with "pdAcroForm.setNeedAppearances(true);", again acrobat rendering things nicely for me.
>
> My last hurdle is to create a radio button group with "pdAcroForm.setNeedAppearances(true);" and have a default value (or value) be displayed.
>
> Using your code provided earlier Tilman, I was able to set a value or a default value, but acrobat just does not want to render it.
>
> Is " pdAcroForm.setNeedAppearances(true);" a hack? Should I be rendering everything myself?

Yes, it is a bit of a hack. Good applications should create their own 
appearance streams. In PDF 2.0 it will be mandatory.

>
> Adam
>
> -----Original Message-----
> From: Tilman Hausherr [mailto:THausherr@t-online.de]
> Sent: Thursday, 21 January 2016 4:29 PM
> To: users@pdfbox.apache.org
> Subject: Re: How do you create a Radio Button Group with PDFBox 2.0?
>
> Am 21.01.2016 um 06:51 schrieb Adam Steen:
>> It seems without building an appearance I am unable to set a default value?
> Indeed. I've been there too and looked through the code.
>
> Tilman
>
>> Does anyone have any ideas?
>>
>> Adam
>>
>>
>> -----Original Message-----
>> From: Adam Steen [mailto:adams@rmt.com.au]
>> Sent: Thursday, 21 January 2016 8:26 AM
>> To: users@pdfbox.apache.org
>> Subject: RE: How do you create a Radio Button Group with PDFBox 2.0?
>>
>> Hi
>>
>> I did manage to get a Radio Group functioning, I have posted the code to my question on stack overflow -> http://stackoverflow.com/a/34895158/415681
>>
>> The next problem will be getting a default value set.
>>
>> Adam
>>
>> -----Original Message-----
>> From: Tilman Hausherr [mailto:THausherr@t-online.de]
>> Sent: Wednesday, 20 January 2016 5:47 PM
>> To: users@pdfbox.apache.org
>> Subject: Re: How do you create a Radio Button Group with PDFBox 2.0?
>>
>> Here's the code I did yesterday:
>> http://justpaste.it/CreateRadioButtons
>>
>> The problem is that Adobe does things on its own even if the appearance streams are set. This seems to be related to the appearance characteristics (/MK). I haven't been able to teach it to "do nothing", or "do it all" when I do nothing (having empty streams).
>>
>> Tilman
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


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


RE: How do you create a Radio Button Group with PDFBox 2.0?

Posted by Adam Steen <ad...@rmt.com.au>.
I am now able to create a radio button group with "pdAcroForm.setNeedAppearances(true);", acrobat rendering things nicely for me.

I am also able to create a group of checkboxes with default values also with "pdAcroForm.setNeedAppearances(true);", again acrobat rendering things nicely for me.

My last hurdle is to create a radio button group with "pdAcroForm.setNeedAppearances(true);" and have a default value (or value) be displayed.

Using your code provided earlier Tilman, I was able to set a value or a default value, but acrobat just does not want to render it.

Is " pdAcroForm.setNeedAppearances(true);" a hack? Should I be rendering everything myself?

Adam

-----Original Message-----
From: Tilman Hausherr [mailto:THausherr@t-online.de] 
Sent: Thursday, 21 January 2016 4:29 PM
To: users@pdfbox.apache.org
Subject: Re: How do you create a Radio Button Group with PDFBox 2.0?

Am 21.01.2016 um 06:51 schrieb Adam Steen:
> It seems without building an appearance I am unable to set a default value?

Indeed. I've been there too and looked through the code.

Tilman

>
> Does anyone have any ideas?
>
> Adam
>
>
> -----Original Message-----
> From: Adam Steen [mailto:adams@rmt.com.au]
> Sent: Thursday, 21 January 2016 8:26 AM
> To: users@pdfbox.apache.org
> Subject: RE: How do you create a Radio Button Group with PDFBox 2.0?
>
> Hi
>
> I did manage to get a Radio Group functioning, I have posted the code to my question on stack overflow -> http://stackoverflow.com/a/34895158/415681
>
> The next problem will be getting a default value set.
>
> Adam
>
> -----Original Message-----
> From: Tilman Hausherr [mailto:THausherr@t-online.de]
> Sent: Wednesday, 20 January 2016 5:47 PM
> To: users@pdfbox.apache.org
> Subject: Re: How do you create a Radio Button Group with PDFBox 2.0?
>
> Here's the code I did yesterday:
> http://justpaste.it/CreateRadioButtons
>
> The problem is that Adobe does things on its own even if the appearance streams are set. This seems to be related to the appearance characteristics (/MK). I haven't been able to teach it to "do nothing", or "do it all" when I do nothing (having empty streams).
>
> Tilman
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


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


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


Re: How do you create a Radio Button Group with PDFBox 2.0?

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 21.01.2016 um 06:51 schrieb Adam Steen:
> It seems without building an appearance I am unable to set a default value?

Indeed. I've been there too and looked through the code.

Tilman

>
> Does anyone have any ideas?
>
> Adam
>
>
> -----Original Message-----
> From: Adam Steen [mailto:adams@rmt.com.au]
> Sent: Thursday, 21 January 2016 8:26 AM
> To: users@pdfbox.apache.org
> Subject: RE: How do you create a Radio Button Group with PDFBox 2.0?
>
> Hi
>
> I did manage to get a Radio Group functioning, I have posted the code to my question on stack overflow -> http://stackoverflow.com/a/34895158/415681
>
> The next problem will be getting a default value set.
>
> Adam
>
> -----Original Message-----
> From: Tilman Hausherr [mailto:THausherr@t-online.de]
> Sent: Wednesday, 20 January 2016 5:47 PM
> To: users@pdfbox.apache.org
> Subject: Re: How do you create a Radio Button Group with PDFBox 2.0?
>
> Here's the code I did yesterday:
> http://justpaste.it/CreateRadioButtons
>
> The problem is that Adobe does things on its own even if the appearance streams are set. This seems to be related to the appearance characteristics (/MK). I haven't been able to teach it to "do nothing", or "do it all" when I do nothing (having empty streams).
>
> Tilman
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


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


RE: How do you create a Radio Button Group with PDFBox 2.0?

Posted by Adam Steen <ad...@rmt.com.au>.
It seems without building an appearance I am unable to set a default value?

Does anyone have any ideas?

Adam


-----Original Message-----
From: Adam Steen [mailto:adams@rmt.com.au] 
Sent: Thursday, 21 January 2016 8:26 AM
To: users@pdfbox.apache.org
Subject: RE: How do you create a Radio Button Group with PDFBox 2.0?

Hi

I did manage to get a Radio Group functioning, I have posted the code to my question on stack overflow -> http://stackoverflow.com/a/34895158/415681

The next problem will be getting a default value set.

Adam

-----Original Message-----
From: Tilman Hausherr [mailto:THausherr@t-online.de] 
Sent: Wednesday, 20 January 2016 5:47 PM
To: users@pdfbox.apache.org
Subject: Re: How do you create a Radio Button Group with PDFBox 2.0?

Here's the code I did yesterday:
http://justpaste.it/CreateRadioButtons

The problem is that Adobe does things on its own even if the appearance streams are set. This seems to be related to the appearance characteristics (/MK). I haven't been able to teach it to "do nothing", or "do it all" when I do nothing (having empty streams).

Tilman



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


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


RE: How do you create a Radio Button Group with PDFBox 2.0?

Posted by Adam Steen <ad...@rmt.com.au>.
Hi

I did manage to get a Radio Group functioning, I have posted the code to my question on stack overflow -> http://stackoverflow.com/a/34895158/415681

The next problem will be getting a default value set.

Adam

-----Original Message-----
From: Tilman Hausherr [mailto:THausherr@t-online.de] 
Sent: Wednesday, 20 January 2016 5:47 PM
To: users@pdfbox.apache.org
Subject: Re: How do you create a Radio Button Group with PDFBox 2.0?

Here's the code I did yesterday:
http://justpaste.it/CreateRadioButtons

The problem is that Adobe does things on its own even if the appearance streams are set. This seems to be related to the appearance characteristics (/MK). I haven't been able to teach it to "do nothing", or "do it all" when I do nothing (having empty streams).

Tilman



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


Re: How do you create a Radio Button Group with PDFBox 2.0?

Posted by Tilman Hausherr <TH...@t-online.de>.
Here's the code I did yesterday:
http://justpaste.it/CreateRadioButtons

The problem is that Adobe does things on its own even if the appearance 
streams are set. This seems to be related to the appearance 
characteristics (/MK). I haven't been able to teach it to "do nothing", 
or "do it all" when I do nothing (having empty streams).

Tilman



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