View mode

There are a few view modes which can be adjusted to provide an optimal presentation such as layout, fit, or reflow. Additionally, you can present a view mode dialog allowing a user to change these settings.

Reflow document mode in Android

For Android, available in the full version of the library only. See Apryse full or standard?

Reflow makes the document more flexible and easier to read, especially on small devices. Apryse is able to extract the reflowable layout of each page in a PDF document to an HTML file. First, we explain how simple it is to show a widget that allows the user to swipe left or right through the pages of the document to see reflowable document pages. Then, we provide the methods necessary for converting a hard-layout PDF page to an HTML document page.

Show reflow pager

ReflowControl is a ViewPager that allows the user to flip left and right through the reflowable layout of pages in a PDF document.

Apryse Docs Image

Implementation

To set up your layout with ReflowControl, add a <ReflowControl> element to your XML layout. For example, if each page in the swipe view should consume the entire layout, then your layout looks like this:

XML

1<com.pdftron.pdf.controls.ReflowControl xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/reflow_pager" android:layout_width="match_parent" android:layout_height="match_parent" />

Then, you need to attach a PDFDoc to the reflow pager:

1ReflowControl reflowControl = (ReflowControl) findViewById(R.id.reflow_pager);
2reflowControl.setup(pdfDoc);

Scrolling direction

1// horizontal (default)
2reflowControl.setOrientation(ReflowControl.HORIZONTAL);
3// vertical
4reflowControl.setOrientation(ReflowControl.VERTICAL);

That is everything you need to have a simple reflow pager. Next, we will go through advanced features.

Post-processing color

If you want to map each original color to a new color (for example for handling night mode) you need to pass an OnPostProcessColorListener listener to the ReflowControl.

To do so, you can provide an OnPostProcessColorListener listener when setting up the ReflowControl:

1ReflowControl reflowControl = (ReflowControl) findViewById(R.id.reflow_pager);
2reflowControl.setup(pdfDoc, mOnPostProcessColorListener);

For example, OnPostProcessColorListener can be defined by PDFViewCtrl as:

1final ReflowControl.OnPostProcessColorListener mOnPostProcessColorListener =
2 new ReflowControl.OnPostProcessColorListener() {
3 @Override
4 public ColorPt getPostProcessedColor(ColorPt cp) {
5 if (mPDFViewCtrl != null) {
6 return mPDFViewCtrl.getPostProcessedColor(cp);
7 }
8 return cp;
9 }
10 };

Alternatively you can set a listener:

1ReflowControl reflowControl = (ReflowControl) findViewById(R.id.reflow_pager);
2reflowControl.setup(pdfDoc);
3reflowControl.setOnPostProcessColorListener(mOnPostProcessColorListener);

Notify the reflow pager that the document has been modified

To refresh the reflow pager to show the latest changes on your document, you should let the reflow pager know that the document has been modified:

1void notifyReflowModified(ReflowControl reflowControl) {
2 if (reflowControl != null && reflowControl.isReady()) {
3 reflowControl.notifyPagesModified();
4 }
5}

Set the text size

It is possible to change the size of reflowable text. The default text size is 100; valid values are 5, 10, 25, 50, 75, 100, 125, 150, 200, 400, 800, and 1600. See the following code as an example:

1void changeReflowSize(ReflowControl reflowControl, int percent) {
2 if (reflowControl != null && reflowControl.isReady()) {
3 reflowControl.setTextSizeInPercent(percent);
4 }
5}

Alternatively, you can zoom in/out to change the reflowable text size:

1void zoomReflow(ReflowControl reflowControl, boolean zoomIn) {
2 if (reflowControl != null && reflowControl.isReady()) {
3 if (zoomIn) {
4 reflowControl.zoomIn();
5 } else {
6 reflowControl.zoomOut();
7 }
8 }
9}

Assuming the current text size is 100%, by calling zoomReflow(reflowControl, true) and zoomReflow(reflowControl, false) the new text size will be 125% and 75% of the original size, respectively.

Set background color

There are three methods to change the background color:

setDayMode(): no background

setNightMode(): night background

setCustomColorMode(int): customized background

Set right-to-left direction

You can support right-to-left (RTL) languages by setting the direction of reflowable text by calling setRightToLeftDirection(isRtlMode)

Generate a reflow page

It is not necessary to use a reflow pager to create a reflowable layout of PDF pages. It is also possible to extract the reflowable layout by creating an HTML file from a specific page of the document using the ReflowProcessor class. The first step is to let the Core know you are going to use reflow by calling initialize(). Please note that this method clears all existing reflowable data. Thus, preferably put this call in your Application or Activity.

When reflow processor has been initialized, it is possible to turn reflow on by calling getReflow(Page, RequestHandler, Object) and passing a RequestHandler callback in order to be notified once the reflowable HTML file is ready::

1void getReflowPage(PDFViewCtrl pdfViewCtrl, final int pageNum) throws Exception {
2 final PDFDoc doc = pdfViewCtrl.getDoc();
3 pdfViewCtrl.docLockRead(new PDFViewCtrl.LockRunnable() {
4 @Override
5 public void run() throws Exception {
6 Page page = doc.getPage(pageNum);
7 ReflowProcessor.getReflow(page, mRequestHandler, pageNum);
8 }
9 });
10}
11RequestHandler mRequestHandler = new RequestHandler(new RequestHandler.RequestHandlerCallback() {
12 @Override
13 public void RequestHandlerProc(RequestHandler.JobRequestResult result, String outFilename, Object customData) {
14 if (result == RequestHandler.JobRequestResult.FINISHED) {
15 // int pageNum = (int) customData;
16 // A reflowable HTML file with a page number of pageNum is located at outFilename
17 }
18 }
19});

To cancel all reflow requests, call cancelAllRequests().

Finally, if you want to clear all HTML files created in the cache, you may need to call clearCache().

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales