![]() |
VOOZH | about |
Zooming in or out in React-PDF within a React JS application is achieved by using the 'scale' prop inside the `<Page />` component. The 'scale' prop accepts decimal values; values greater than 1 zoom in, while values less than 1 zoom out the page.
Syntax:
<page scale = {value} />
// When we want to pass an integer value to scale.
<Page width={900} scale={30.0} className="page" pageNumber={1} />
This React code utilizes the 'react-pdf' library to render a PDF file ('sample.pdf'). The App component includes a Document component with a specified PDF file, and within it, a Page component renders the first page with a scale of 2.0.
Step 1: Create a React application using the following command:
npx create-react-app pdfappStep 2: After creating your project folder i.e. pdfapp, move to it using the following command:
cd pdfappStep 3: After creating the React JS application, Install the required module using the following command:
npm install react-pdfProject Structure:
The updated dependencies in package.json file will look like:
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-pdf": "^7.6.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4",
}Example: Now write down the following code in the App.js file.
Step to Run Application: Run the application using the following command from the root directory of the project:
npm startOutput: Now open your browser and go to http://localhost:3000