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

Is it possible to represent text inside a "box" in a specific position? #580

Closed
TeoColuccio opened this issue Oct 13, 2022 · 6 comments
Closed
Labels

Comments

@TeoColuccio
Copy link

The most suitable function seems to be .multi_cell(), but with this I can't set the coordinates on the y axis.
In fact I'm trying to set the "h" parameter, but this goes to set the height of the single cell (hence also the distance between them), and not where the text is to be printed.

@Lucas-C
Copy link
Member

Lucas-C commented Oct 13, 2022

Hi @TeoColuccio!
Could you provide some minimal code describing what you are trying to achieve?
Maybe your problem is similar to issue #210?

@TeoColuccio
Copy link
Author

TeoColuccio commented Oct 13, 2022

Hi @Lucas-C,
Basically, what I would like to be able to do is insert a text box in a sheet position that I specify. As in this example created manually:
es

@TeoColuccio
Copy link
Author

TeoColuccio commented Oct 14, 2022

Ok,

txt = """ 
Laborum ut aute occaecat laboris cupidatat sit. Cupidatat irure excepteur id labore sunt velit. Laborum in sit pariatur aliqua enim dolore sint nostrud eiusmod ex sunt elit. Enim ipsum sint reprehenderit laboris incididunt consequat amet ullamco laborum cillum nulla elit esse.

Sint occaecat aliqua do irure cupidatat et excepteur. Sint nisi do in ipsum irure. Elit sit quis enim commodo aliquip laborum ex pariatur elit anim id velit anim. Exercitation veniam id irure enim dolore ad enim elit. Non in est est excepteur.
"""

pdf.set_x(100)
pdf.set_y(100) 

print(pdf.get_x(), pdf.get_y())
pdf.multi_cell(w=x2-x1, 
               txt=txt)

Now the problem is that the .set_x () doesn't seem to work. Whatever value I enter, when I call get_x (), it always returns 9.999999999999998. Maybe it's a bug !?

Update: I think it is a bug, because set_xy() works fine and it was just what I was looking for.

@gmischler
Copy link
Collaborator

Maybe it's a bug !?

No, it's working perfectly just as designed and documented.
While you were looking the other way, this happened (the very first sentence):

set_y(y)

Moves the current abscissa back to the left margin and sets the ordinate.
If the value provided is negative, it is relative to the bottom of the page.
Args

y : float
    the new current ordinate 

This behaviour may be somewhat surprising given the method name, but it has historical reasons and can't easily be changed without breaking a lot of existing code.
So either you need to switch the order of your .set_x() and .set_y() calls, or indeed use .set_xy(), which internally does exactly that.

@TeoColuccio
Copy link
Author

Maybe it's a bug !?

No, it's working perfectly just as designed and documented. While you were looking the other way, this happened (the very first sentence):

set_y(y)

Moves the current abscissa back to the left margin and sets the ordinate.
If the value provided is negative, it is relative to the bottom of the page.
Args

y : float
    the new current ordinate 

This behaviour may be somewhat surprising given the method name, but it has historical reasons and can't easily be changed without breaking a lot of existing code. So either you need to switch the order of your .set_x() and .set_y() calls, or indeed use .set_xy(), which internally does exactly that.

Ok I understand. But in fact set_xy () works perfectly and so I can also close the issue.

@Lucas-C
Copy link
Member

Lucas-C commented Oct 14, 2022

Great!
Thank you for your help @gmischler 😊

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

No branches or pull requests

3 participants