For the complete documentation index, see llms.txt. This page is also available as Markdown.

Color modes

There are a few themes which can be adjusted to change the output color mode.

Day and night themes in Android

AppCompat has a new theme called DayNight since Support Lib 23.2.0. So, if your activity's theme extends from one of the DayNight variants then you can switch between dark theme and light theme in your activity as follows.

As you can see, to take any effect for changing night mode the activity should be re-created.

For example, in our DocumentActivity, we change the device UI night mode when the PDFViewCtrl's color mode is updated:

You can also have different styles for device day/night modes by creating new resources for night. This involves adding a new directory to the resources folder, using the night qualifier, to re-define the resources. In the following example, primary colors and accent color are different in day and night mode:

res/values/styles.xml

res/values-night/styles.xml

Page color mode

PDFViewCtrl has three special color modes: night mode, inverted color mode, and custom color mode. In night mode, colors are adjusted to improve reading at night, in inverted color mode, all colors are inverted, and in custom color mode, you can set a custom color for text and the background color.

Color modes from left to right: normal color mode, inverted color mode, night mode and custom color mode.

Set the color mode

To set the color mode:

  1. Find the constant value of the color mode

  1. Optionally, set the PDFViewCtrl background color for the best visual result. You can set background color by calling [setClientBackgroundColor(int, int, int, boolean)](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/PDFViewCtrl.html#setClientBackgroundColor(int, int, int, boolean)).For example, set the background color to black for night mode:

  1. If you are using postprocess_gradient_map, call [PDFViewCtrl.setColorPostProcessColors(int, int)](https://sdk.apryse.com/api/android/javadoc/reference/com/pdftron/pdf/PDFViewCtrl.html#setColorPostProcessColors(int, int)) to set the white and black points. For example, for a sepia effect, try:

  1. Update PDFViewCtrl to redraw the contents:Sample result when using postprocess_gradient_map and a light/dark brown for the white/black color: The example below shows all of this functionality being used to set up a custom color mode for PDFViewCtrl:Result:

Alternatively, you can also set custom color mode by adding a gradient map image as follows:

  1. Add a gradient map .png image to your project res/raw folder.For example, add the following image to res/raw folder and name it custom_mode_filter.png:

To learn more about res/raw resource directory, see Providing Resources

  1. Set the gradient image to a new MappedFile:

  1. Set the mappedFile created above to PDFViewCtrl by calling PDFViewCtrl.setColorPostProcessMapFile(Filter).Where pdfViewCtrl is an instance of PDFViewCtrl.

  1. Set the color process mode PDFRasterizer.e_postprocess_gradient_map to pdfViewCtrl by calling pdfViewCtrl.setColorPostProcessMode(int). Then update pdfViewCtrl:

Result:

Last updated

Was this helpful?