Color modes

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

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.

Apryse Docs Image

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. Call setColorPostProcessMode(int).
  2. Optionally, set the PDFViewCtrl background color for the best visual result. You can set background color by calling setClientBackgroundColor(int, int, int, boolean).For example, set the background color to black for night mode:
Apryse Docs Image
1mPdfViewCtrl.setClientBackgroundColor(0, 0, 0, false);
  1. If you are using postprocess_gradient_map, call PDFViewCtrl.setColorPostProcessColors(int, int) to set the white and black points. For example, for a sepia effect, try:
1int darkBrown = Color.rgb(61, 38, 10);
2int lightBrown = Color.rgb(245, 224, 202);
3mPdfViewCtrl.setColorPostProcessColors(lightBrown, darkBrown);
  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:
1mPdfViewCtrl.update(true);
Apryse Docs Image
1private PDFViewCtrl mPdfViewCtrl;
2// ...
3// Sets background color to dark gray, as well as text color to red.
4private void setCustomColorMode(@ColorInt int backgroundColor, @ColorInt int textColor) throws PDFNetException {
5 // Sets color process mode
6 mPdfViewCtrl.setColorPostProcessMode(PDFRasterizer.e_postprocess_gradient_map);
7 // Sets client area color to backgroundColor
8 mPdfViewCtrl.setClientBackgroundColor(Color.red(backgroundColor), Color.green(backgroundColor), Color.blue(backgroundColor), false);
9 // Sets background color and text color
10 mPdfViewCtrl.setColorPostProcessColors(backgroundColor, textColor);
11 // Updates mPdfViewCtrl
12 mPdfViewCtrl.update(true);
13}
Apryse Docs Image

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:
Apryse Docs Image

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

  1. Set the gradient image to a new MappedFile:
1InputStream is = null;
2OutputStream os = null;
3MappedFile mappedFile = null;
4try {
5 File filterFile = new File(activity.getCacheDir(), "cachedCustomColorFilter.png");
6 if (!filterFile.exists() || !filterFile.isFile()) {
7 is = getResources().openRawResource(R.raw.custom_mode_filter);
8 os = new FileOutputStream(filterFile);
9 IOUtils.copy(is, os);
10 }
11 mappedFile = new MappedFile(filterFile.getAbsolutePath());
12} catch (Exception e) {
13 e.printStackTrace();
14} finally {
15 IOUtils.closeQuietly(is);
16 IOUtils.closeQuietly(os);
17}
  1. Set the mappedFile created above to PDFViewCtrl by calling PDFViewCtrl.setColorPostProcessMapFile(Filter).Where pdfViewCtrl is an instance of PDFViewCtrl.
1if (mappedFile != null) {
2 try {
3 pdfViewCtrl.setColorPostProcessMapFile(mappedFile);
4 } catch (PDFNetException e) {
5 e.printStackTrace();
6 }
7}
  1. Set the color process mode PDFRasterizer.e_postprocess_gradient_map to pdfViewCtrl by calling pdfViewCtrl.setColorPostProcessMode(int). Then update pdfViewCtrl:
1try {
2 pdfViewCtrl.setColorPostProcessMode(PDFRasterizer.e_postprocess_gradient_map);
3 // Sets client area background color to rgb(138, 138, 138)
4 pdfViewCtrl.setClientBackgroundColor(138, 138, 138, false);
5 // Updates pdfViewCtrl
6 pdfViewCtrl.update(true);
7} catch (PDFNetException e) {
8 e.printStackTrace();
9}

Result:

Apryse Docs Image

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales