Search code examples
c#wpfchromiumcefsharp

CefSharp - Hide scrollbar and background


I am trying out cefsharp in a simple WPF test application to view a PDF that is on my local PC.

I am wondering if there is anyway to modify the background and scrollbar of the ChromiumWebBrowser, I removed the toolbar using #toolbar=0 in the file path.

Interface

<Grid >
      <Grid  Margin="10">
          <cef:ChromiumWebBrowser Name="pdfBrowser" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></cef:ChromiumWebBrowser>
      </Grid>
  </Grid> 

Codebehind

public MainWindow()
 {
     InitializeComponent();

 
     pdfBrowser.Address = "C:\\Users\\User\\Desktop\\USA-Pickleball-Official-Rulebook-2024-v1.pdf#toolbar=0";
 }

Solution

  • Google Chromium based viewers come in many flavours, Here is one newer Chrome floating variant where scrollbar is a spigot slider and contrasting blackground is dark. This is similar to current Chrome Web browser styling.

    enter image description here

    PDF viewers tend not to expose components that are Part of System interface and traditionally Windows Scrollbars along with TitleBar were considered only the domain of the OS for "Theming" via SystemColours.

    The background is changeable via a PDF viewers options or code variables and supposedly the related UI Control element was BackColor, but I suspect that only affects the surround. The related historic question for the background is covered here Is there a way to style Google Chrome default PDF viewer.

    There are 3rd party tools that can attempt to change scrollbars but rarely the PDF viewer backdrop.

    However CEF can use an easier to customise PDf.js base code https://github.com/cefsharp/CefSharp/wiki/Embedding-PDF.JS-in-CEFSharp