-
Notifications
You must be signed in to change notification settings - Fork 251
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
How to put a PNG image into a table, using an IO buffer? #680
Comments
Hi @eabase! There is an example of putting images side by side in a table using Does that help you doing what you want? This project being based on volunteering, if you want you can submit a Pull Request to also add an example in our documentation 😊 |
Hi @Lucas-C
Unfortunately not, as I have no need or intention to use HTML. What I need is a simple example for generating 4-6 columns, in which every other has a QR code, like this:
PS. All QR images are square and of equal size, and possibly with some additional padding between columns, perhaps via an empty column. |
Hi @eabase! Currently, from fpdf import FPDF
pdf = FPDF()
with pdf.table() as table:
table.set_col_widths(...) # optional
with table.row() as row:
row.cell(...) # or row.image(...) For now, we only have a list of useful recipes in our documentation: https://pyfpdf.github.io/fpdf2/Tables.html#recipes You can also easily achieve your goal using from fpdf import FPDF
pdf = FPDF()
pdf.add_page()
IMG_URL = "https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/QR_deWP.svg/270px-QR_deWP.svg.png"
pdf.write_html(f"""
<table>
<thead>
<tr>
<th width="10%">#</th>
<th width="40%">QR</th>
<th width="10%">#</th>
<th width="40%">QR</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><img src="{IMG_URL}"></td>
<td>2</td>
<td><img src="{IMG_URL}"></td>
</tr>
<tr>
<td>55</td>
<td><img src="{IMG_URL}"></td>
<td>404</td>
<td><img src="{IMG_URL}"></td>
</tr>
</tbody>
</table>
""")
pdf.output("issue_680.pdf") Does that answer your initial questions? |
Hi @Lucas-C As for the 2nd option of using HTML, that is an absolute no-go, as I have 100's of rows, and really really don't want to see any HTML, anywhere! 😱 👹 |
@Lucas-C Then, given your sample snippet above, how could I put this to practical use? OMG! I just found PR #703 ❤️ |
Ok, these are really 2 questions:
Using
segno
I can create a PNG IO buffer like this:Your documentation for
image()
say to use:But I am not able to get this to work.
UPDATE
I managed to get the image from the buffer, but I am not able to get the image into a table cell.
The text was updated successfully, but these errors were encountered: