Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Templates do not work with images #175

Closed
EmperorArthur opened this issue Jun 24, 2021 · 2 comments
Closed

Bug: Templates do not work with images #175

EmperorArthur opened this issue Jun 24, 2021 · 2 comments

Comments

@EmperorArthur
Copy link

EmperorArthur commented Jun 24, 2021

When attempting to use templates to arrange QR codes, I found that it produces an error.

The error may occur in the render call, but the issue is with the assignment. The fact the data is stored in pdf.texts gives a hint to the problem, which is Template.__setitem__ always calls str(value).

Example Code:

import qrcode
from fpdf import Template
barcode_page_elements = [
            {
                "name": "barcode_0",
                "type": "I",
                "x1": 50,
                "y1": 50,
                "x2": 100,
                "y2": 100,
                "priority": 0,
                "text": None,
            },
            {
                "name": "barcode_1",
                "type": "I",
                "x1": 150,
                "y1": 150,
                "x2": 200,
                "y2": 200,
                "priority": 0,
                "text": None,
            }
]
pdf = Template(format="letter", elements=barcode_page_elements)
pdf.add_page()
pdf["barcode_0"] = qrcode.make("Test 0").get_image()
pdf["barcode_1"] = qrcode.make("Test 1").get_image()
pdf.render("out.txt")
@EmperorArthur
Copy link
Author

Note: Given how multi-page works with templates, I would suggest considering marking __setitem__ as deprecated, and adjusting the instructions/examples to directly set the appropriate page within pdf.texts.

Lucas-C added a commit that referenced this issue Jun 25, 2021
@Lucas-C Lucas-C added the bug label Jun 25, 2021
@Lucas-C
Copy link
Member

Lucas-C commented Jun 25, 2021

I have just submitted #177 to solve this issue

Could you please have a look at it @EmperorArthur?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants