We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

ListBoxField issue

Hi,


I have a question.
I wont to add ListBoxField to pdf page.
I try it like this code.

Document document = new Document();
Page page = document.getPages().add();

TextFragment textFragment = new TextFragment( “Problem with ListBoxField” );

page.getParagraphs().add( textFragment );

// Options in this list are not displayed!
Rectangle rec1 = new Rectangle( 0, 0, 0, 0 );

ListBoxField listBoxField1 = new ListBoxField(page, rec1);
listBoxField1.setWidth(200);
listBoxField1.setHeight(500);
listBoxField1.setMultiSelect( true );

java.util.Arrays.asList(“First list”,“111”,“221”,“331”,“441”,“551”,“661”,“771”,“881”,“99”,“00”).stream().forEach(listBoxField1::addOption);
//page.getParagraphs().add(listBoxField1);
document.getForm().add(listBoxField1, page.getNumber());

try (OutputStream output = new FileOutputStream(“C:\1\ListBoxField_problem_demo.pdf”)) {
document.save(output);
}

question is - how i can put this field after TextFragment and define size.
like on my screenshot.

Thank you!
Aspose.pdf 17.2.0

Hi Aleksandr,


Thanks for contacting support.

Please use following code snippet, it will work as per your requirement

JAVA

Document document = new Document();

Page page = document.getPages().add();

TextFragment textFragment = new TextFragment( “Problem with ListBoxField” );
page.getParagraphs().add( textFragment );
// Options in this list are not displayed!
Rectangle rec1 = new Rectangle(90, 600, 300, 750 );

ListBoxField listBoxField1 = new ListBoxField(page, rec1);
listBoxField1.setWidth(200);
listBoxField1.setHeight(150);
listBoxField1.setMultiSelect(true);

java.util.Arrays.asList(“First list”,“111”,“221”,“331”,“441”,“551”,“661”,“771”,“881”,“99”,“00”).stream().forEach(listBoxField1::addOption);
//page.getParagraphs().add(listBoxField1);
document.getForm().add(listBoxField1, page.getNumber());
try (OutputStream output = new FileOutputStream(dataDir + “ListBoxField_problem_demo1.pdf”)) {
document.save(output);
}


If you still face any issue or need further assistance, please feel free to contact us.

Best Regards,

Hi,


Thank you, yes it’s works.

but what about <span style=“background-color: rgb(255, 255, 255); color: rgb(0, 128, 0); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>page.getParagraphs().add(listBoxField1);

it’s look better but list of items is empty. (i mean not need to calculate position)

Thank you!

Hi Aleksandr,


It is good to know that the suggested code is working for you. ListBoxField is a form field and we need to add it using document.getForm().add method.

If you need further assistance, please feel free to contact us.

We are sorry for the inconvenience.

Best Regards,

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco}
span.s1 {color: #7e504f}