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

Place image in a background page #1047

Closed
gbgssoftware opened this issue Dec 5, 2023 · 8 comments
Closed

Place image in a background page #1047

gbgssoftware opened this issue Dec 5, 2023 · 8 comments

Comments

@gbgssoftware
Copy link

gbgssoftware commented Dec 5, 2023

Greetings,
I create a PDF with custom dimensions.
Inside the page add an image (svg) of the same size as the PDF page.
The PDF page does not size correctly. The image is resized and positioned in the center.

Minimal code

from fpdf import FPDF

image_path = '../t1.svg'
margin_top, margin_left, margin_right = (0, 0, 0)
pdf = FPDF(unit='mm')
pdf.set_margins(margin_left, margin_top, margin_right)
pdf.set_font('Helvetica', style='B', size=10)

pdf.add_page(format=(120,153))
pdf.image(image_path,  x=0, y=0, w=120, h=153)
pdf.output("target.pdf")

Environment

What can I do?
Thanks

@Lucas-C
Copy link
Member

Lucas-C commented Dec 5, 2023

Hi @gbgssoftware

You did not provide the t1.svg vector image you used in your sample code.
As a consequence, I cannot reproduce the problem that you are having, I'm sorry.

@gbgssoftware
Copy link
Author

You are right :-)
t1

@Lucas-C
Copy link
Member

Lucas-C commented Dec 6, 2023

Are you aware that this has already been reported ?
cf. #1036

Where is this image coming from?

@gmischler
Copy link
Collaborator

Are you aware that this has already been reported ?

Umm... Those are two different issues (lack of <style> support vs. positioning) submitted by the same user... 😉

@gbgssoftware
Copy link
Author

Since they are two different problems, I thought it was correct to open two issues
In this svg file, there are no css styles

@Lucas-C
Copy link
Member

Lucas-C commented Dec 7, 2023

Since they are two different problems, I thought it was correct to open two issues
In this svg file, there are no css styles

You are right, sorry.
The two images looked visually identical, but they are indeed different. My mistake 😅

However, when testing your code, it worked perfectly well using the latest version of fpdf2 from this repo master branch:

pip install git+https://github.com/py-pdf/fpdf2.git@master

There is the resulting PDF:
issue_1047.pdf

@Lucas-C
Copy link
Member

Lucas-C commented Dec 8, 2023

We will be releasing a new version of fpdf2 very soon.

Apart from that, is there anything else we can do regarding this @gbgssoftware?

@Lucas-C
Copy link
Member

Lucas-C commented Dec 10, 2023

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

3 participants