RPHorizontalBar Beta
The RPHorizontalBar
display the default group icons of the horizontal bar with an arranged layout by horizontal and responsive behavior, allowing customization of icons and slots.
Name | Type | Description |
---|---|---|
icons | RPHorizontalBarIcons | Provide properties of the horizontal bar default tool icons |
slots | RPHorizontalBarSlots | Provide properties of the horizontal bar default tool slots |
RPHorizontalBarIcons
Section titled “RPHorizontalBarIcons”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 |
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 |
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 |
Change the icon of any tool
Section titled “Change the icon of any tool”import { RPConfig, RPProvider, RPLayout, RPPages, RPHorizontalBar } from '@pdf-viewer/react'
const HeartIcon = ( <svg width="24" height="24" viewBox="0 0 24 24" fill="red" xmlns="http://www.w3.org/2000/svg"> <path d="M12 21s-6-4.35-9-7.69C-1 8.07 3.6 2.6 8.44 6.24L12 9l3.56-2.76C20.4 2.6 25 8.07 21 13.31 18 16.65 12 21 12 21z" /> </svg>)
const AppPdfViewer = () => { return ( <RPConfig licenseKey="YOUR_LICENSE_KEY"> <RPProvider src="https://cdn.codewithmosh.com/image/upload/v1721763853/guides/web-roadmap.pdf"> <RPLayout toolbar={{ topbar: { component: ( <RPHorizontalBar // Change icon icons={{ searchIcon: HeartIcon, downloadIcon: HeartIcon }} /> ) } }} > <RPPages /> </RPLayout> </RPProvider> </RPConfig> )}export default AppPdfViewer
More details for Customize Toolbar (New)
RPHorizontalBarSlots
Section titled “RPHorizontalBarSlots”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 page navigation 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 |
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. |
viewModeTool | boolean | To control the display of the view mode. Set to false to hide the view mode |
zoomTool | boolean | 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
documentProperties
tofalse
within theslots
propExample
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{ documentProperties: false }}/>)}}}>
downloadTool
Section titled “downloadTool”-
To hide the file download button, set
downloadTool
tofalse
within theslots
propExample
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{ downloadTool: false }}/>)}}}> -
To use a custom file download component, define
downloadTool
as a function component in theslots
. This example adds a confirmation flow before initiating the download process.Example
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{downloadTool: ({ download }) => (<divonClick={() => {// Show a confirm alert before downloadingif (confirm('confirm download')) {download()}}}>Download File</div>)}}/>)}}}>
dropFileZone
Section titled “dropFileZone”- To hide the drop file zone tool, set
dropFileZone
tofalse
within theslots
prop
Example
<RPLayout toolbar={{ topbar: { component: ( <RPHorizontalBar slots={{ dropFileZone: false }} /> ) } }}>
-
To use a custom drop zone component, define
dropFileZone
as a function component in theslots
. This example shows a drop zone component with a custom style.Example
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{dropFileZone: () => {return (<div// Customize styles of the drop zonestyle={{backgroundColor: 'blue',height: '100%',width: '100%',color: 'white',textAlign: 'center'}}><p>Drop Here!</p></div>)}}}/>)}}}>
fullScreenTool
Section titled “fullScreenTool”- To hide the fullscreen tool, set
fullScreenTool
tofalse
within theslots
prop
Example
<RPLayout toolbar={{ topbar: { component: ( <RPHorizontalBar slots={{ fullscreenTool: false }} /> ) } }}>
-
To use a custom fullscreen component, define
fullScreenTool
as 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
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{fullscreenTool: ({ isFullScreen, toggleFullScreen }) => (<div onClick={toggleFullScreen}>{isFullScreen ? '' : 'full screen'}</div>)}}/>)}}}>
jumpNavigationTool
Section titled “jumpNavigationTool”-
To hide the jump to page UI, set
jumpNavigationTool
tofalse
within theslots
propExample
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{ jumpNavigationTool: false }}/>)}}}>
openFileTool
Section titled “openFileTool”-
To hide the open file tool, set
openFileTool
tofalse
within theslots
propExample
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{ openFileTool: false }}/>)}}}> -
To use a custom open file component, define
openFileTool
as a function component in theslots
. This example demonstrates how to implement a custom open file flow.Example
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{openFileTool: ({ openFile }) => {return (<divonClick={() => {// Show a confirm alert before opening a PDFif (confirm('confirm open')) {openFile()}}}>Click to open PDF</div>)}}}/>)}}}>
pageNavigationTool
Section titled “pageNavigationTool”-
To hide the page navigation tool, set
pageNavigationTool
tofalse
within theslots
propExample
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{ pageNavigationTool: false }}/>)}}}> -
To use a custom page navigation component, define
pageNavigationTool
as a function component in theslots
. This example allows user to change the current page.Example
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{pageNavigationTool: ({ total, current, nextPage, prevPage }) => (<div><button onClick={prevPage}> {'<'} </button>{current}/{total}<button onClick={nextPage}> {'>'} </button></div>)}}/>)}}}>
printTool
Section titled “printTool”-
To hide the print tool, set
printTool
tofalse
within theslots
propExample
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{ printTool: false }}/>)}}}> -
To use a custom print component, define
printTool
as a function component in theslots
. This example demonstrates how to implement a custom print flow.Example
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{printTool: ({ print, setOnComplete, setOnError, setOnProgress }) => {const handlePrint = () => {// Set up callback for when printing is completed successfullysetOnComplete(() => {console.log('Print Completed!')})// Set up progress tracking callback to monitor printing progresssetOnProgress((progress) => {console.log('Print progress',progress.percentage,progress.loadedPages)})// Set up error handling callback for printing errorssetOnError((error) => {if (error) {console.log('print error:', error)}})print()}return <div onClick={handlePrint}>print here!</div>}}}/>)}}}>
rotateTool
Section titled “rotateTool”-
To hide the rotate tool, set
rotateTool
tofalse
within theslots
propExample
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{ rotateTool: false }}/>)}}}>
scrollModeTool
Section titled “scrollModeTool”-
To hide the scroll mode tool, set
scrollModeTool
tofalse
within theslots
propExample
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{ scrollModeTool: false }}/>)}}}>
searchTool
Section titled “searchTool”-
To hide the search tool, set
searchTool
tofalse
within theslots
propExample
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{ searchTool: false }}/>)}}}>
selectionModeTool
Section titled “selectionModeTool”- To hide the selection mode tool, set
selectionModeTool
tofalse
within theslots
prop
Example
<RPLayout toolbar={{ topbar: { component: ( <RPHorizontalBar slots={{ selectionModeTool: false }} /> ) } }}>
themeSwitcher
Section titled “themeSwitcher”-
To hide the theme switcher, set
themeSwitcher
tofalse
within theslots
propExample
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{ themeSwitcher: false }}/>)}}}> -
To use a custom theme switcher component, define
themeSwitcher
as a function component in theslots
. This example uses a toggle displaying between a sun or a moon icon depending on the current theme.Example
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{// 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>)}}/>)}}}>
viewModeTool
Section titled “viewModeTool”- To hide the view mode tool, set
viewModeTool
tofalse
within theslots
prop
Example
<RPLayout toolbar={{ topbar: { component: ( <RPHorizontalBar slots={{ viewModeTool: false }} /> ) } }}>
zoomTool
Section titled “zoomTool”-
To hide the zoom tool, set
zoomTool
tofalse
within theslots
propExample
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{ zoomTool: false }}/>)}}}> -
To use a custom zoom tool component, define
zoomTool
as a function component in theslots
. This example allows user to change the PDF page’s scale with input.Example
<RPLayouttoolbar={{topbar: {component: (<RPHorizontalBarslots={{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>)}}/>)}}}>