Some test text!

Search
Hamburger Icon

Xamarin / Guides

Customize PDFViewCtrl

You can change the color themes inside document viewers.

Change color theme in Xamarin.iOS viewer

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
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

    Color modeConstant value
    Normal color modePDFRasterizer.ColorPostProcessMode.e_postprocess_none
    Night modePDFRasterizer.ColorPostProcessMode.e_postprocess_night_mode
    Inverted color modePDFRasterizer.ColorPostProcessMode.e_postprocess_invert
    Custom color modePDFRasterizer.ColorPostProcessMode.e_postprocess_gradient_map
  2. Call SetColorPostProcessMode.

  3. Optionally, set the PDFViewCtrl background color for the best visual result. You can set background color by calling SetClientBackgroundColor (Xamarin.Android) or SetBackgroundColor (Xamarin.iOS).

    Background area

    For example, set the background color to black for night mode:

    // Xamarin.Android
    mPdfViewCtrl.SetClientBackgroundColor(0, 0, 0, false);
    
    // Xamarin.iOS
    mPdfViewCtrl.SetBackgroundColor(0, 0, 0, false);
  4. If you are using postprocess_gradient_map, call PDFViewCtrl.SetColorPostProcessColors to set the white and black points. For example, for a sepia effect, try:

    // Xamarin.Android
    var darkBrown = Android.Graphics.Color.Rgb(61, 38, 10);
    var lightBrown = Android.Graphics.Color.Rgb(245, 224, 202);
    mPdfViewCtrl.SetColorPostProcessColors(lightBrown, darkBrown);
    
    // Xamarin.iOS
    var darkBrown = new UIKit.UIColor(0.24f, 0.15f, 0.04f, 1.0f);
    var lightBrown = new UIKit.UIColor(0.96f, 0.88f, 0.79f, 1.0f);
    mPdfViewCtrl.SetColorPostProcessColors(lightBrown, darkBrown);
  5. Update PDFViewCtrl to redraw the contents:

    mPdfViewCtrl.Update(true);

    Sample result when using postprocess_gradient_map and a light/dark brown for the white/black color: custom color mode

Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales