Package com.pd4ml.dom

Class Layout


  • public final class Layout
    extends java.lang.Object
    The document laid out into pages as writePDF() would write it, as PD4ML.layout() returns it: where each element is, on which page, and its computed style. Positions are in PDF points from the top left corner of a page.
     Layout layout = pd4ml.layout();
     for (LayoutBox box : layout.getBoxes(doc.getElementById("signature"))) {
         System.out.println(box); // page 2: 56.69, 640.10, 481.89 x 85.00 pt
     }
     if (layout.getPageCount() > 1) {
         doc.getElementById("summary").setAttribute("style", "page-break-before: always");
     }
     pd4ml.writePDF(out);
     
    A layout is a snapshot: changes made to the document afterwards are not in it (call layout() again). The page content of pd4ml:page.header/footer, footnotes and endnotes is not part of it. With generateMulticolumn(), a page here is a column; on a page turned by a page format directive (rotate), boxes are given as on the page before turning.
    Since:
    v4.2.0
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Element elementAt​(int page, float x, float y)
      The innermost element at a point of a page, or null (a margin, or nothing there).
      java.util.List<LayoutBox> getBoxes​(Element element)
      The boxes of an element, in page order; empty if it is not displayed (display: none, in <head>, ...).
      java.lang.String getComputedStyle​(Element element, java.lang.String property)
      The computed value of a CSS property of an element (e.g.
      int getPageCount()
      The number of pages.
      float getPageHeight​(int page)
      The height of a page (1 for the first one), in points.
      int getPageNumber​(int page)
      The page number printed on a page (1 for the first one): $[page], after setInitialPageNumber().
      java.util.List<java.lang.Integer> getPages​(Element element)
      The pages an element is on, in order; empty if it is not displayed.
      float getPageWidth​(int page)
      The width of a page (1 for the first one), in points.
      static Layout of​(java.lang.Object pagedDocument, float pointsPerPixel)
      The layout object for a paginated v42 layout.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • of

        public static Layout of​(java.lang.Object pagedDocument,
                                float pointsPerPixel)
        The layout object for a paginated v42 layout. Internal: use PD4ML.layout().
      • getPageCount

        public int getPageCount()
        The number of pages.
      • getPageWidth

        public float getPageWidth​(int page)
        The width of a page (1 for the first one), in points.
      • getPageHeight

        public float getPageHeight​(int page)
        The height of a page (1 for the first one), in points.
      • getPageNumber

        public int getPageNumber​(int page)
        The page number printed on a page (1 for the first one): $[page], after setInitialPageNumber().
      • getBoxes

        public java.util.List<LayoutBox> getBoxes​(Element element)
        The boxes of an element, in page order; empty if it is not displayed (display: none, in <head>, ...).
      • getPages

        public java.util.List<java.lang.Integer> getPages​(Element element)
        The pages an element is on, in order; empty if it is not displayed.
      • getComputedStyle

        public java.lang.String getComputedStyle​(Element element,
                                                 java.lang.String property)
        The computed value of a CSS property of an element (e.g. color, font-size, display), as CSS text, or null if the element is not displayed.
      • elementAt

        public Element elementAt​(int page,
                                 float x,
                                 float y)
        The innermost element at a point of a page, or null (a margin, or nothing there).
        Parameters:
        page - the page, 1 for the first one
        x - the distance from the left edge of the page, in points
        y - the distance from the top edge of the page, in points