Android
ComPDFKit PDF SDK
Guides

Text Reflow

 

Rearrange text to fit the device screen size for displaying same layout by using the following method.

 

// First, get array of TextSelection from the specific area on a page.
RectF size = readerView.getPageNoZoomSize(1);
CPDFPage pdfPage = readerView.getPDFDocument().pageAtIndex(1);
CPDFTextPage pdfTextPage = pdfPage.getTextPage();
RectF selectRect = new RectF(0f, 0f, 500f, 500f);
selectRect = pdfPage.convertRectFromPage(readerView.isCropMode(), size.width(), size.height(), selectRect);
TextSelection[] selections = pdfTextPage.getSelectionsByLineForRect(selectRect);
 
//Then, get text from array of TextSelection.
int len = selections.length;
for (int i = 0; i < len; i++) {
   TextSelection textSelection = selections[i];
   if (textSelection == null) {
       continue;
  }
   String text = pdfTextPage.getText(textSelection.getTextRange());
}