Do you have an issue with a specific file(s)? No all files.
Can you reproduce using one of our samples or online demos? No
Are you using the WebViewer server? No
Does the issue only happen on certain browsers? No
Is your issue related to a front-end framework? Yes
Is your issue related to annotations? No
I am trying to use this API so that i can change the background color of the file being viewed in pdftron. I want to change the file background color to black.
Webviewer({}, document.getElementById('viewer')).then(instance => {
const { docViewer } = instance;
docViewer.on('documentLoaded', () => {
// wait till after the document is loaded and upset the rasterizer option
// Default value is 0 for null. "1" is for inverting the colors
docViewer.getDocument().updateRasterizerOptions({ colorPostProcessMode: 1 });
});
});
Please let me know if this works for you or if you have any other questions
Best Regards,
Andrew Yip
Software Developer
PDFTron Systems, Inc. www.pdftron.com
Thanks for the quick response.
I have tried this solution but now my file by default is launched in an inverted view which is not the expectation.
I have added three options in the viewer to change the background color to either Black, Gray and White and the expectation is to change the background color on selecting the page view options.
Currently, i am using below API to change the background colors.
This works for white and gray but the view is not consistent when changed to black as the text does not get inverted. User will use this extensively for vector file types and the expectation is that color in files should not affected.
Also, when will the documentLoaded event is fired? i want to change the background color once the document is fully loaded.
Thanks for helping, please let me know your comments.
The “setDefaultPageColor” API set the “background-color” of each page element, it doesn’t change any of the content on the page besides the background color. This works, but could be problematic if you have content that matches the background color (why inverting the color to set background to black might be a good idea if possible).
The “documentLoaded” event is fired when WebViewer has enough of the document data to start displaying the document. For large files, WebViewer will try to stream the document, in this case the event will trigger when there is enough data to render the document but the document wouldn’t be fully loaded yet. You can use the “useDownloader” option to wait for the document is fully loaded before doing anything
Best Regards,
Andrew Yip
Software Developer
PDFTron Systems, Inc. www.pdftron.com
Below is my code to set the background color when viewing files.
case BACKGROUND_COLOR_WHITE:
this.pdftron.Core.documentViewer.setDefaultPageColor(‘white’);
this.pdftron.Core.documentViewer.refreshAll();
this.pdftron.Core.documentViewer.updateView();
break;
case BACKGROUND_COLOR_GRAY:
this.pdftron.Core.documentViewer.setDefaultPageColor(‘gray’);
this.pdftron.Core.documentViewer.refreshAll();
this.pdftron.Core.documentViewer.updateView();
break;
case BACKGROUND_COLOR_BLACK:
this.pdftron.Core.documentViewer.setDefaultPageColor(‘black’);
this.pdftron.Core.documentViewer.refreshAll();
this.pdftron.Core.documentViewer.updateView();
break;
When setting the color to black the text color doesn’t get inverted to white and is not readable. How should i fix this? I tried below code but this inverts complete file so if a text is in green color than on changing the bg color to black than the text is shown in red which is not expected. Also, any image in the file should not get inverted.