Text Columns

Hi to everyone

I’m developing an android app, and I need to create word documents with two columns, somebody knows how can I do it?

Thank you!

Hi Alejandro,

Thanks for your inquiry. Please use following code example to create multiple columns of different widths in a section using DocumentBuilder. Hope this helps you.

Please let us know if you have any more queries.

DocumentBuilder builder = new DocumentBuilder();
TextColumnCollection columns = builder.getPageSetup().getTextColumns();
// Show vertical line between columns.
columns.setLineBetween(true);
// Indicate we want to create column with different widths.
columns.setEvenlySpaced(false);
// Create two columns, note they will be created with zero widths, need to set them.
columns.setCount(2);
// Set the first column to be narrow.
TextColumn c1 = columns.get(0);
c1.setWidth(100);
c1.setSpaceAfter(20);
// Set the second column to take the rest of the space available on the page.
TextColumn c2 = columns.get(1);
PageSetup ps = builder.getPageSetup();
double contentWidth = ps.getPageWidth() - ps.getLeftMargin() - ps.getRightMargin();
c2.setWidth(contentWidth - c1.getWidth() - c1.getSpaceAfter());
builder.writeln("Narrow column 1.");
builder.insertBreak(BreakType.COLUMN_BREAK);
builder.writeln("Wide column 2.");
builder.getDocument().save("PageSetup.ColumnsCustomWidth Out.docx");

Thank you the answer, it works!

Another question, how can I create a TextBox, I’m googling but nothing yet.

Hi Alejandro,

Thanks for your inquiry. Please use following code example to insert shape (text box) node in the document. Hope this helps you.

Please let us know if you have any more queries.

Document doc = new Document();
Shape shape = new Shape(doc, ShapeType.TEXT_BOX);
shape.setWidth(100);
shape.setHeight(100);
doc.getFirstSection().getBody().getFirstParagraph().appendChild(shape);
doc.save("Out.docx");