Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWord
>
Tutorial
> Page settings
The following example shows you how to set page size and margins.
import com.independentsoft.office.word.Paragraph; import com.independentsoft.office.word.Run; import com.independentsoft.office.word.WordDocument; import com.independentsoft.office.word.sections.PageMargins; import com.independentsoft.office.word.sections.PageSize; import com.independentsoft.office.word.sections.Section; public class Example { public static void main(String[] args) { try { WordDocument doc = new WordDocument(); PageMargins margins = new PageMargins(); margins.setBottom(1440); // 1 inch margins.setLeft(1440); // 1 inch margins.setRight(1440); // 1 inch margins.setTop(1440); // 1 inch margins.setFooter(720); // 1/2 inch margins.setHeader(720); // 1/2 inch Section section = new Section(); section.setPageSize(new PageSize(12240, 15840)); //8.5 x 11 in section.setPageMargins(margins); doc.getBody().setSection(section); Run run = new Run(); run.addText("Page size is 8.5 x 11 in (Letter)."); Paragraph paragraph = new Paragraph(); paragraph.add(run); doc.getBody().add(paragraph); doc.save("c:\\test\\output.docx", true); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*