Class DocumentLayout
A document broken into pages: every line, table, picture and footnote placed, in points.
Layout is pure: it reads a Document and a Measurer and touches no user interface, so the
same result paints DocumentView, is written by the PDF export, and can run on a server.
DocumentModel model = new DocumentModel(new Document());
model.insertBlock(0, new Paragraph(model.newId('p'), RichText.of("Quarterly review")));
DocumentLayout layout = new DocumentLayout(model.getDocument(), new PdfMeasurer());
for (int i = 0; i < layout.getPageCount(); i++) {
for (LayoutItem item : layout.getPage(i).getItems()) {
Log.p("page " + i + ": item at " + item.x + ", " + item.y);
}
}
Paragraphs break at spaces (a word wider than the line breaks between letters) and honor
alignment, justification, indents, spacing, line spacing, page breaks and keep-with-next.
List items get bullets or numbers, restarted where the paragraph says so. Table rows move to
the next page whole, repeating the header rows; a row taller than a page is split. Footnotes
are placed at the bottom of the page that references them and endnotes after the text. PAGE
and NUMPAGES fields show the real page number and count.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfloat[]caretRect(TextPosition position) Where the caret for a position is drawn.The measurer this layout was made with.getPage(int index) A page.intThe number of pages; at least one.The page geometry used.positionAt(int page, float x, float y) The caret position nearest a point on a page.
-
Constructor Details
-
DocumentLayout
-
-
Method Details
-
getPageSpec
The page geometry used.
Returns
the document's page, or A4 when it has none
-
getPageCount
public int getPageCount()The number of pages; at least one.
Returns
the page count
-
getPage
A page.
Parameters
index: from zero
Returns
the page
-
getMeasurer
The measurer this layout was made with.
Returns
the measurer
-
positionAt
The caret position nearest a point on a page.
Parameters
-
page: the page index -
x: from the page's left edge, in points -
y: from the page's top edge, in points
Returns
the position, or null when the page holds no text
-
-
caretRect
Where the caret for a position is drawn.
Parameters
position: the position
Returns
{page, x, top, height}in points, or null when the paragraph is not laid out
-