🌐
React-pdf
react-pdf.org › components
React-pdf
The most fundamental component ... and can have 0 to many children. A React component for displaying network or local (Node only) JPG or PNG images, as well as base64 encoded image strings....
🌐
GitHub
github.com › diegomura › react-pdf › issues › 1736
Image not rendering in react-pdf? · Issue #1736 · diegomura/react-pdf
March 2, 2022 - I am using react-pdf. I write one component Named MyDoc- <Document> <Page size="A4"> <View style={styles.Header}> <Image style={styles.image} src="https://jobsicle.org/images/jobseekers/16462432893850.jpg" cache={false} /> <View style={styles.profileNameContainer}> <Text style={styles.profileName}>Jannat</Text> <View style={styles.profileDivider} /> <Text style={styles.profileJob}>Full Stack Developer</Text> </View> </View> </Page> </Document> Here I am facing problem with rendering image.
Published   Mar 02, 2022
🌐
npm
npmjs.com › package › @react-pdf › image
react-pdf/image
Parses the images in png or jpeg format for react-pdf document. Latest version: 3.0.3, last published: 7 months ago. Start using @react-pdf/image in your project by running `npm i @react-pdf/image`. There are 12 other projects in the npm registry ...
      » npm install @react-pdf/image
    
Published   Mar 03, 2025
Version   3.0.3
Author   Diego Muracciole
🌐
CodeSandbox
codesandbox.io › examples › package › @react-pdf › image
react-pdf/image examples
Use this online @react-pdf/image playground to view and fork @react-pdf/image example apps and templates on CodeSandbox.
🌐
npm
npmjs.com › package › react-pdf
react-pdf - npm
Display PDFs in your React app as easily as if they were images.. Latest version: 10.2.0, last published: 2 months ago. Start using react-pdf in your project by running `npm i react-pdf`. There are 985 other projects in the npm registry using ...
      » npm install react-pdf
    
Published   Oct 09, 2025
Version   10.2.0
Author   Wojciech Maj
🌐
GitHub
github.com › diegomura › react-pdf › issues › 2639
ReactPDF.Image is not rendering some images · Issue #2639 · diegomura/react-pdf
February 14, 2024 - <ReactPDF.Image key={fileId} source={{ uri: '/fae5c83b-431c-44e9-829d-004871a5f32f.jpeg', headers: { Pragma: 'no-cache', 'Cache-Control': 'no-cache' }, method: 'GET', body: undefined, }} style={style.image} /> Expected behavior · Desktop (please complete the following information): OS: MacOS, W · Browser chrome · React-pdf version 3.3.8 ·
Published   Feb 14, 2024
🌐
Stack Overflow
stackoverflow.com › questions › 78587769 › how-to-display-an-image-only-on-the-first-page-using-react-pdf-renderer
reactjs - How to Display an Image Only on the First Page Using @react-pdf/renderer? - Stack Overflow
import { Document, Page, Text, View, StyleSheet, pdf, Image } from '@react-pdf/renderer' import moment from 'moment' import { headerImgPdfQuote } from '../../../Clients/devisTemplate' const styles = StyleSheet.create({ page: { flexDirection: 'column', backgroundColor: '#FFFFFF', padding: '0 40px' }, header: { position: 'absolute', top: 0, left: 0, right: 0 }, headerImage: { width: '100%', height: 'auto' } }) const QuotePDF = () => ( <Document> <Page size="A4" style={styles.page} wrap> <View style={styles.header}> <View render={({ pageNumber }) => ( pageNumber === 1 && ( <Image src={headerImgPd
🌐
CodeSandbox
codesandbox.io › examples › package › react-pdf-to-image
react-pdf-to-image examples - CodeSandbox
Use this online react-pdf-to-image playground to view and fork react-pdf-to-image example apps and templates on CodeSandbox.
Find elsewhere
🌐
npm
npmjs.com › package › react-pdf-to-image
react-pdf-to-image - npm
React Component for transforming pdf files to image data urls. Latest version: 1.0.2, last published: 7 years ago. Start using react-pdf-to-image in your project by running `npm i react-pdf-to-image`. There are no other projects in the npm registry ...
      » npm install react-pdf-to-image
    
Published   Dec 01, 2018
Version   1.0.2
Author   Marc Aaron Glasser
🌐
GitHub
github.com › wojtekmaj › react-pdf
GitHub - wojtekmaj/react-pdf: Display PDFs in your React app as easily as if they were images.
Display PDFs in your React app as easily as if they were images. - wojtekmaj/react-pdf
Starred by 10.7K users
Forked by 981 users
Languages   TypeScript 94.3% | CSS 5.6% | HTML 0.1%
🌐
GitHub
github.com › marcaaron › react-pdf-to-image
GitHub - marcaaron/react-pdf-to-image: Render prop component that turns PDF files into image data URLs
import React from 'react'; import {PDFtoIMG} from 'react-pdf-to-image'; import file from './pdf-sample.pdf'; const App = () => <div> <PDFtoIMG file={file}> {({pages}) => { if (!pages.length) return 'Loading...'; return pages.map((page, index)=> <img key={index} src={page}/> ); }} </PDFtoIMG> </div> export default App;
Starred by 10 users
Forked by 4 users
Languages   JavaScript
🌐
Cloudinary
cloudinary.com › home › convert images to pdf files with react-to-pdf
How to Use the React to PDF Converter for Images
June 8, 2023 - In this article, we looked at the image to PDF React converter that allows you to convert images into a PDF document on the fly using the react-to-pdf library (within the react to pdf converter tool). We rendered a grid of images for our demonstration, which we eventually converted to a PDF document.
🌐
Medium
medium.com › @charanvinaynarni › pdf-to-image-conversion-using-reactjs-fd250a25bf05
PDF to Image conversion using Reactjs | by Charan vinay Narni | Medium
April 16, 2023 - PDF to Image conversion using Reactjs This tutorial will build a PDF-to-image converter using ReactJS. The app will allow users to upload a PDF file and convert it to a series of images, which can …
Top answer
1 of 4
6

I created a helper function: convertPdfToImages which takes in the pdf file and returns an array of images encoded in base64, using the pdfjs package.

npm install pdfjs-dist -S

const PDFJS = require("pdfjs-dist/webpack");

const readFileData = (file) => {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.onload = (e) => {
      resolve(e.target.result);
    };
    reader.onerror = (err) => {
      reject(err);
    };
    reader.readAsDataURL(file);
  });
};

//param: file -> the input file (e.g. event.target.files[0])
//return: images -> an array of images encoded in base64 
const convertPdfToImages = async (file) => {
  const images = [];
  const data = await readFileData(file);
  const pdf = await PDFJS.getDocument(data).promise;
  const canvas = document.createElement("canvas");
  for (let i = 0; i < pdf.numPages; i++) {
    const page = await pdf.getPage(i + 1);
    const viewport = page.getViewport({ scale: 1 });
    const context = canvas.getContext("2d");
    canvas.height = viewport.height;
    canvas.width = viewport.width;
    await page.render({ canvasContext: context, viewport: viewport }).promise;
    images.append(canvas.toDataURL());
  }
  canvas.remove();
  return images;
}
2 of 4
5

Please use this library

https://www.npmjs.com/package/react-pdf-to-image

It is pretty straight forward. It will return the list of images (each page in the pdf as one image)

import React from 'react';
import {PDFtoIMG} from 'react-pdf-to-image';
import file from './pdf-sample.pdf';

const App = () =>
    <div>
        <PDFtoIMG file={file}>
            {({pages}) => {
                if (!pages.length) return 'Loading...';
                return pages.map((page, index)=>
                    <img key={index} src={page}/>
                );
            }}
        </PDFtoIMG>
    </div>

export default App;

if you want to just download the each pdf page as image instead of component please follow below code

import PDFJS from 'pdfjs-dist/webpack';

this is the dependency library for react-pdf-to-image. Then read the pdf file(I'm giving base64 as input)

PDFJS.getDocument(blob).promise.then(pdf => {
     const pages = [];
     this.pdf = pdf;
     for (let i = 0; i < this.pdf.numPages; i++) {
         this.getPage(i + 1).then(result => {
         // the result is the base 64 version of image
     });
   }
})

after reading each page, read each page as image from getPage method as below

getPage = (num) => {
    return new Promise((resolve, reject) => {
        this.pdf.getPage(num).then(page => {
            const scale = "1.5";
            const viewport = page.getViewport({
                scale: scale
            });
            const canvas = document.createElement('canvas');
            const canvasContext = canvas.getContext('2d');
            canvas.height = viewport.height || viewport.viewBox[3]; /* viewport.height is NaN */
            canvas.width = viewport.width || viewport.viewBox[2];  /* viewport.width is also NaN */
            page.render({
                canvasContext, viewport
            }).promise.then((res) => {
                resolve(canvas.toDataURL());
            })
        })
    })
}
🌐
GitHub
github.com › diegomura › react-pdf › issues › 929
Issue rendering images via <Image> component · Issue #929 · diegomura/react-pdf
June 18, 2020 - I have been unable to correctly load images via the component in React PDF. I had issue locally in my code but have also been able to replicate the same issue on the image test page https://react-pdf.org/repl?example=images This works an...
Published   Jun 18, 2020