Knowledgebase (2311)
Children categories
We can format Word document in a multi-column newsletter layout by adding columns. This article demonstrates how to add multiple columns to a Word document and specify the column width and the spacing between columns using Spire.Doc for Java.
import com.spire.doc.*;
import com.spire.doc.documents.*;
public class CreateMutiColumnWordDocument {
public static void main(String[] args){
//create a Document object
Document document = new Document();
//add a section
Section section = document.addSection();
//add 3 columns to the section
section.addColumn(100, 20);
section.addColumn(100, 20);
section.addColumn(100, 20);
//add a paragraph to the section
Paragraph paragraph = section.addParagraph();
//add a paragraph to the section
paragraph = section.addParagraph();
String text = "Spire.Doc for Java is a professional Java Word API that enables Java applications "
+"to create, convert, manipulate and print Word documents without using Microsoft Office.";
//add text to the paragraph
paragraph.appendText(text);
//add column break to the paragraph
paragraph.appendBreak(BreakType.Column_Break);
//add a paragraph to the section
paragraph = section.addParagraph();
//add text to the paragraph
paragraph.appendText(text);
//add column break to the paragraph
paragraph.appendBreak(BreakType.Column_Break);
//add a paragraph to the section
paragraph = section.addParagraph();
//add text to the paragraph
paragraph.appendText(text);
//add line between columns
section.getPageSetup().setColumnsLineBetween(true);
//save the resultant document
document.saveToFile("Muti-Column Document.docx", FileFormat.Docx_2013);
}
}
Output:

Published in
Page Setup
Tagged under
When we print a huge PDF document, print as a booklet is a great way to save the paper and make the pages tidy. This article we will introduce how to create a booklet from a PDF document in Java applications.
import com.spire.pdf.*;
public class PDFBooklet{
public static void main(String[] args) throws Exception {
String inputPath = "Sample.pdf";
PdfDocument doc = new PdfDocument();
doc.loadFromFile(inputPath);
PdfPageBase page = doc.getPages().get(0);
float width = (float) page.getSize().getWidth()*2;
float height = (float) page.getSize().getHeight();
doc.createBooklet(inputPath, width, height,true);
doc.saveToFile("Output/Booklet.pdf");
}
}
Effective screenshot after creating PDF booklet:

Published in
Print
Tagged under
This article demonstrates how to detect the required form fields in an existing PDF document using Spire.PDF for Java.
import com.spire.pdf.fields.PdfField;
import com.spire.pdf.widget.PdfFormWidget;
public class DetectRequiredFields {
public static void main(String[] args) {
//load a PDF file
PdfDocument doc = new PdfDocument();
doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\Fields.pdf");
//get form widget from the PDF document.
PdfFormWidget formWidget = (PdfFormWidget)doc.getForm();
//loop through the fields widget
for (int i = 0; i < formWidget.getFieldsWidget().getList().getCapacity(); i++) {
//get the specific field
PdfField field = (PdfField) formWidget.getFieldsWidget().getList().get_Item(i);
//get the field name
String fieldName = field.getName();
//determine if the field is required
boolean isRequired = field.getRequired();
if (isRequired){
//print the required field
System.out.println(fieldName + " is required");
}
}
}
}

Published in
Form Fields
Tagged under