public class PaperSize
Example: Example:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getPageSetup().setPaperSize(PaperSize.LEGAL);
builder.getPageSetup().setOrientation(Orientation.LANDSCAPE);
builder.getPageSetup().setTopMargin(ConvertUtil.inchToPoint(1.0));
builder.getPageSetup().setBottomMargin(ConvertUtil.inchToPoint(1.0));
builder.getPageSetup().setLeftMargin(ConvertUtil.inchToPoint(1.5));
builder.getPageSetup().setRightMargin(ConvertUtil.inchToPoint(1.5));
builder.getPageSetup().setHeaderDistance(ConvertUtil.inchToPoint(0.2));
builder.getPageSetup().setFooterDistance(ConvertUtil.inchToPoint(0.2));
builder.writeln("Hello world.");
doc.save(getArtifactsDir() + "PageSetup.PageMargins.docx");
Document doc = new Document();
// A newly created blank document still comes one section, one body and one paragraph
// Calling this method will remove all those nodes to completely empty the document
doc.removeAllChildren();
// This document now has no composite nodes that content can be added to
// If we wish to edit it, we will need to repopulate its node collection,
// which we will start to do with by creating a new Section node
Section section = new Section(doc);
// Append the section to the document
doc.appendChild(section);
// Lets set some properties for the section
section.getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
section.getPageSetup().setPaperSize(PaperSize.LETTER);
// A section needs a body, which will contain all other nodes that can be edited
Body body = new Body(doc);
section.appendChild(body);
// The body needs to have at least one paragraph
// Note that the paragraph has not yet been added to the document, but we have to specify the parent document
// The parent document is needed so the paragraph can correctly work
// with styles and other document-wide information
Paragraph para = new Paragraph(doc);
body.appendChild(para);
// We can set some formatting for the paragraph
para.getParagraphFormat().setStyleName("Heading 1");
para.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
// Now we can begin adding content to the document
Run run = new Run(doc);
run.setText("Hello World!");
run.getFont().setColor(Color.RED);
para.appendChild(run);
Assert.assertEquals("Hello World!" + ControlChar.SECTION_BREAK_CHAR, doc.getText());
doc.save(getArtifactsDir() + "Section.CreateFromScratch.docx");
Field Summary | ||
---|---|---|
static final int | A3 | |
297 x 420 mm.
|
||
static final int | A4 | |
210 x 297 mm.
|
||
static final int | A5 | |
148 x 210 mm.
|
||
static final int | B4 | |
250 x 353 mm.
|
||
static final int | B5 | |
176 x 250 mm.
|
||
static final int | EXECUTIVE | |
7.25 x 10.5 inches.
|
||
static final int | FOLIO | |
8.5 x 13 inches.
|
||
static final int | LEDGER | |
17 x 11 inches.
|
||
static final int | LEGAL | |
8.5 x 14 inches.
|
||
static final int | LETTER | |
8.5 x 11 inches.
|
||
static final int | ENVELOPE_DL | |
110 x 220 mm.
|
||
static final int | QUARTO | |
8.47 x 10.83 inches.
|
||
static final int | STATEMENT | |
8.5 x 5.5 inches.
|
||
static final int | TABLOID | |
11 x 17 inches.
|
||
static final int | PAPER_10_X_14 | |
10 x 14 inches.
|
||
static final int | PAPER_11_X_17 | |
11 x 17 inches.
|
||
static final int | CUSTOM | |
Custom paper size.
|
public static final int A3
public static final int A4
public static final int A5
public static final int B4
public static final int B5
public static final int EXECUTIVE
public static final int FOLIO
public static final int LEDGER
public static final int LEGAL
public static final int LETTER
public static final int ENVELOPE_DL
public static final int QUARTO
public static final int STATEMENT
public static final int TABLOID
public static final int PAPER_10_X_14
public static final int PAPER_11_X_17
public static final int CUSTOM