Class PdfiumCore


  • public class PdfiumCore
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      PdfiumCore​(android.content.Context ctx)
      Context needed to get screen density
    • Constructor Detail

      • PdfiumCore

        public PdfiumCore​(android.content.Context ctx)
        Context needed to get screen density
    • Method Detail

      • getNumFd

        public static int getNumFd​(android.os.ParcelFileDescriptor fdObj)
      • newDocument

        public PdfDocument newDocument​(android.os.ParcelFileDescriptor fd)
                                throws java.io.IOException
        Create new document from file
        Throws:
        java.io.IOException
      • newDocument

        public PdfDocument newDocument​(android.os.ParcelFileDescriptor fd,
                                       java.lang.String password)
                                throws java.io.IOException
        Create new document from file with password
        Throws:
        java.io.IOException
      • newDocument

        public PdfDocument newDocument​(byte[] data)
                                throws java.io.IOException
        Create new document from bytearray
        Throws:
        java.io.IOException
      • newDocument

        public PdfDocument newDocument​(byte[] data,
                                       java.lang.String password)
                                throws java.io.IOException
        Create new document from bytearray with password
        Throws:
        java.io.IOException
      • getPageCount

        public int getPageCount​(PdfDocument doc)
        Get total numer of pages in document
      • openPage

        public long openPage​(PdfDocument doc,
                             int pageIndex)
        Open page and store native pointer in PdfDocument
      • openPage

        public long[] openPage​(PdfDocument doc,
                               int fromIndex,
                               int toIndex)
        Open range of pages and store native pointers in PdfDocument
      • getPageWidth

        public int getPageWidth​(PdfDocument doc,
                                int index)
        Get page width in pixels.
        This method requires page to be opened.
      • getPageHeight

        public int getPageHeight​(PdfDocument doc,
                                 int index)
        Get page height in pixels.
        This method requires page to be opened.
      • getPageWidthPoint

        public int getPageWidthPoint​(PdfDocument doc,
                                     int index)
        Get page width in PostScript points (1/72th of an inch).
        This method requires page to be opened.
      • getPageHeightPoint

        public int getPageHeightPoint​(PdfDocument doc,
                                      int index)
        Get page height in PostScript points (1/72th of an inch).
        This method requires page to be opened.
      • getPageSize

        public Size getPageSize​(PdfDocument doc,
                                int index)
        Get size of page in pixels.
        This method does not require given page to be opened.
      • renderPage

        public void renderPage​(PdfDocument doc,
                               android.view.Surface surface,
                               int pageIndex,
                               int startX,
                               int startY,
                               int drawSizeX,
                               int drawSizeY)
        Render page fragment on Surface.
        Page must be opened before rendering.
      • renderPage

        public void renderPage​(PdfDocument doc,
                               android.view.Surface surface,
                               int pageIndex,
                               int startX,
                               int startY,
                               int drawSizeX,
                               int drawSizeY,
                               boolean renderAnnot)
        Render page fragment on Surface. This method allows to render annotations.
        Page must be opened before rendering.
      • renderPageBitmap

        public void renderPageBitmap​(PdfDocument doc,
                                     android.graphics.Bitmap bitmap,
                                     int pageIndex,
                                     int startX,
                                     int startY,
                                     int drawSizeX,
                                     int drawSizeY)
        Render page fragment on Bitmap.
        Page must be opened before rendering.

        Supported bitmap configurations:

        • ARGB_8888 - best quality, high memory usage, higher possibility of OutOfMemoryError
        • RGB_565 - little worse quality, twice less memory usage
      • renderPageBitmap

        public void renderPageBitmap​(PdfDocument doc,
                                     android.graphics.Bitmap bitmap,
                                     int pageIndex,
                                     int startX,
                                     int startY,
                                     int drawSizeX,
                                     int drawSizeY,
                                     boolean renderAnnot)
        Render page fragment on Bitmap. This method allows to render annotations.
        Page must be opened before rendering.

        For more info see renderPageBitmap(PdfDocument, Bitmap, int, int, int, int, int)

      • closeDocument

        public void closeDocument​(PdfDocument doc)
        Release native resources and opened file
      • getTableOfContents

        public java.util.List<PdfDocument.Bookmark> getTableOfContents​(PdfDocument doc)
        Get table of contents (bookmarks) for given document
      • getPageLinks

        public java.util.List<PdfDocument.Link> getPageLinks​(PdfDocument doc,
                                                             int pageIndex)
        Get all links from given page
      • mapPageCoordsToDevice

        public android.graphics.Point mapPageCoordsToDevice​(PdfDocument doc,
                                                            int pageIndex,
                                                            int startX,
                                                            int startY,
                                                            int sizeX,
                                                            int sizeY,
                                                            int rotate,
                                                            double pageX,
                                                            double pageY)
        Map page coordinates to device screen coordinates
        Parameters:
        doc - pdf document
        pageIndex - index of page
        startX - left pixel position of the display area in device coordinates
        startY - top pixel position of the display area in device coordinates
        sizeX - horizontal size (in pixels) for displaying the page
        sizeY - vertical size (in pixels) for displaying the page
        rotate - page orientation: 0 (normal), 1 (rotated 90 degrees clockwise), 2 (rotated 180 degrees), 3 (rotated 90 degrees counter-clockwise)
        pageX - X value in page coordinates
        pageY - Y value in page coordinate
        Returns:
        mapped coordinates