Giter Club home page Giter Club logo

Comments (6)

Lucas-C avatar Lucas-C commented on July 18, 2024 1

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.

Lucas-C avatar Lucas-C commented on July 18, 2024 1

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.

Lucas-C avatar Lucas-C commented on July 18, 2024 1

New release: https://github.com/py-pdf/fpdf2/releases/tag/2.7.7

from fpdf2.

Lucas-C avatar Lucas-C commented on July 18, 2024

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.

glebarez avatar glebarez commented on July 18, 2024

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.

glebarez avatar glebarez commented on July 18, 2024

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

Exactly!
Thanks for the hint, the master branch tip works perfectly!

from fpdf2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.