PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
The text content in a PDF is stored in a CPDFPage object associated with a specific page. The CPDFPage class can be used to retrieve text information from a PDF page, such as individual characters, single words, text content within a specified character range, or within a defined boundary.
The steps for text reflow are divided into two parts:
CPDFTextSelection array and rearrange it to fit the device screen size for displaying the same layout.Here is an example code for obtaining text boundaries on the page through selection:
RectF size = readerView.getPageNoZoomSize(1);
CPDFPage pdfPage = readerView.getPDFDocument().pageAtIndex(1);
CPDFTextPage pdfTextPage = pdfPage.getTextPage();
RectF selectRect = new RectF(0f, 0f, size.width(), size.height());
selectRect = pdfPage.convertRectFromPage(readerView.isCropMode(), size.width(), size.height(), selectRect);
CPDFTextSelection[] textSelectionArr = pdfTextPage.getSelectionsByLineForRect(selectRect);val size = readerView.getPageNoZoomSize(1)
val pdfPage = readerView.pdfDocument.pageAtIndex(1)
val pdfTextPage = pdfPage.textPage
var selectRect: RectF? = RectF(0F, 0F, size.width(), size.height())
selectRect = pdfPage.convertRectFromPage(readerView.isCropMode, size.width(), size.height(), selectRect)
val textSelectionArr = pdfTextPage.getSelectionsByLineForRect(selectRect)Here is an example code for retrieving text from the CPDFTextSelection array:
int len = textSelectionArr.length;
for (int i = 0; i < len; i++) {
CPDFTextSelection textSelection = textSelectionArr[i];
if (textSelection == null) {
continue;
}
String text = pdfTextPage.getText(textSelection.getTextRange());
}val textSelectionArr = pdfTextPage.getSelectionsByLineForRect(selectRect)
for (textSelection in textSelectionArr) {
val text = pdfTextPage.getText(textSelection.textRange)
}