Skip to content

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub

Themes & Styles ​

The WebViewer ships with light and dark themes and supports injecting custom CSS. This guide covers setTheme and setCustomStyle.

UI APIs ​

UI.setTheme(value) ​

Set the UI theme.

javascript
UI.setTheme('dark');   // 'light' | 'dark'

The value is case-insensitive; other values are ignored with a warning. The theme is written to the data-theme attribute of the UI root element, and UI.Events.THEME_CHANGED fires with the new theme. The theme can also be set at load time with the theme option of ComPDFKitViewer().

UI.setCustomStyle(cssText) ​

Inject a CSS string into the UI.

javascript
UI.setCustomStyle(`
  [data-element="default-top-header"] { background: #1e1e2e !important; }
  [data-element="searchPanelToggle"]:hover { opacity: 0.8; }
`);

Each call adds a new <style> element to the UI of this instance; it does not touch the host page. The styles are removed when the instance is disposed. Use it for style overrides that the theme does not expose.

Built-in themes ​

ThemeDescription
lightDefault light theme.
darkDark theme.

UI.Theme provides the constants LIGHT and DARK. The users can also switch the theme in the main menu (lightThemeButton, darkThemeButton).

Loading-time theme & CSS ​

You can set the theme and inject a stylesheet before the UI renders, with the options of ComPDFKitViewer():

javascript
import ComPDFKitViewer from "@compdfkit_pdf_sdk/webviewer";

const viewer = document.getElementById('webviewer');

ComPDFKitViewer({
  path: '/',
  initialDoc: 'Your PDF Url',
  licenseKey: 'Input your license here',
  theme: 'dark',                       // initial theme
  css: '/styles/my-overrides.css',     // injects a <link rel="stylesheet">
}, viewer);

The css option injects a stylesheet into the UI; theme sets the initial theme. showToolbarControl: false hides the header.

Examples ​

Toggle theme on a button ​

javascript
let dark = false;
const header = UI.getModularHeader('default-top-header');
header.setItems([
  ...header.getItems(),
  new UI.Components.CustomButton({
    dataElement: 'themeToggle',
    label: 'Theme',
    onClick: () => {
      dark = !dark;
      UI.setTheme(dark ? 'dark' : 'light');
    },
  }),
]);

Change the panel width ​

javascript
UI.setPanelWidth('stylePanel', 320);
UI.setPanelWidth('tabPanel', 300);