Right-to-Left (RTL) Support in Our Android PDF Viewer
PDF documents support a metaphorical page binding, which is used when pages are laid out horizontally. Many languages use a left-to-right script, which calls for a page binding on the left edge. However, binding on the right edge is preferable for right-to-left scripts such as Arabic and Hebrew and several East Asian scripts. The page binding is used with horizontal scrolling and in the thumbnails view. It has no effect when using vertical scrolling unless double-page mode is also enabled.
The page binding ought to be specified by the author when a PDF is created. However, sometimes this isn’t done, in which case, most PDF readers will default to a left-edge binding.
Updating the Page Binding Programmatically
PSPDFKit for Android uses the
PageBinding enum to define the possible values that can be used to configure a document’s page binding via the
PdfDocument#setPageBinding() method. The possible values are:
LEFT_EDGE— the document flows from left to right
RIGHT_EDGE— the document flows from right to left
UNKNOWN— the document doesn’t explicitly define a page binding, so the behavior is the same as it is with
The following snippet updates the page binding property of a document:
val document: PdfDocument = ... // This document should be read from right to left. document.pageBinding = PageBinding.RIGHT_EDGE document.saveIfModified()
PdfDocument document = ... // This document should be read from right to left. document.setPageBinding(PageBinding.RIGHT_EDGE); document.saveIfModified();
The following UI components will change their behavior based on the current document’s page binding. Keep in mind that all other UI components that aren’t mentioned here will follow the layout direction provided by the currently selected locale.
When in horizontal scrolling mode, documents with the
RIGHT_EDGEpage binding will scroll from right to left instead of the default left to right.
When in vertical double-page mode, documents with the
RIGHT_EDGEpage binding will have their displayed page order flipped pairwise. So the right page will be the first one, the left page will be the second one, and so on.
The Thumbnail Bar
In documents with the
RIGHT_EDGEpage binding, the order of thumbnails will be flipped, so the first page will be on the right and the last page will be on the left.
This also applies when in double-page mode, where the order of the pages in the pairs is also flipped.
The Thumbnail Grid
In documents with the
RIGHT_EDGEpage binding, the thumbnails will be laid out from right to left, so the first page will be on the top right.
Updating the Page Binding via the UI
You can also edit a document’s page binding directly from the
Changing the page binding will automatically trigger a restart of the
PdfActivity, since changing the page binding requires the
PdfFragment and the rest of the UI to be recreated.