java.lang.Object
com.aspose.words.PageSetup
public class PageSetup
- extends java.lang.Object
Represents the page setup properties of a section.
PageSetup object contains all the page setup attributes of a section
(left margin, bottom margin, paper size, and so on) as properties.
Example:
Shows how to insert sections using DocumentBuilder, specify page setup for a section and reset page setup to defaults.
DocumentBuilder builder = new DocumentBuilder();
// Modify the first section in the document.
builder.getPageSetup().setOrientation(Orientation.LANDSCAPE);
builder.getPageSetup().setVerticalAlignment(PageVerticalAlignment.CENTER);
builder.writeln("Section 1, landscape oriented and text vertically centered.");
// Start a new section and reset its formatting to defaults.
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
builder.getPageSetup().clearFormatting();
builder.writeln("Section 2, back to default Letter paper size, portrait orientation and top alignment.");
builder.getDocument().save(getMyDir() + "PageSetup.ClearFormatting Out.doc");
Property Getters/Setters Detail |
getOddAndEvenPagesHeaderFooter/setOddAndEvenPagesHeaderFooter | |
public boolean getOddAndEvenPagesHeaderFooter() / public void setOddAndEvenPagesHeaderFooter(boolean value)
|
- True if the document has different headers and footers for odd-numbered and even-numbered pages.
Note, changing this property affects all sections in the document.
Example:
Creates headers and footers different for first, even and odd pages using DocumentBuilder.
DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.getPageSetup();
ps.setDifferentFirstPageHeaderFooter(true);
ps.setOddAndEvenPagesHeaderFooter(true);
ps.setFirstPageTray(PaperTray.ENVELOPE_FEED);
ps.setOtherPagesTray(PaperTray.FORM_SOURCE);
builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
builder.writeln("First page header.");
builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
builder.writeln("Even pages header.");
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.writeln("Odd pages header.");
// Move back to the main story of the first section.
builder.moveToSection(0);
builder.writeln("Text page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Text page 2.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Text page 3.");
builder.getDocument().save(getMyDir() + "PageSetup.DifferentHeaders Out.doc");
Example:
Creates headers and footers in a document using DocumentBuilder.
// Create a blank document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Specify that we want headers and footers different for first, even and odd pages.
builder.getPageSetup().setDifferentFirstPageHeaderFooter(true);
builder.getPageSetup().setOddAndEvenPagesHeaderFooter(true);
// Create the headers.
builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
builder.write("Header First");
builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
builder.write("Header Even");
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.write("Header Odd");
// Create three pages in the document.
builder.moveToSection(0);
builder.writeln("Page1");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page2");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page3");
doc.save(getMyDir() + "DocumentBuilder.HeadersAndFooters Out.doc");
getDifferentFirstPageHeaderFooter/setDifferentFirstPageHeaderFooter | |
public boolean getDifferentFirstPageHeaderFooter() / public void setDifferentFirstPageHeaderFooter(boolean value)
|
- True if a different header or footer is used on the first page.
Example:
Creates headers and footers different for first, even and odd pages using DocumentBuilder.
DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.getPageSetup();
ps.setDifferentFirstPageHeaderFooter(true);
ps.setOddAndEvenPagesHeaderFooter(true);
ps.setFirstPageTray(PaperTray.ENVELOPE_FEED);
ps.setOtherPagesTray(PaperTray.FORM_SOURCE);
builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
builder.writeln("First page header.");
builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
builder.writeln("Even pages header.");
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.writeln("Odd pages header.");
// Move back to the main story of the first section.
builder.moveToSection(0);
builder.writeln("Text page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Text page 2.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Text page 3.");
builder.getDocument().save(getMyDir() + "PageSetup.DifferentHeaders Out.doc");
Example:
Creates headers and footers in a document using DocumentBuilder.
// Create a blank document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Specify that we want headers and footers different for first, even and odd pages.
builder.getPageSetup().setDifferentFirstPageHeaderFooter(true);
builder.getPageSetup().setOddAndEvenPagesHeaderFooter(true);
// Create the headers.
builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
builder.write("Header First");
builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
builder.write("Header Even");
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.write("Header Odd");
// Create three pages in the document.
builder.moveToSection(0);
builder.writeln("Page1");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page2");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page3");
doc.save(getMyDir() + "DocumentBuilder.HeadersAndFooters Out.doc");
getMirrorMargins/setMirrorMargins | |
public boolean getMirrorMargins() / public void setMirrorMargins(boolean value)
|
-
For multiple page documents, swaps left and right margins on facing pages.
Note, changing this property affects all sections in the document.
getSectionStart/setSectionStart | |
public int getSectionStart() / public void setSectionStart(int value)
|
-
Returns or sets the type of section break for the specified object.
The value of the property is SectionStart integer constant.
Example:
Specifies how the section starts, from a new page, on the same page or other.
Document doc = new Document();
doc.getSections().get(0).getPageSetup().setSectionStart(SectionStart.CONTINUOUS);
Example:
Creates a simple document from scratch using the Aspose.Words object model.
// Create an "empty" document. Note that like in Microsoft Word,
// the empty document has one section, body and one paragraph in it.
Document doc = new Document();
// This truly makes the document empty. No sections (not possible in Microsoft Word).
doc.removeAllChildren();
// Create a new section node.
// Note that the section has not yet been added to the document,
// but we have to specify the parent document.
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);
// The section that we created is empty, lets populate it. The section needs at least the Body node.
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);
// So far we have one empty pararagraph in the document.
// The document is valid and can be saved, but lets add some text before saving.
// Create a new run of text and add it to our paragraph.
Run run = new Run(doc);
run.setText("Hello World!");
run.getFont().setColor(Color.RED);
para.appendChild(run);
// As a matter of interest, you can retrieve text of the whole document and
// see that \u000c is automatically appended. \u000c is the end of section character.
Assert.assertEquals("Hello World!\u000c", doc.getText());
// Save the document.
doc.save(getMyDir() + "Section.CreateFromScratch Out.doc");
getSuppressEndnotes/setSuppressEndnotes | |
public boolean getSuppressEndnotes() / public void setSuppressEndnotes(boolean value)
|
- True if endnotes are printed at the end of the next section that doesn't suppress endnotes.
Suppressed endnotes are printed before the endnotes in that section.
getVerticalAlignment/setVerticalAlignment | |
public int getVerticalAlignment() / public void setVerticalAlignment(int value)
|
-
Returns or sets the vertical alignment of text on each page in a document or section.
The value of the property is PageVerticalAlignment integer constant.
Example:
Shows how to insert sections using DocumentBuilder, specify page setup for a section and reset page setup to defaults.
DocumentBuilder builder = new DocumentBuilder();
// Modify the first section in the document.
builder.getPageSetup().setOrientation(Orientation.LANDSCAPE);
builder.getPageSetup().setVerticalAlignment(PageVerticalAlignment.CENTER);
builder.writeln("Section 1, landscape oriented and text vertically centered.");
// Start a new section and reset its formatting to defaults.
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
builder.getPageSetup().clearFormatting();
builder.writeln("Section 2, back to default Letter paper size, portrait orientation and top alignment.");
builder.getDocument().save(getMyDir() + "PageSetup.ClearFormatting Out.doc");
getBidi/setBidi | |
public boolean getBidi() / public void setBidi(boolean value)
|
-
Specifies that this section contains bidirectional (complex scripts) text.
When true, the columns in this section are laid out from right to left.
getPageWidth/setPageWidth | |
public double getPageWidth() / public void setPageWidth(double value)
|
-
Returns or sets the width of the page in points.
Example:
Shows how to insert a floating image and specify its position and size.
// This creates a builder and also an empty document inside the builder.
DocumentBuilder builder = new DocumentBuilder();
// By default, the image is inline.
Shape shape = builder.insertImage(getMyDir() + "Hammer.wmf");
// Make the image float, put it behind text and center on the page.
shape.setWrapType(WrapType.NONE);
// Make position relative to the page.
shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
// Make the shape occupy a band 50 points high at the very top of the page.
shape.setLeft(0);
shape.setTop(0);
shape.setWidth(builder.getCurrentSection().getPageSetup().getPageWidth());
shape.setHeight(50);
builder.getDocument().save(getMyDir() + "Image.CreateFloatingPositionSize Out.doc");
Example:
Inserts a watermark image into a document using DocumentBuilder.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// The best place for the watermark image is in the header or footer so it is shown on every page.
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
// Insert a floating picture.
BufferedImage image =
javax.imageio.ImageIO.read(new File(getMyDir() + "Watermark.png"));
Shape shape = builder.insertImage(image);
shape.setWrapType(WrapType.NONE);
shape.setBehindText(true);
shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
// Calculate image left and top position so it appears in the centre of the page.
shape.setLeft((builder.getPageSetup().getPageWidth() - shape.getWidth()) / 2);
shape.setTop((builder.getPageSetup().getPageHeight() - shape.getHeight()) / 2);
doc.save(getMyDir() + "DocumentBuilder.InsertWatermark Out.doc");
getPageHeight/setPageHeight | |
public double getPageHeight() / public void setPageHeight(double value)
|
-
Returns or sets the height of the page in points.
Example:
Inserts a watermark image into a document using DocumentBuilder.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// The best place for the watermark image is in the header or footer so it is shown on every page.
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
// Insert a floating picture.
BufferedImage image =
javax.imageio.ImageIO.read(new File(getMyDir() + "Watermark.png"));
Shape shape = builder.insertImage(image);
shape.setWrapType(WrapType.NONE);
shape.setBehindText(true);
shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
// Calculate image left and top position so it appears in the centre of the page.
shape.setLeft((builder.getPageSetup().getPageWidth() - shape.getWidth()) / 2);
shape.setTop((builder.getPageSetup().getPageHeight() - shape.getHeight()) / 2);
doc.save(getMyDir() + "DocumentBuilder.InsertWatermark Out.doc");
getPaperSize/setPaperSize | |
public int getPaperSize() / public void setPaperSize(int value)
|
-
Returns or sets the paper size.
The value of the property is PaperSize integer constant.
Setting this property updates PageWidth and PageHeight values.
Setting this value to PaperSize.CUSTOM does not change existing values.
Example:
Specifies paper size, orientation, margins and other settings for a section.
DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.getPageSetup();
ps.setPaperSize(PaperSize.LEGAL);
ps.setOrientation(Orientation.LANDSCAPE);
ps.setTopMargin(ConvertUtil.inchToPoint(1.0));
ps.setBottomMargin(ConvertUtil.inchToPoint(1.0));
ps.setLeftMargin(ConvertUtil.inchToPoint(1.5));
ps.setRightMargin(ConvertUtil.inchToPoint(1.5));
ps.setHeaderDistance(ConvertUtil.inchToPoint(0.2));
ps.setFooterDistance(ConvertUtil.inchToPoint(0.2));
builder.writeln("Hellow world.");
builder.getDocument().save(getMyDir() + "PageSetup.PageMargins Out.doc");
Example:
Creates a simple document from scratch using the Aspose.Words object model.
// Create an "empty" document. Note that like in Microsoft Word,
// the empty document has one section, body and one paragraph in it.
Document doc = new Document();
// This truly makes the document empty. No sections (not possible in Microsoft Word).
doc.removeAllChildren();
// Create a new section node.
// Note that the section has not yet been added to the document,
// but we have to specify the parent document.
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);
// The section that we created is empty, lets populate it. The section needs at least the Body node.
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);
// So far we have one empty pararagraph in the document.
// The document is valid and can be saved, but lets add some text before saving.
// Create a new run of text and add it to our paragraph.
Run run = new Run(doc);
run.setText("Hello World!");
run.getFont().setColor(Color.RED);
para.appendChild(run);
// As a matter of interest, you can retrieve text of the whole document and
// see that \u000c is automatically appended. \u000c is the end of section character.
Assert.assertEquals("Hello World!\u000c", doc.getText());
// Save the document.
doc.save(getMyDir() + "Section.CreateFromScratch Out.doc");
getOrientation/setOrientation | |
public int getOrientation() / public void setOrientation(int value)
|
-
Returns or sets the orientation of the page.
The value of the property is Orientation integer constant.
Changing Orientation swaps PageWidth and PageHeight.
Example:
Specifies paper size, orientation, margins and other settings for a section.
DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.getPageSetup();
ps.setPaperSize(PaperSize.LEGAL);
ps.setOrientation(Orientation.LANDSCAPE);
ps.setTopMargin(ConvertUtil.inchToPoint(1.0));
ps.setBottomMargin(ConvertUtil.inchToPoint(1.0));
ps.setLeftMargin(ConvertUtil.inchToPoint(1.5));
ps.setRightMargin(ConvertUtil.inchToPoint(1.5));
ps.setHeaderDistance(ConvertUtil.inchToPoint(0.2));
ps.setFooterDistance(ConvertUtil.inchToPoint(0.2));
builder.writeln("Hellow world.");
builder.getDocument().save(getMyDir() + "PageSetup.PageMargins Out.doc");
Example:
Shows how to insert sections using DocumentBuilder, specify page setup for a section and reset page setup to defaults.
DocumentBuilder builder = new DocumentBuilder();
// Modify the first section in the document.
builder.getPageSetup().setOrientation(Orientation.LANDSCAPE);
builder.getPageSetup().setVerticalAlignment(PageVerticalAlignment.CENTER);
builder.writeln("Section 1, landscape oriented and text vertically centered.");
// Start a new section and reset its formatting to defaults.
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
builder.getPageSetup().clearFormatting();
builder.writeln("Section 2, back to default Letter paper size, portrait orientation and top alignment.");
builder.getDocument().save(getMyDir() + "PageSetup.ClearFormatting Out.doc");
getLeftMargin/setLeftMargin | |
public double getLeftMargin() / public void setLeftMargin(double value)
|
-
Returns or sets the distance (in points) between the left edge of the page and the left boundary of the body text.
Example:
Specifies paper size, orientation, margins and other settings for a section.
DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.getPageSetup();
ps.setPaperSize(PaperSize.LEGAL);
ps.setOrientation(Orientation.LANDSCAPE);
ps.setTopMargin(ConvertUtil.inchToPoint(1.0));
ps.setBottomMargin(ConvertUtil.inchToPoint(1.0));
ps.setLeftMargin(ConvertUtil.inchToPoint(1.5));
ps.setRightMargin(ConvertUtil.inchToPoint(1.5));
ps.setHeaderDistance(ConvertUtil.inchToPoint(0.2));
ps.setFooterDistance(ConvertUtil.inchToPoint(0.2));
builder.writeln("Hellow world.");
builder.getDocument().save(getMyDir() + "PageSetup.PageMargins Out.doc");
getRightMargin/setRightMargin | |
public double getRightMargin() / public void setRightMargin(double value)
|
-
Returns or sets the distance (in points) between the right edge of the page and the right boundary of the body text.
Example:
Specifies paper size, orientation, margins and other settings for a section.
DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.getPageSetup();
ps.setPaperSize(PaperSize.LEGAL);
ps.setOrientation(Orientation.LANDSCAPE);
ps.setTopMargin(ConvertUtil.inchToPoint(1.0));
ps.setBottomMargin(ConvertUtil.inchToPoint(1.0));
ps.setLeftMargin(ConvertUtil.inchToPoint(1.5));
ps.setRightMargin(ConvertUtil.inchToPoint(1.5));
ps.setHeaderDistance(ConvertUtil.inchToPoint(0.2));
ps.setFooterDistance(ConvertUtil.inchToPoint(0.2));
builder.writeln("Hellow world.");
builder.getDocument().save(getMyDir() + "PageSetup.PageMargins Out.doc");
getTopMargin/setTopMargin | |
public double getTopMargin() / public void setTopMargin(double value)
|
-
Returns or sets the distance (in points) between the top edge of the page and the top boundary of the body text.
Example:
Specifies paper size, orientation, margins and other settings for a section.
DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.getPageSetup();
ps.setPaperSize(PaperSize.LEGAL);
ps.setOrientation(Orientation.LANDSCAPE);
ps.setTopMargin(ConvertUtil.inchToPoint(1.0));
ps.setBottomMargin(ConvertUtil.inchToPoint(1.0));
ps.setLeftMargin(ConvertUtil.inchToPoint(1.5));
ps.setRightMargin(ConvertUtil.inchToPoint(1.5));
ps.setHeaderDistance(ConvertUtil.inchToPoint(0.2));
ps.setFooterDistance(ConvertUtil.inchToPoint(0.2));
builder.writeln("Hellow world.");
builder.getDocument().save(getMyDir() + "PageSetup.PageMargins Out.doc");
getBottomMargin/setBottomMargin | |
public double getBottomMargin() / public void setBottomMargin(double value)
|
-
Returns or sets the distance (in points) between the bottom edge of the page and the bottom boundary of the body text.
Example:
Specifies paper size, orientation, margins and other settings for a section.
DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.getPageSetup();
ps.setPaperSize(PaperSize.LEGAL);
ps.setOrientation(Orientation.LANDSCAPE);
ps.setTopMargin(ConvertUtil.inchToPoint(1.0));
ps.setBottomMargin(ConvertUtil.inchToPoint(1.0));
ps.setLeftMargin(ConvertUtil.inchToPoint(1.5));
ps.setRightMargin(ConvertUtil.inchToPoint(1.5));
ps.setHeaderDistance(ConvertUtil.inchToPoint(0.2));
ps.setFooterDistance(ConvertUtil.inchToPoint(0.2));
builder.writeln("Hellow world.");
builder.getDocument().save(getMyDir() + "PageSetup.PageMargins Out.doc");
getHeaderDistance/setHeaderDistance | |
public double getHeaderDistance() / public void setHeaderDistance(double value)
|
-
Returns or sets the distance (in points) between the header and the top of the page.
Example:
Specifies paper size, orientation, margins and other settings for a section.
DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.getPageSetup();
ps.setPaperSize(PaperSize.LEGAL);
ps.setOrientation(Orientation.LANDSCAPE);
ps.setTopMargin(ConvertUtil.inchToPoint(1.0));
ps.setBottomMargin(ConvertUtil.inchToPoint(1.0));
ps.setLeftMargin(ConvertUtil.inchToPoint(1.5));
ps.setRightMargin(ConvertUtil.inchToPoint(1.5));
ps.setHeaderDistance(ConvertUtil.inchToPoint(0.2));
ps.setFooterDistance(ConvertUtil.inchToPoint(0.2));
builder.writeln("Hellow world.");
builder.getDocument().save(getMyDir() + "PageSetup.PageMargins Out.doc");
getFooterDistance/setFooterDistance | |
public double getFooterDistance() / public void setFooterDistance(double value)
|
-
Returns or sets the distance (in points) between the footer and the bottom of the page.
Example:
Specifies paper size, orientation, margins and other settings for a section.
DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.getPageSetup();
ps.setPaperSize(PaperSize.LEGAL);
ps.setOrientation(Orientation.LANDSCAPE);
ps.setTopMargin(ConvertUtil.inchToPoint(1.0));
ps.setBottomMargin(ConvertUtil.inchToPoint(1.0));
ps.setLeftMargin(ConvertUtil.inchToPoint(1.5));
ps.setRightMargin(ConvertUtil.inchToPoint(1.5));
ps.setHeaderDistance(ConvertUtil.inchToPoint(0.2));
ps.setFooterDistance(ConvertUtil.inchToPoint(0.2));
builder.writeln("Hellow world.");
builder.getDocument().save(getMyDir() + "PageSetup.PageMargins Out.doc");
getGutter/setGutter | |
public double getGutter() / public void setGutter(double value)
|
-
Gets or sets the amount of extra space added to the margin for document binding.
getFirstPageTray/setFirstPageTray | |
public int getFirstPageTray() / public void setFirstPageTray(int value)
|
-
Returns or sets the paper tray to use for the first page of a section.
The value of the property is PaperTray integer constant.
Example:
Creates headers and footers different for first, even and odd pages using DocumentBuilder.
DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.getPageSetup();
ps.setDifferentFirstPageHeaderFooter(true);
ps.setOddAndEvenPagesHeaderFooter(true);
ps.setFirstPageTray(PaperTray.ENVELOPE_FEED);
ps.setOtherPagesTray(PaperTray.FORM_SOURCE);
builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
builder.writeln("First page header.");
builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
builder.writeln("Even pages header.");
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.writeln("Odd pages header.");
// Move back to the main story of the first section.
builder.moveToSection(0);
builder.writeln("Text page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Text page 2.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Text page 3.");
builder.getDocument().save(getMyDir() + "PageSetup.DifferentHeaders Out.doc");
getOtherPagesTray/setOtherPagesTray | |
public int getOtherPagesTray() / public void setOtherPagesTray(int value)
|
-
Returns or sets the paper tray to be used for all but the first page of a section.
The value of the property is PaperTray integer constant.
Example:
Creates headers and footers different for first, even and odd pages using DocumentBuilder.
DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.getPageSetup();
ps.setDifferentFirstPageHeaderFooter(true);
ps.setOddAndEvenPagesHeaderFooter(true);
ps.setFirstPageTray(PaperTray.ENVELOPE_FEED);
ps.setOtherPagesTray(PaperTray.FORM_SOURCE);
builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
builder.writeln("First page header.");
builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
builder.writeln("Even pages header.");
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.writeln("Odd pages header.");
// Move back to the main story of the first section.
builder.moveToSection(0);
builder.writeln("Text page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Text page 2.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Text page 3.");
builder.getDocument().save(getMyDir() + "PageSetup.DifferentHeaders Out.doc");
getPageNumberStyle/setPageNumberStyle | |
public int getPageNumberStyle() / public void setPageNumberStyle(int value)
|
-
Gets or sets the page number format.
The value of the property is NumberStyle integer constant.
Example:
Shows how to control page numbering per section.
// This document has two sections, but no page numbers yet.
Document doc = new Document(getMyDir() + "PageSetup.PageNumbering.doc");
// Use document builder to create a header with a page number field for the first section.
// The page number will look like "Page V".
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToSection(0);
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.write("Page ");
builder.insertField("PAGE", "");
// Set first section page numbering.
Section section = doc.getSections().get(0);
section.getPageSetup().setRestartPageNumbering(true);
section.getPageSetup().setPageStartingNumber(5);
section.getPageSetup().setPageNumberStyle(NumberStyle.UPPERCASE_ROMAN);
// Create a header for the section section.
// The page number will look like " - 10 - ".
builder.moveToSection(1);
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.write(" - ");
builder.insertField("PAGE", "");
builder.write(" - ");
// Set second section page numbering.
section = doc.getSections().get(1);
section.getPageSetup().setPageStartingNumber(10);
section.getPageSetup().setRestartPageNumbering(true);
section.getPageSetup().setPageNumberStyle(NumberStyle.ARABIC);
doc.save(getMyDir() + "PageSetup.PageNumbering Out.doc");
getRestartPageNumbering/setRestartPageNumbering | |
public boolean getRestartPageNumbering() / public void setRestartPageNumbering(boolean value)
|
- True if page numbering restarts at the beginning of the section.
If set to false, the RestartPageNumbering property will override the
PageStartingNumber property so that page numbering can continue from the previous section.
Example:
Shows how to control page numbering per section.
// This document has two sections, but no page numbers yet.
Document doc = new Document(getMyDir() + "PageSetup.PageNumbering.doc");
// Use document builder to create a header with a page number field for the first section.
// The page number will look like "Page V".
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToSection(0);
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.write("Page ");
builder.insertField("PAGE", "");
// Set first section page numbering.
Section section = doc.getSections().get(0);
section.getPageSetup().setRestartPageNumbering(true);
section.getPageSetup().setPageStartingNumber(5);
section.getPageSetup().setPageNumberStyle(NumberStyle.UPPERCASE_ROMAN);
// Create a header for the section section.
// The page number will look like " - 10 - ".
builder.moveToSection(1);
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.write(" - ");
builder.insertField("PAGE", "");
builder.write(" - ");
// Set second section page numbering.
section = doc.getSections().get(1);
section.getPageSetup().setPageStartingNumber(10);
section.getPageSetup().setRestartPageNumbering(true);
section.getPageSetup().setPageNumberStyle(NumberStyle.ARABIC);
doc.save(getMyDir() + "PageSetup.PageNumbering Out.doc");
getPageStartingNumber/setPageStartingNumber | |
public int getPageStartingNumber() / public void setPageStartingNumber(int value)
|
-
Gets or sets the starting page number of the section.
The RestartPageNumbering property, if set to false, will override the
PageStartingNumber property so that page numbering can continue from the previous section.
Example:
Shows how to control page numbering per section.
// This document has two sections, but no page numbers yet.
Document doc = new Document(getMyDir() + "PageSetup.PageNumbering.doc");
// Use document builder to create a header with a page number field for the first section.
// The page number will look like "Page V".
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToSection(0);
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.write("Page ");
builder.insertField("PAGE", "");
// Set first section page numbering.
Section section = doc.getSections().get(0);
section.getPageSetup().setRestartPageNumbering(true);
section.getPageSetup().setPageStartingNumber(5);
section.getPageSetup().setPageNumberStyle(NumberStyle.UPPERCASE_ROMAN);
// Create a header for the section section.
// The page number will look like " - 10 - ".
builder.moveToSection(1);
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.write(" - ");
builder.insertField("PAGE", "");
builder.write(" - ");
// Set second section page numbering.
section = doc.getSections().get(1);
section.getPageSetup().setPageStartingNumber(10);
section.getPageSetup().setRestartPageNumbering(true);
section.getPageSetup().setPageNumberStyle(NumberStyle.ARABIC);
doc.save(getMyDir() + "PageSetup.PageNumbering Out.doc");
getLineNumberRestartMode/setLineNumberRestartMode | |
public int getLineNumberRestartMode() / public void setLineNumberRestartMode(int value)
|
-
Gets or sets the way line numbering runs that is, whether it starts over at the beginning of a new
page or section or runs continuously.
The value of the property is LineNumberRestartMode integer constant.
Example:
Turns on Microsoft Word line numbering for a section.
DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.getPageSetup();
ps.setLineStartingNumber(1);
ps.setLineNumberCountBy(5);
ps.setLineNumberRestartMode(LineNumberRestartMode.RESTART_PAGE);
for (int i = 1; i <= 20; i++)
builder.writeln(MessageFormat.format("Line {0}.", i));
builder.getDocument().save(getMyDir() + "PageSetup.LineNumbers Out.doc");
getLineNumberCountBy/setLineNumberCountBy | |
public int getLineNumberCountBy() / public void setLineNumberCountBy(int value)
|
-
Returns or sets the numeric increment for line numbers.
Example:
Turns on Microsoft Word line numbering for a section.
DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.getPageSetup();
ps.setLineStartingNumber(1);
ps.setLineNumberCountBy(5);
ps.setLineNumberRestartMode(LineNumberRestartMode.RESTART_PAGE);
for (int i = 1; i <= 20; i++)
builder.writeln(MessageFormat.format("Line {0}.", i));
builder.getDocument().save(getMyDir() + "PageSetup.LineNumbers Out.doc");
getLineNumberDistanceFromText/setLineNumberDistanceFromText | |
public double getLineNumberDistanceFromText() / public void setLineNumberDistanceFromText(double value)
|
-
Gets or sets distance between the right edge of line numbers and the left edge of the document.
Set this property to zero for automatic distance between the line numbers and text of the document.
getLineStartingNumber/setLineStartingNumber | |
public int getLineStartingNumber() / public void setLineStartingNumber(int value)
|
-
Gets or sets the starting line number.
Example:
Turns on Microsoft Word line numbering for a section.
DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.getPageSetup();
ps.setLineStartingNumber(1);
ps.setLineNumberCountBy(5);
ps.setLineNumberRestartMode(LineNumberRestartMode.RESTART_PAGE);
for (int i = 1; i <= 20; i++)
builder.writeln(MessageFormat.format("Line {0}.", i));
builder.getDocument().save(getMyDir() + "PageSetup.LineNumbers Out.doc");
-
Returns a collection that represents the set of text columns.
Example:
Creates multiple evenly spaced columns in a section using DocumentBuilder.
DocumentBuilder builder = new DocumentBuilder();
TextColumnCollection columns = builder.getPageSetup().getTextColumns();
// Make spacing between columns wider.
columns.setSpacing(100);
// This creates two columns of equal width.
columns.setCount(2);
builder.writeln("Text in column 1.");
builder.insertBreak(BreakType.COLUMN_BREAK);
builder.writeln("Text in column 2.");
builder.getDocument().save(getMyDir() + "PageSetup.ColumnsSameWidth Out.doc");
getRtlGutter/setRtlGutter | |
public boolean getRtlGutter() / public void setRtlGutter(boolean value)
|
-
Gets or sets whether Microsoft Word uses gutters for the section based on a right-to-left language or a left-to-right language.
getBorderAlwaysInFront/setBorderAlwaysInFront | |
public boolean getBorderAlwaysInFront() / public void setBorderAlwaysInFront(boolean value)
|
-
Specifies where the page border is positioned relative to intersecting texts and objects.
Example:
Creates a page border that looks like a wide blue band at the top of the first page only.
Document doc = new Document();
PageSetup ps = doc.getSections().get(0).getPageSetup();
ps.setBorderAlwaysInFront(false);
ps.setBorderDistanceFrom(PageBorderDistanceFrom.PAGE_EDGE);
ps.setBorderAppliesTo(PageBorderAppliesTo.FIRST_PAGE);
Border border = ps.getBorders().get(BorderType.TOP);
border.setLineStyle(LineStyle.SINGLE);
border.setLineWidth(30);
border.setColor(Color.BLUE);
border.setDistanceFromText(0);
doc.save(getMyDir() + "PageSetup.PageBorderTop Out.doc");
getBorderDistanceFrom/setBorderDistanceFrom | |
public int getBorderDistanceFrom() / public void setBorderDistanceFrom(int value)
|
-
Gets or sets a value that indicates whether the specified page border is measured from the edge of the page or from the text it surrounds.
The value of the property is PageBorderDistanceFrom integer constant.
Example:
Creates a page border that looks like a wide blue band at the top of the first page only.
Document doc = new Document();
PageSetup ps = doc.getSections().get(0).getPageSetup();
ps.setBorderAlwaysInFront(false);
ps.setBorderDistanceFrom(PageBorderDistanceFrom.PAGE_EDGE);
ps.setBorderAppliesTo(PageBorderAppliesTo.FIRST_PAGE);
Border border = ps.getBorders().get(BorderType.TOP);
border.setLineStyle(LineStyle.SINGLE);
border.setLineWidth(30);
border.setColor(Color.BLUE);
border.setDistanceFromText(0);
doc.save(getMyDir() + "PageSetup.PageBorderTop Out.doc");
getBorderAppliesTo/setBorderAppliesTo | |
public int getBorderAppliesTo() / public void setBorderAppliesTo(int value)
|
-
Specifies which pages the page border is printed on.
The value of the property is PageBorderAppliesTo integer constant.
Example:
Creates a page border that looks like a wide blue band at the top of the first page only.
Document doc = new Document();
PageSetup ps = doc.getSections().get(0).getPageSetup();
ps.setBorderAlwaysInFront(false);
ps.setBorderDistanceFrom(PageBorderDistanceFrom.PAGE_EDGE);
ps.setBorderAppliesTo(PageBorderAppliesTo.FIRST_PAGE);
Border border = ps.getBorders().get(BorderType.TOP);
border.setLineStyle(LineStyle.SINGLE);
border.setLineWidth(30);
border.setColor(Color.BLUE);
border.setDistanceFromText(0);
doc.save(getMyDir() + "PageSetup.PageBorderTop Out.doc");
getBorderSurroundsHeader/setBorderSurroundsHeader | |
public boolean getBorderSurroundsHeader() / public void setBorderSurroundsHeader(boolean value)
|
-
Specifies whether the page border includes or excludes the header.
Note, changing this property affects all sections in the document.
getBorderSurroundsFooter/setBorderSurroundsFooter | |
public boolean getBorderSurroundsFooter() / public void setBorderSurroundsFooter(boolean value)
|
-
Specifies whether the page border includes or excludes the footer.
Note, changing this property affects all sections in the document.
-
Gets a collection of the page borders.
Example:
Creates a fancy looking green wavy page border with a shadow.
Document doc = new Document();
PageSetup ps = doc.getSections().get(0).getPageSetup();
ps.getBorders().setLineStyle(LineStyle.DOUBLE_WAVE);
ps.getBorders().setLineWidth(2);
ps.getBorders().setColor(Color.GREEN);
ps.getBorders().setDistanceFromText(24);
ps.getBorders().setShadow(true);
doc.save(getMyDir() + "PageSetup.PageBorders Out.doc");
-
Provides options that control numbering and positioning of footnotes in this section.
-
Provides options that control numbering and positioning of endnotes in this section.
clearFormatting | |
public void clearFormatting() |
-
Resets page setup to default paper size, margins and orientation.
Example:
Shows how to insert sections using DocumentBuilder, specify page setup for a section and reset page setup to defaults.
DocumentBuilder builder = new DocumentBuilder();
// Modify the first section in the document.
builder.getPageSetup().setOrientation(Orientation.LANDSCAPE);
builder.getPageSetup().setVerticalAlignment(PageVerticalAlignment.CENTER);
builder.writeln("Section 1, landscape oriented and text vertically centered.");
// Start a new section and reset its formatting to defaults.
builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
builder.getPageSetup().clearFormatting();
builder.writeln("Section 2, back to default Letter paper size, portrait orientation and top alignment.");
builder.getDocument().save(getMyDir() + "PageSetup.ClearFormatting Out.doc");
getDirectBorderAttr | |
public java.lang.Object getDirectBorderAttr(int key) |
- Reserved for internal use.
fetchInheritedBorderAttr | |
public java.lang.Object fetchInheritedBorderAttr(int key)
throws java.lang.Exception |
- Reserved for internal use.
setBorderAttr | |
public void setBorderAttr(int key, java.lang.Object value) |
- Reserved for internal use.
See Also:
Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
Aspose.Words Support Forum - our preferred method of support.