RPDefaultLayout
The RPDefaultLayout component renders the default theme and layout of the React PDF viewer, including the top bar and sidebar.
The RPDefaultLayout component’s default height and width are set to 600px and 100% of the parent’s component respectively which can be overridden via the style prop. The dimensions can be configured with absolute values (e.g., 250px, 550px or 856px) or relative values (e.g., auto, initial or inherit).
Overriding the Component’s Dimensions
Section titled “Overriding the Component’s Dimensions”This example will set the height and width to 100% of the parent’s component and 720px respectively.
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'
// Example of a parent componentconst ParentComponent = ({ children }) => { return <div style={{ height: '500px' }}>{children}</div>}
export const AppPdfViewer = () => { return ( <ParentComponent> <RPConfig licenseKey="YOUR_LICENSE_KEY"> <RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"> <RPDefaultLayout // Override the default height and width style={{ height: '100%', width: '720px' }} icons={{ zoomInIcon: <>Zoom in</>, zoomOutIcon: <>Zoom out</> }} > <RPPages /> </RPDefaultLayout> </RPProvider> </RPConfig> </ParentComponent> )}Additionally, the RPDefaultLayout component also provides customization options for the appearance and functionalities of these UI elements through the use of props.
| Name | Type | Description |
|---|---|---|
| icons | RPIcons | Customize the appearance of toolbar icons by providing your own icon components. See RPIcons for the complete list of customizable icons |
| mobileWidth | number | The default breakpoint for mobile view is 768px, which determines when the component switches to the mobile layout. This value is configurable as needed. For more information, see Mobile View |
| onLayoutWidthChange | (isMobileScreen: boolean, currentWidth: number) => void | Triggered whenever the viewer layout width changes. Provides a flag indicating if the screen is considered mobile and the current width in pixels. Useful for adjusting UI components responsively based on screen size. |
| slots | RPSlots | Customize the viewer’s interface by replacing default components with your own implementations. This includes toolbar buttons, search functionality, page navigation, and other UI elements. See RPSlots for the complete list of customizable slots |
RPIcons
Section titled “RPIcons”| Name | Type | Description |
|---|---|---|
| lightModeIcon | React.ReactNode | To change the light mode icon when the current state of the theme toggle button is light |
| darkModeIcon | React.ReactNode | To change the dark mode icon when the current state of the theme toggle button is dark |
| documentPropertiesIcon | React.ReactNode | To change the icon of the document properties menu |
| downloadIcon | React.ReactNode | To change the icon of the file download button |
| dualPageIcon | React.ReactNode | To change the icon of the dual page view mode menu |
| fullScreenIcon | React.ReactNode | To change the fullscreen icon of the fullscreen button |
| handSelectionIcon | React.ReactNode | To change the icon of the hand selection menu |
| openFileIcon | React.ReactNode | To change the icon of the file upload button |
| nextIcon | React.ReactNode | To change the icon of the next page button |
| pageScrollIcon | React.ReactNode | To change the icon of the page scrolling menu |
| prevIcon | React.ReactNode | To change the icon of the previous page button |
| printIcon | React.ReactNode | To change the icon of the print button |
| rotateClockwiseIcon | React.ReactNode | To change the icon of the rotate clockwise menu |
| rotateCounterClockwiseIcon | React.ReactNode | To change the icon of the rotate counterclockwise menu |
| singlePageIcon | React.ReactNode | To change the icon of the single page view mode menu |
| textSelectionIcon | React.ReactNode | To change the icon of the text selection menu |
| thumbnailIcon | React.ReactNode | To change the icon of the thumbnail button |
| verticalScrollIcon | React.ReactNode | To change the icon of the vertical scrolling menu |
| wrappedScrollIcon | React.ReactNode | To change the icon of the wrapped scrolling menu |
| zoomInIcon | React.ReactNode | To change the zoom in icon of the zoom UI |
| zoomOutIcon | React.ReactNode | To change the zoom out icon of the zoom UI |
Changing of icons in the toolbar
Section titled “Changing of icons in the toolbar”This example can be applied to all icons.
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'
export const AppPdfViewer = () => { return ( <RPConfig licenseKey="YOUR_LICENSE_KEY"> <RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"> <RPDefaultLayout icons={{ zoomInIcon: <>Zoom in</>, zoomOutIcon: <>Zoom out</> }} > <RPPages /> </RPDefaultLayout> </RPProvider> </RPConfig> )}RPSlots
Section titled “RPSlots”| Name | Type | Description |
|---|---|---|
| documentProperties | boolean | To view the PDF metadata such as title, author, and page count. Set to false to hide the document properties menu |
| downloadTool | boolean | FC<DownloadToolProps> | To control the download tool display and customization. Set to false to hide the file download button, or provide a custom React component to replace the default file download button. |
| dropFileZone | boolean | React.ReactNode | React.ComponentType | To customize the display of the drag and drop file zone component. Set to false to hide the drag and drop file zone |
| fullscreenTool | boolean | FC<FullScreenToolProps> | To control the fullscreen tool’s display and customization. Set to false to hide the button or pass a custom React component to replace it. |
| jumpNavigationTool | boolean | To control the display of the jump to page UI. Set to false to hide the jump to page UI |
| openFileTool | boolean | React.FC<OpenFileToolProps> | To control the file upload’s display and customization. Set to false to hide the file upload button or provide a custom React component to replace the default file upload button. |
| pageNavigationTool | boolean | React.FC<PageNavigationToolProps> | To customize the display of the page navigation UI. Set to false to hide the zoom UI |
| printTool | boolean | React.FC<PrintToolProps> | To control the print display and customization. Set to false to hide the print button or provide a custom React component to replace the default print button |
| rotateTool | boolean | To rotate the PDF page clockwise or counterclockwise. Set to false to hide the rotate menu |
| scrollModeTool | boolean | To change the scroll mode (i.e. a single page and two pages side-by-side. Set to false to hide the view mode menu |
| searchTool | boolean | To control the display of the search UI. Set to false to hide the search UI |
| selectionModeTool | boolean | To control the display of the selection mode. Set to false to hide the selection mode |
| sidebarEnable | boolean | To control the display of the sidebar. Set to false to hide the sidebar |
| themeSwitcher | boolean | React.FC<DarkModeProps> | To control the theme switcher display and customization. Set to false to hide the theme switcher button. Alternatively, pass a custom React component (compatible with the DarkMode interface) to replace the default theme switcher button. |
| thumbnailTool | boolean | FC<ThumbnailToolProps> | To customize the display of the thumbnail button. Set to false to hide the thumbnail button |
| viewModeTool | boolean | To control the display of the view mode. Set to false to hide the view mode |
| zoomTool | boolean | React.FC<ZoomProps> | To customize the display of the zoom UI. Set to false to hide the zoom UI |
documentProperties
Section titled “documentProperties”-
To hide the document properties menu, set
documentPropertiestofalsewithin theslotspropExample
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig licenseKey="YOUR_LICENSE_KEY"><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{documentProperties: false}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)}
downloadTool
Section titled “downloadTool”-
To hide the file download button, set
downloadTooltofalsewithin theslotspropExample
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig licenseKey="YOUR_LICENSE_KEY"><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{downloadTool: false}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)} -
To use a custom file download component, define
downloadToolas a function component in theslots. This example adds a confirmation flow before initiating the download process.Example
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig licenseKey="YOUR_LICENSE_KEY"><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{downloadTool: ({ download }) => (<divonClick={() => {// Show a confirm alert before downloadingif (confirm('confirm download')) {download()}}}>Download File</div>)}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)}
dropFileZone
Section titled “dropFileZone”-
To hide the drop file zone tool, set
dropFileZonetofalsewithin theslotspropExample
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig licenseKey="YOUR_LICENSE_KEY"><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{dropFileZone: false}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)} -
To use a custom drop zone component, define
dropFileZoneas a function component in theslots. This example shows a drop zone component with a custom style.Example
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{dropFileZone: () => {return (<div// Customize styles of the drop zonestyle={{backgroundColor: 'blue',height: '100%',width: '100%',color: 'white',textAlign: 'center'}}><p>Drop Here!</p></div>)}}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)}
fullScreenTool
Section titled “fullScreenTool”-
To hide the fullscreen tool, set
fullScreenTooltofalsewithin theslotspropExample
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig licenseKey="YOUR_LICENSE_KEY"><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{fullscreenTool: false}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)} -
To use a custom fullscreen component, define
fullScreenToolas a function component in theslots. This example uses a toggle to display text indicating whether fullscreen mode is active (true) or not (false), instead of an icon.Example
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{fullscreenTool: ({ isFullScreen, toggleFullScreen }) => (<div onClick={toggleFullScreen}>{isFullScreen ? '' : 'full screen'}</div>)}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)}
jumpNavigationTool
Section titled “jumpNavigationTool”-
To hide the jump to page UI, set
jumpNavigationTooltofalsewithin theslotspropExample
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{jumpNavigationTool: false}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)}
openFileTool
Section titled “openFileTool”-
To hide the open file tool, set
openFileTooltofalsewithin theslotspropExample
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{openFileTool: false}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)} -
To use a custom open file component, define
openFileToolas a function component in theslots. This example demonstrates how to implement a custom open file flow.Example
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig licenseKey="YOUR_LICENSE_KEY"><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{openFileTool: ({ openFile }) => {return (<divonClick={() => {// Show a confirm alert before opening a PDFif (confirm('confirm open')) {openFile()}}}>Click to open PDF</div>)}}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)}
pageNavigationTool
Section titled “pageNavigationTool”-
To hide the page navigation tool, set
pageNavigationTooltofalsewithin theslotspropExample
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{pageNavigationTool: false}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)} -
To use a custom page navigation component, define
pageNavigationToolas a function component in theslots. This example allows user to change the current page.Example
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig licenseKey="YOUR_LICENSE_KEY"><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{pageNavigationTool: ({ total, current, nextPage, prevPage }) => (<div><button onClick={prevPage}> {'<'} </button>{current}/{total}<button onClick={nextPage}> {'>'} </button></div>)}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)}
printTool
Section titled “printTool”-
To hide the print tool, set
printTooltofalsewithin theslotspropExample
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig licenseKey="YOUR_LICENSE_KEY"><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{printTool: false}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)} -
To use a custom print component, define
printToolas a function component in theslots. This example demonstrates how to implement a custom print flow.Example
import { useEffect } from 'react'import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig licenseKey="YOUR_LICENSE_KEY"><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{printTool: ({ print, setOnComplete, setOnError, setOnProgress }) => {// Set up callback for when printing is completed successfullyuseEffect(() => {setOnComplete(() => {console.log('Print Completed!')})}, [])// Set up error handling callback for printing errorsuseEffect(() => {setOnError((error) => {if (error) {console.log('print error:', error)}})}, [])// Set up progress tracking callback to monitor printing progressuseEffect(() => {setOnProgress((progress) => {console.log('Print progress', progress.percentage, progress.loadedPages)})}, [])return <div onClick={print}>print here!</div>}}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)}
rotateTool
Section titled “rotateTool”-
To hide the rotate tool, set
rotateTooltofalsewithin theslotspropExample
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{rotateTool: false}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)}
scrollModeTool
Section titled “scrollModeTool”-
To hide the scroll mode tool, set
scrollModeTooltofalsewithin theslotspropExample
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig licenseKey="YOUR_LICENSE_KEY"><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{scrollModeTool: false}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)}
searchTool
Section titled “searchTool”-
To hide the search tool, set
searchTooltofalsewithin theslotspropExample
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig licenseKey="YOUR_LICENSE_KEY"><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{searchTool: false}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)}
selectionModeTool
Section titled “selectionModeTool”-
To hide the selection mode tool, set
selectionModeTooltofalsewithin theslotspropExample
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig licenseKey="YOUR_LICENSE_KEY"><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{selectionModeTool: false}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)}
sidebarEnable
Section titled “sidebarEnable”-
To hide the sidebar, set
sidebarEnabletofalsewithin theslotspropExample
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig licenseKey="YOUR_LICENSE_KEY"><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{sidebarEnable: false}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)}
themeSwitcher
Section titled “themeSwitcher”-
To hide the theme switcher, set
themeSwitchertofalsewithin theslotspropExample
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig licenseKey="YOUR_LICENSE_KEY"><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{themeSwitcher: false}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)} -
To use a custom theme switcher component, define
themeSwitcheras a function component in theslots. This example uses a toggle displaying between a sun or a moon icon depending on the current theme.Example
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig licenseKey="YOUR_LICENSE_KEY"><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{// Render a custom theme switcher and// Handle component click event to change the state of darkModethemeSwitcher: ({ darkMode, setDarkMode }) => (<div onClick={() => setDarkMode((prev) => !prev)}>{darkMode ? '🌙' : '☀️'}</div>)}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)}
thumbnailTool
Section titled “thumbnailTool”-
To hide the thumbnail tool, set
thumbnailTooltofalsewithin theslotspropExample
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{thumbnailTool: false}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)} -
To use a custom thumbnail component, define
thumbnailToolas a function component in theslots. This example uses a toggle to display text indicating whether thumbnail sidebar is opened (true) or not (false), instead of an icon.Example
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{thumbnailTool: ({ onClick, active }) => (<div onClick={onClick}>{active ? 'T' : 't'}</div>)}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)}
viewModeTool
Section titled “viewModeTool”-
To hide the view mode tool, set
viewModeTooltofalsewithin theslotspropExample
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{viewModeTool: false}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)}
zoomTool
Section titled “zoomTool”-
To hide the zoom tool, set
zoomTooltofalsewithin theslotspropExample
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{zoomTool: false}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)} -
To use a custom zoom tool component, define
zoomToolas a function component in theslots. This example allows user to change the PDF page’s scale with input.Example
import { RPProvider, RPDefaultLayout, RPPages, RPConfig } from '@pdf-viewer/react'export const AppPdfViewer = () => {return (<RPConfig licenseKey="YOUR_LICENSE_KEY"><RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"><RPDefaultLayoutslots={{zoomTool: ({ zoomLevel, setZoomLevel }) => (<div><button onClick={() => setZoomLevel(zoomLevel - 20)}>ZoomOut</button><span style={{ marginInline: 10 }}>{zoomLevel}</span><button onClick={() => setZoomLevel(zoomLevel + 20)}>ZoomIn</button></div>)}}><RPPages /></RPDefaultLayout></RPProvider></RPConfig>)}