This document provides examples of how to use the Custom CSS feature to customize the appearance of the PDF viewer beyond the built-in theme options.
- Getting Started
- Simple Examples
- Intermediate Examples
- Advanced Examples
- Common Selectors
- Tips and Best Practices
- Open your ng2-pdfjs-viewer application
- Navigate to Individual Properties β Theme & Visual Customization β Custom CSS
- Enter your CSS code in the text area
- Changes apply immediately
- Always use
!importantto override PDF.js default styles - Test changes incrementally
- Use browser DevTools (F12) to inspect elements and test CSS
.page {
border: 3px solid #ff6b6b !important;
border-radius: 8px !important;
}#toolbarContainer {
background-color: #3498db !important;
color: white !important;
}.toolbarButton {
background-color: #e74c3c !important;
color: white !important;
border-radius: 4px !important;
}.page {
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3) !important;
}#sidebarContainer {
background-color: #2c3e50 !important;
color: #ecf0f1 !important;
}#toolbarContainer {
background: linear-gradient(45deg, #ff6b6b, #4ecdc4) !important;
border-radius: 10px !important;
margin: 5px !important;
}
.toolbarButton {
color: white !important;
font-weight: bold !important;
}.toolbarButton {
background-color: #3498db !important;
color: white !important;
border-radius: 8px !important;
margin: 2px !important;
transition: all 0.3s ease !important;
}
.toolbarButton:hover {
background-color: #2980b9 !important;
transform: scale(1.05) !important;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2) !important;
}.toolbarField {
background: #3498db !important;
color: white !important;
border: 2px solid #2980b9 !important;
border-radius: 20px !important;
padding: 5px 10px !important;
}
.toolbarField:focus {
background: #2980b9 !important;
box-shadow: 0 0 10px rgba(52, 152, 219, 0.5) !important;
}.page {
transition: all 0.3s ease !important;
cursor: pointer !important;
}
.page:hover {
transform: scale(1.02) !important;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3) !important;
}#secondaryToolbar {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
border-radius: 8px !important;
border: none !important;
}
#secondaryToolbar .toolbarButton {
color: white !important;
border-radius: 6px !important;
}/* Main container */
#viewerContainer {
background: #1a1a1a !important;
color: #ffffff !important;
}
/* PDF pages with invert filter */
.page {
background: #2d2d2d !important;
filter: invert(0.9) hue-rotate(180deg) !important;
border: 1px solid #444 !important;
}
/* Toolbar dark styling */
#toolbarContainer {
background: #333333 !important;
color: #ffffff !important;
border-bottom: 1px solid #555 !important;
}
/* Sidebar dark styling */
#sidebarContainer {
background: #2c2c2c !important;
color: #ffffff !important;
}
/* Input fields */
.toolbarField {
background: #444 !important;
color: #fff !important;
border: 1px solid #666 !important;
}/* Webkit scrollbar styling */
#viewerContainer::-webkit-scrollbar {
width: 12px !important;
}
#viewerContainer::-webkit-scrollbar-track {
background: #f1f1f1 !important;
border-radius: 10px !important;
}
#viewerContainer::-webkit-scrollbar-thumb {
background: linear-gradient(45deg, #ff6b6b, #4ecdc4) !important;
border-radius: 10px !important;
}
#viewerContainer::-webkit-scrollbar-thumb:hover {
background: linear-gradient(45deg, #ff5252, #26a69a) !important;
}/* Hide default spinner */
.ng2-pdf-spinner {
opacity: 0 !important;
}
/* Custom loading overlay */
#viewerContainer::before {
content: "" !important;
position: fixed !important;
top: 0 !important;
left: 0 !important;
width: 100% !important;
height: 100% !important;
background: rgba(0, 0, 0, 0.8) !important;
z-index: 1000 !important;
display: flex !important;
align-items: center !important;
justify-content: center !important;
}
#viewerContainer::after {
content: "π Loading PDF..." !important;
position: fixed !important;
top: 50% !important;
left: 50% !important;
transform: translate(-50%, -50%) !important;
color: white !important;
font-size: 24px !important;
z-index: 1001 !important;
animation: pulse 1.5s infinite !important;
}
@keyframes pulse {
0% {
opacity: 1;
transform: translate(-50%, -50%) scale(1);
}
50% {
opacity: 0.5;
transform: translate(-50%, -50%) scale(1.1);
}
100% {
opacity: 1;
transform: translate(-50%, -50%) scale(1);
}
}#toolbarContainer {
background: rgba(255, 255, 255, 0.1) !important;
backdrop-filter: blur(10px) !important;
border: 1px solid rgba(255, 255, 255, 0.2) !important;
border-radius: 15px !important;
margin: 10px !important;
}
.toolbarButton {
background: rgba(255, 255, 255, 0.1) !important;
backdrop-filter: blur(5px) !important;
border: 1px solid rgba(255, 255, 255, 0.2) !important;
border-radius: 8px !important;
color: rgba(0, 0, 0, 0.8) !important;
}
.toolbarButton:hover {
background: rgba(255, 255, 255, 0.2) !important;
transform: translateY(-2px) !important;
}/* Dark background */
#viewerContainer {
background: #0a0a0a !important;
}
/* Neon toolbar */
#toolbarContainer {
background: #1a1a1a !important;
border: 2px solid #00ffff !important;
border-radius: 10px !important;
box-shadow: 0 0 20px #00ffff !important;
}
/* Neon buttons */
.toolbarButton {
background: transparent !important;
color: #00ffff !important;
border: 1px solid #00ffff !important;
border-radius: 5px !important;
text-shadow: 0 0 10px #00ffff !important;
transition: all 0.3s ease !important;
}
.toolbarButton:hover {
background: #00ffff !important;
color: #000 !important;
box-shadow: 0 0 15px #00ffff !important;
}
/* Neon pages */
.page {
border: 1px solid #ff00ff !important;
box-shadow: 0 0 15px #ff00ff !important;
background: #111 !important;
}#viewerContainer- Main PDF viewing area#outerContainer- Outermost container#mainContainer- Main content container
#toolbarContainer- Main toolbar#toolbarViewer- Toolbar viewer section#toolbarViewerLeft- Left toolbar section#toolbarViewerMiddle- Middle toolbar section#toolbarViewerRight- Right toolbar section.toolbarButton- All toolbar buttons.toolbarField- Input fields in toolbar#secondaryToolbar- Secondary (right-click) toolbar
.page- Individual PDF pages.pdfViewer- PDF viewer container.textLayer- Text selection layer.annotationLayer- Annotation layer
#sidebarContainer- Sidebar container#sidebarContent- Sidebar content area#thumbnailView- Thumbnail view#outlineView- Outline/bookmarks view
#zoomIn- Zoom in button#zoomOut- Zoom out button#pageNumber- Page number input#scaleSelect- Zoom level dropdown#sidebarToggle- Sidebar toggle button
PDF.js has high CSS specificity, so you need !important to override:
.toolbarButton {
background: red !important; /* β
Works */
background: red; /* β Might not work */
}Use specific selectors to avoid breaking functionality:
/* β
Good - specific */
#toolbarContainer .toolbarButton {
}
/* β Bad - too broad */
button {
}Start with simple changes and build up:
/* Start with this */
.page {
border: 2px solid red !important;
}
/* Then add more */
.page {
border: 2px solid red !important;
border-radius: 8px !important;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3) !important;
}- Press
F12to open DevTools - Go to Elements tab
- Inspect PDF viewer elements
- Find the right selectors
- Test CSS live before adding to Custom CSS
Avoid expensive CSS operations on frequently changing elements:
/* β Expensive - avoid on scroll elements */
.page {
filter: blur(2px) drop-shadow(0 0 10px red) !important;
}
/* β
Better - simple properties */
.page {
border: 1px solid red !important;
background: #f0f0f0 !important;
}Consider different screen sizes:
/* Desktop styles */
.toolbarButton {
padding: 8px !important;
}
/* Mobile styles */
@media (max-width: 768px) {
.toolbarButton {
padding: 4px !important;
font-size: 12px !important;
}
}Use CSS animations sparingly and make them smooth:
.toolbarButton {
transition: all 0.2s ease !important; /* Keep transitions short */
}
.page {
transition: transform 0.3s ease !important; /* Smooth transforms */
}
/* Avoid animating expensive properties like box-shadow constantly */- Check for typos in selectors
- Add
!importantto your rules - Use more specific selectors
- Check browser console for CSS errors
- Increase CSS specificity
- Use
!important - Check if other custom CSS conflicts
- Avoid complex filters and effects
- Limit animations
- Use simple selectors
- Test with large PDF files
This documentation covers the most common and useful Custom CSS examples for ng2-pdfjs-viewer. Experiment with these examples and combine them to create your unique PDF viewer appearance!