PdfiumCore
Core class for interacting with the Pdfium library.
This class provides a Java interface to the native Pdfium library, allowing you to open, read, render, and interact with PDF documents.
Key functionalities:
Opening PDF documents from files or byte arrays.
Retrieving document metadata, such as title, author, and page count.
Accessing and navigating through the document's table of contents (bookmarks).
Rendering pages to surfaces or bitmaps for display.
Extracting text from pages, including character positions and bounding boxes.
Searching for text within pages.
Handling annotations (limited functionality).
Managing native resources and closing documents.
Usage:
Create a new
PdfiumCore
instance.Open a PDF document using
newDocument()
.Perform desired operations, such as rendering pages or extracting text.
Close the document using
closeDocument()
to release native resources.
Example:
PdfiumCore pdfiumCore = new PdfiumCore();
try (ParcelFileDescriptor fd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY)) {
pdfiumCore.newDocument(fd);
int pageCount = pdfiumCore.getPageCount();
// ... perform operations on the document ...
} finally {
pdfiumCore.closeDocument();
}
Note: This class interacts with native code through JNI. Ensure that the necessary native libraries (pdfium and pdfium_jni) are loaded before using this class.
Functions
Closes the PDF document and releases resources.
Count number of rectangular areas occupied by a segment of texts.
Get Unicode of a character in a page.
Extract unicode text string from the page.
Extract unicode text within a rectangular boundary on the page. If the buffer is too small, as much text as will fit is copied into it.
Gets the error message from a specific error code.
Gets the last occurred error code. Should be called after a native function has failed.
Get page height in pixels.
This method requires page to be opened.
Get page height in PostScript points (1/72th of an inch).
This method requires page to be opened.
Get all links from given page
Get the rotation of page
Get size of page in pixels.
This method does not require given page to be opened.
Get page width in pixels.
This method requires page to be opened.
Get page width in PostScript points (1/72th of an inch).
This method requires page to be opened.
Get table of contents (bookmarks) for given document
Get a rectangular area from the result generated by FPDFText_CountRects.
Get bounding box of a particular character.
Create new document from file
Create new document from file with password
A handle class for the search context. stopSearch must be called to release this handle.
Prepare information about all characters in a page. Application must call FPDFText_ClosePage to release the text page information.
Prepare information about all characters in a range of pages. Application must call FPDFText_ClosePage to release the text page information.
Release all resources allocated for a text page information structure.
Sets the LogWriter instance to be used for logging.