Comments (6)
Seems like I might have misformulated the issue.
I am looking for a way for SVG to be displayed in original size (e.g. 16x16) no matter what the cell's size is (e.g. prevent stretching in any direction, regardless of cell size)
Is there a way to achieve this ?
Oh, you mean to keep the original aspect ratio?
I think we fixed that recently.
Could you please test if you still get this problem when using the latest version of fpdf2
from this repository master
branch?
pip install git+https://github.com/py-pdf/fpdf2.git@master
from fpdf2.
Exactly!
Thanks for the hint, the master branch tip works perfectly!
Great 🙂
We are planning to perform a new release of fpdf2
shortly
from fpdf2.
New release: https://github.com/py-pdf/fpdf2/releases/tag/2.7.7
from fpdf2.
Hi @glebarez
One way to render images at a bigger size is simply to pass img_fill_width=True
to Row.cell()
:
row.cell(img="check.svg", img_fill_width=True)
Another way can be to extend the row height by introducing more newlines in text cells.
Also, to have full control over the table rendering logic, you could subclass fpdf.table.Table
:
from dataclasses import replace
from fpdf import FPDF
from fpdf.table import Table
MIN_HEIGHT = 50
class TableWithMinRowHeight(Table):
def _render_table_cell(self, *args, cell_height_info=None, **kwargs):
if cell_height_info and cell_height_info.height < MIN_HEIGHT:
cell_height_info = replace(cell_height_info, height=MIN_HEIGHT)
return super()._render_table_cell(*args, cell_height_info=cell_height_info, **kwargs)
pdf = FPDF()
pdf.add_page()
pdf.set_font("helvetica")
table = TableWithMinRowHeight(pdf, first_row_as_headings=False)
row = table.row()
row.cell("some text")
row.cell(img="check.svg")
table.render()
pdf.output("issue_1059.pdf")
And finally, you could make a contribution to fpdf2
, for example to introduce a new optional min_height
parameter to Table.row()
😊
Do you have other questions, or are those information enough to solve your problem?
from fpdf2.
Hello @Lucas-C
Thanks for such a detailed answer!
Seems like I might have misformulated the issue.
I am looking for a way for SVG to be displayed in original size (e.g. 16x16) no matter what the cell's size is (e.g. prevent stretching in any direction, regardless of cell size)
Is there a way to achieve this ?
from fpdf2.
Oh, you mean to keep the original aspect ratio?
I think we fixed that recently. Could you please test if you still get this problem when using the latest version of
fpdf2
from this repositorymaster
branch?pip install git+https://github.com/py-pdf/fpdf2.git@master
Exactly!
Thanks for the hint, the master branch tip works perfectly!
from fpdf2.
Related Issues (20)
- Currently failing unit tests in the GitHub Actions pipeline HOT 5
- Can i change the vertical space between lines inside a table? HOT 8
- Creating Links in Table Cells HOT 10
- adding an SVG image displays a black square HOT 6
- Pillow Import Issue when using custom FPDF2 Layer in AWS Lambda HOT 4
- TypeError: FPDF.set_fill_color() takes from 2 to 4 positional arguments but 5 were given HOT 8
- Place image in a background page HOT 8
- Table header override style is not working HOT 4
- Leading spaces on new lines ignored in <pre><code> tags HOT 7
- Tables with multiple header rows and merging cells HOT 4
- Test failure in test_share_images_cache on fast computers HOT 1
- Expected behaviour re outer table border with nonzero gutter? HOT 5
- Sections must have a style HOT 2
- Long HTML list entries are not correctly indented HOT 24
- HTML blockquotes are not indented HOT 1
- Combination of set_text_shaping and offset_rendering causing error HOT 5
- `KeyError: '{http://www.w3.org/2000/svg}path'` when using an svg HOT 4
- Error when using multi-page tables in table of contents placeholder HOT 5
- Headings and Title styles HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fpdf2.