Adding these lines seems to fix the code for me:

    
const bytes  = new Uint8Array( pdfBytes ); 
const blob   = new Blob( [ bytes ], { type: "application/pdf" } );
const docUrl = URL.createObjectURL( blob );
setPdfInfo( docUrl );

Or use it directly:

return <iframe src={docUrl} type="application/pdf" />
Answer from Saed Jaber on Stack Overflow
🌐
npm
npmjs.com › package › pdf-lib
pdf-lib - npm
react-native-pdf-lib is a PDF generation and modification library for React Native environments.
      » npm install pdf-lib
    
Published   Nov 06, 2021
Version   1.17.1
Author   Andrew Dillon
🌐
PDF-LIB
pdf-lib.js.org
PDF-LIB · Create and modify PDF documents in any ...
Works in any JavaScript runtime, including browsers, Node, Deno, and even React Native. Add, insert, and remove pages. Split a single PDF into separate ones. Or merge multiple PDFs into a single document.
🌐
React-pdf
react-pdf.org
React-pdf
React renderer for creating PDF files on the browser and server

Adding these lines seems to fix the code for me:

    
const bytes  = new Uint8Array( pdfBytes ); 
const blob   = new Blob( [ bytes ], { type: "application/pdf" } );
const docUrl = URL.createObjectURL( blob );
setPdfInfo( docUrl );

Or use it directly:

return <iframe src={docUrl} type="application/pdf" />
Answer from Saed Jaber on Stack Overflow
🌐
Mozilla
mozilla.github.io › pdf.js
PDF.js - Home
A general-purpose, web standards-based platform for parsing and rendering PDFs.
🌐
GitHub
github.com › Hopding › react-native-pdf-lib
GitHub - Hopding/react-native-pdf-lib: Library for creating and editing PDFs in React Native.
This library's purpose is to fill the gap that currently exists in the React Native ecosystem for PDF creation and editing. It aims to provide an easy, simple, and consistent API for both creating new and editing existing PDF documents in React ...
Starred by 200 users
Forked by 78 users
Languages   C 75.5% | C++ 22.6% | Objective-C++ 0.9% | Java 0.7% | JavaScript 0.3% | Ruby 0.0%
Find elsewhere
🌐
LogRocket
blog.logrocket.com › home › managing pdfs in node with pdf-lib
Managing PDFs in Node with pdf-lib - LogRocket Blog
June 4, 2024 - pdf-lib is a third-party package that runs in Node.js, Deno, React Native, and the browser.
🌐
Honeybadger
honeybadger.io › blog › pdf-node
Managing PDFs in Node.js with pdf-lib - Honeybadger Developer Blog
November 16, 2023 - As your PDF manipulation needs evolve, you'll often find yourself needing to modify existing PDF documents. pdf-lib offers a versatile set of tools to help you efficiently make changes to PDFs. In this section, we'll dive into more detail about how to load, edit, and save modifications to existing PDFs using pdf-lib. Before you can modify an existing PDF, you need to load it into a PDFDocument instance.
🌐
GitHub
github.com › Shogobg › rn-pdf-lib
GitHub - Shogobg/rn-pdf-lib: Library for creating and editing PDFs in React Native.
Library for creating and editing PDFs in React Native. - Shogobg/rn-pdf-lib
Starred by 10 users
Forked by 2 users
Languages   C 75.4% | C++ 22.6% | Objective-C++ 0.9% | Java 0.8% | JavaScript 0.3% | Ruby 0.0%
🌐
npm
npmjs.com › package › react-pdf
react-pdf - npm
October 9, 2025 - 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
🌐
Medium
medium.com › developers-keep-learning › how-to-create-and-modify-pdf-files-with-pdf-lib-15787083ff2c
How to Create and Modify PDF Files With pdf-lib | by Atakan Demircioğlu | Developers Keep Learning | Medium
August 22, 2024 - How to Create and Modify PDF Files With pdf-lib In this post, we will cover how to modify an existing PDF using JavaScript with PDF-lib. Specifically, we’ll generate a QR code and insert it into a …
🌐
JSFiddle
jsfiddle.net › Hopding › vcwmfnbe › 2
Set Document Metadata (pdf-lib) - JSFiddle - Code Playground
JSFiddle - Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle.
🌐
Nutrient
nutrient.io › blog › sdk › top js pdf libraries
Top JavaScript PDF generator libraries for 2025
June 24, 2025 - How to export to PDF using React · PDF-lib(opens in a new tab) is a versatile JavaScript library for creating and manipulating PDF documents in both browser and Node.js environments.
🌐
Nutrient
nutrient.io › blog › sdk › how to build a javascript pdf editor
JavaScript PDF editor tutorial using pdf‑lib
November 4, 2024 - pdf-lib(opens in a new tab) is a versatile JavaScript library for creating and modifying PDF documents in any JavaScript environment, including browsers, Node.js, Deno, and React Native.
🌐
Stack Overflow
stackoverflow.com › questions › tagged › pdf-lib.js
Highest scored 'pdf-lib.js' questions - Stack Overflow
I am trying to add links to a PDF document using the pdf-lib JavaScript library. When I open the PDF in a browser and click on a link, it opens the website, but it does so in the same browser tab.
🌐
CloudDefense.ai
clouddefense.ai › code › javascript › example › pdf-lib
Top 10 Examples of pdf-lib code in Javascript
Since this is a Node script, we can just // save the `pdfBytes` to the file system, where it can be opened with a PDF // reader. const filePath = `${__dirname}/modified.pdf`; fs.writeFileSync(filePath, pdfBytes); console.log(`PDF file written to: ${filePath}`); ... // JavaScript runtime (e.g. ...
🌐
React PDF
blog.react-pdf.dev › 6-open-source-pdf-generation-and-modification-libraries-every-react-dev-should-know-in-2025
Top 6 Open-Source PDF Libraries for React Developers
September 2, 2025 - This post spotlights six open-source libraries, proven to work well with React projects, ensuring your next build is developer-friendly and dynamic.
🌐
Form.io
mindbowser.com › home › blogs › unlocking the potential of pdfs: a guide to pdf-lib.js
Unlocking the Potential of PDFs: A Guide to PDF-lib.js
July 10, 2023 - Discover PDF-lib.js, a versatile JavaScript library that empowers developers to create, modify, and manipulate PDF documents effortlessly.
🌐
Bundlephobia
bundlephobia.com › package › pdf-lib
pdf-lib ❘ Bundlephobia
Find the size of javascript package pdf-lib. Bundlephobia helps you find the performance impact of npm packages.