I'm trying to implement a PDF viewer for a Xamarin.Forms WPF application, and I'm using CefSharp to load and render the PDF file. However I've been unable to perform the necessary customizations on the default Chromium PDF Viewer, or PDFium, as far as my research goes.
This is what I need to change, and the image with the corresponding items:
- A - Remove the toolbar.
- B - Customize the scrollbar.
- C - Remove the zoom items.
- D - Change the background color.
I think that the scrollbar I might be able to change on the Xamarin side of things, the other items however, I'm quite sure I'll have to deal with PDFium or Chromium.
When I open a PDF file on Google chrome, I'm able to remove the toolbar and the zoom items using some simple JavaScript. This is the source that I see when I inspect the elements of the PDF viewer on Google Chrome:
Using these JavaScript statements in the Console Window I can remove the toolbar and zoom items (but only within Google Chrome:
Remover toolbar:
document.getElementById("toolbar").remove()
Remove zoom items:
document.getElementById("zoom-toolbar").remove()
This is the custom implementation of the CefSharp RenderProcessMessageHandler
that I created in order to try to get to the source and run these JavaScript instructions and customize the control as I've been able to do within the Google Chrome browser:
class PdfRenderProcessMessageHandler : IRenderProcessMessageHandler
{
// <other methods required by the interface>
// Method called when the context is created
public void OnContextCreated(IWebBrowser browserControl, IBrowser browser, IFrame frame)
{
frame.ExecuteJavaScriptAsync("document.getElementById('toolbar').remove()");
frame.ExecuteJavaScriptAsync("document.getElementById('zoom - toolbar').remove()");
frame.ViewSource(); //Display the source code
}
}
However when I call the frame.ViewSoure()
method to view the source code, this is the source code that I get:
So it seems pretty obvious that the code that I have when viewing a PDF file through Google Chrome and the code that I have when viewing the same file through CefSharp ChromiumWebBrowser
it's pretty different.
Am I intercepting the source code at the wrong point, how can I have access to the full source when using CefSharp? Even if I can't change the background color (based on my research), removing the toolbar, zoom items and scrollbar could solve my problem.
Does anyone know how I might be able to achieve this?