Some test text!

Page color mode


Set the 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.

linkSet the color mode

To set the color mode:

  1. Find the constant value of the color mode

    Color modeConstant value
    Normal color modePDFRasterizer.e_postprocess_none
    Night modePDFRasterizer.e_postprocess_night_mode
    Inverted color modePDFRasterizer.e_postprocess_invert
    Custom color modePDFRasterizer.e_postprocess_gradient_map
  2. Call setColorPostProcessMode(int).

  3. 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:

    mPdfViewCtrl.setClientBackgroundColor(0, 0, 0, false);
  4. 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:

    int darkBrown = Color.rgb(61, 38, 10);
    int lightBrown = Color.rgb(245, 224, 202);
    mPdfViewCtrl.setColorPostProcessColors(lightBrown, darkBrown);
  5. 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:

    private PDFViewCtrl mPdfViewCtrl;
    // ...
    // Sets background color to dark gray, as well as text color to red.
    private void setCustomColorMode(@ColorInt int backgroundColor, @ColorInt int textColor) throws PDFNetException {
        // Sets color process mode
        // Sets client area color to backgroundColor
        mPdfViewCtrl.setClientBackgroundColor(,,, false);
        // Sets background color and text color
        mPdfViewCtrl.setColorPostProcessColors(backgroundColor, textColor);
        // Updates mPdfViewCtrl


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
  2. Set the gradient image to a new MappedFile:

    InputStream is = null;
    OutputStream os = null;
    MappedFile mappedFile = null;
    try {
        File filterFile = new File(activity.getCacheDir(), "cachedCustomColorFilter.png");
        if (!filterFile.exists() || !filterFile.isFile()) {
            is = getResources().openRawResource(R.raw.custom_mode_filter);
            os = new FileOutputStream(filterFile);
            IOUtils.copy(is, os);
        mappedFile = new MappedFile(filterFile.getAbsolutePath());
    } catch (Exception e) {
    } finally {
  3. Set the mappedFile created above to PDFViewCtrl by calling PDFViewCtrl.setColorPostProcessMapFile(Filter).

    if (mappedFile != null) {
        try {
        } catch (PDFNetException e) {

    Where pdfViewCtrl is an instance of PDFViewCtrl.

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

    try {
        // Sets client area background color to rgb(138, 138, 138)
        pdfViewCtrl.setClientBackgroundColor(138, 138, 138, false);
        // Updates pdfViewCtrl
    } catch (PDFNetException e) {


Get the anwsers you need: Support


Set the color mode