Some test text!
Android / Guides
There are a few themes which can be adjusted to change the output 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.
To set the color mode:
Find the constant value of the color mode
Color mode | Constant value |
---|---|
Normal color mode | PDFRasterizer.e_postprocess_none |
Night mode | PDFRasterizer.e_postprocess_night_mode |
Inverted color mode | PDFRasterizer.e_postprocess_invert |
Custom color mode | PDFRasterizer.e_postprocess_gradient_map |
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);
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);
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:
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
mPdfViewCtrl.setColorPostProcessMode(PDFRasterizer.e_postprocess_gradient_map);
// Sets client area color to backgroundColor
mPdfViewCtrl.setClientBackgroundColor(Color.red(backgroundColor), Color.green(backgroundColor), Color.blue(backgroundColor), false);
// Sets background color and text color
mPdfViewCtrl.setColorPostProcessColors(backgroundColor, textColor);
// Updates mPdfViewCtrl
mPdfViewCtrl.update(true);
}
Result:
Alternatively, you can also set custom color mode by adding a gradient map image as follows:
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
:
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) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
Set the mappedFile
created above to PDFViewCtrl
by calling PDFViewCtrl.setColorPostProcessMapFile(Filter)
.
if (mappedFile != null) {
try {
pdfViewCtrl.setColorPostProcessMapFile(mappedFile);
} catch (PDFNetException e) {
e.printStackTrace();
}
}
Where pdfViewCtrl
is an instance of PDFViewCtrl
.
Set the color process mode PDFRasterizer.e_postprocess_gradient_map
to pdfViewCtrl
by calling pdfViewCtrl.setColorPostProcessMode(int)
. Then update pdfViewCtrl
:
try {
pdfViewCtrl.setColorPostProcessMode(PDFRasterizer.e_postprocess_gradient_map);
// Sets client area background color to rgb(138, 138, 138)
pdfViewCtrl.setClientBackgroundColor(138, 138, 138, false);
// Updates pdfViewCtrl
pdfViewCtrl.update(true);
} catch (PDFNetException e) {
e.printStackTrace();
}
Result:
Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales