How can I render QR Code on a PDF?
See original GitHub issueI need to render a QR code on a PDF which my end-user can download. FOr creating the pdf I am using react-pdf/renderer
.
Here is my code -
import React from "react";
import {Page, Text, View, Document, StyleSheet, Image} from "@react-pdf/renderer";
import { QRCode } from "react-qr-svg";
export function PdfDocument(props) {
return (
<Document>
<Page size="A4">
<View>
<Text>Section #1</Text>
</View>
<View>
<Text>Section #2</Text>
<QRCode
bgColor="#FFFFFF"
fgColor="#000000"
level="Q"
style={{ width: 256 }}
value="some text"
/>
</View>
</Page>
</Document>
);
}
The above gives me the following error -
Error: Invalid element of type rect passed to PDF renderer
What I am doing wrong? How can I render a QR code on the fly onto a PDF?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top Results From Across the Web
Use QR Code Generator for PDF
Sign up to QR Code Generator PRO. · To create a PDF QR Code, select Create QR Code on the Dashboard and choose...
Read more >How to convert a PDF file to a QR code - Adobe
How to turn a PDF into a QR code. ... First, you will need a PDF file to share. If you only have...
Read more >QR code for PDF. Convert your files into QR - ME-QR
Generating QR code PDF is a process in a few simple steps. • To create a QR code you need to select the...
Read more >Convert your PDF to a QR Code - Easy. Reliable. Secure
1. Log in to the dashboard, go to 'QR Codes', and click '+Create QR Code'. 2. Choose 'PDF' from the list of campaign...
Read more >How to Make a QR Code in PDF - CraftMyPDF.com
CraftMyPDF brings in an easy-to-use drag & drop template editor which lets you create quick QR PDFs that support embedding dynamic QRCode in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
HI @ChengLam123
I solved it, but I guess there is no native way to solve it. I kind of did a dirty hack.
I laid out the HTML code and used a Qr Code generator (like this one), to render a QRcode in the HTML itself. Later, I converted the HTML to pdf.
Also here: https://github.com/magicismight/react-native-svg-example/blob/master/examples/Svg.js#L153-L185