Class Page

java.lang.Object
org.nordstjernen.Page
All Implemented Interfaces:
AutoCloseable

public final class Page extends Object implements AutoCloseable
A laid-out page. Backed by native memory; close() frees it. Not thread-safe.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Largest full-page render dimension, in device pixels, to bound memory.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    linkAt(int x, int y)
    The absolute URL of the link at page coordinates (x, y) in CSS pixels, or null if there is none.
    All <a href> links on the page as absolute URLs, de-duplicated and in document order.
    Total laid-out page size in CSS pixels.
    render(int scrollX, int scrollY, int width, int height, double scale)
    Convenience wrapper around renderRgba(int, int, int, int, double) producing a premultiplied-ARGB image.
    renderFullPage(double scale)
    Render the entire page (top to bottom, full width) to a single image at scale.
    byte[]
    renderRgba(int scrollX, int scrollY, int width, int height, double scale)
    Render a viewport region into raw RGBA8888 (premultiplied) bytes, height rows of width*4 bytes.
    void
    Render the whole page to a file.
    The rendered text content of the page.
    The page's <title> (whitespace-collapsed), or null.
    url()
    The page's final URL (after redirects).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_FULL_PAGE_PX

      public static final int MAX_FULL_PAGE_PX
      Largest full-page render dimension, in device pixels, to bound memory.
      See Also:
  • Method Details

    • pageSize

      public Size pageSize()
      Total laid-out page size in CSS pixels.
    • text

      public String text()
      The rendered text content of the page.
    • title

      public String title()
      The page's <title> (whitespace-collapsed), or null.
    • url

      public String url()
      The page's final URL (after redirects).
    • links

      public List<String> links()
      All <a href> links on the page as absolute URLs, de-duplicated and in document order. javascript: and pure-fragment (#…) links are excluded.
    • linkAt

      public String linkAt(int x, int y)
      The absolute URL of the link at page coordinates (x, y) in CSS pixels, or null if there is none.
    • renderRgba

      public byte[] renderRgba(int scrollX, int scrollY, int width, int height, double scale)
      Render a viewport region into raw RGBA8888 (premultiplied) bytes, height rows of width*4 bytes.
      Parameters:
      scrollX - CSS-pixel x offset into the page
      scrollY - CSS-pixel y offset into the page
      width - output width in device pixels
      height - output height in device pixels
      scale - CSS-pixel to device-pixel scale (1.0 for 1:1)
    • render

      public BufferedImage render(int scrollX, int scrollY, int width, int height, double scale)
      Convenience wrapper around renderRgba(int, int, int, int, double) producing a premultiplied-ARGB image.
    • renderFullPage

      public BufferedImage renderFullPage(double scale)
      Render the entire page (top to bottom, full width) to a single image at scale. Each dimension is clamped to MAX_FULL_PAGE_PX device pixels.
    • renderToFile

      public void renderToFile(Path path)
      Render the whole page to a file. A .pdf path produces a PDF; any other path produces a PNG.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable