question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I render QR Code on a PDF?

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
iCHAITcommented, Mar 18, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found