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

Background in Template not working #203

Closed
johann-su opened this issue Aug 21, 2021 · 3 comments
Closed

Background in Template not working #203

johann-su opened this issue Aug 21, 2021 · 3 comments
Assignees

Comments

@johann-su
Copy link

johann-su commented Aug 21, 2021

I am having trouble getting the background on boxes to work when using templates.

There is an open issue in the original repo (#151) and a pull request (#74).

An example for reproduction:

from fpdf import Template

elements = [
    # Paper markings
    { 'name': 'marking_1', 'type': 'B', 'x1': 5, 'y1': 105, 'x2': 10, 'y2': 105.5, 'font': None, 'size': 0.0, 'bold': 0, 'italic': 0, 'underline': 0, 'foreground': 0, 'background': '0x000000', 'align': 'I', 'text': None, 'priority': 1, },
    { 'name': 'marking_2', 'type': 'B', 'x1': 5, 'y1': 148.5, 'x2': 10, 'y2': 149, 'font': None, 'size': 0.0, 'bold': 0, 'italic': 0, 'underline': 0, 'foreground': 0, 'background': '0x000000', 'align': 'I', 'text': None, 'priority': 1, },
    { 'name': 'marking_3', 'type': 'B', 'x1': 5, 'y1': 210, 'x2': 10, 'y2': 210.5, 'font': None, 'size': 0.0, 'bold': 0, 'italic': 0, 'underline': 0, 'foreground': 0, 'background': '0x000000', 'align': 'I', 'text': None, 'priority': 1, },
]

# here we instantiate the template and define the HEADER
f = Template(format="A4", elements=elements,
             title="Sample Invoice")
f.add_page()

# and now we render the page
f.render("./template.pdf")
@alexp1917
Copy link
Collaborator

it would be good to add this and #205 in the same release. The fix for this issue must contain a test though.

I notice there are some code changes which i do not understand. the default value of background can stay as 65535 instead of 0xFFFFFF. but this bit, for instance:

if pdf.text_color!=rgb(foreground):
  pdf.set_text_color(*rgb(foreground))

that avoids un-necessary pdf syntax from being added to the document, so i would try to keep that unless there's a good reason not to.

It seems like the critical places that we want to change the code (and create tests for) are: lines 140, 164, 167, 173, and lines 186-189 seem like they need review as well.

@Lucas-C Lucas-C self-assigned this Aug 24, 2021
@Lucas-C
Copy link
Member

Lucas-C commented Aug 24, 2021

I opened a PR to fix this: #206

@Lucas-C Lucas-C added the bug label Aug 26, 2021
@Lucas-C
Copy link
Member

Lucas-C commented Sep 1, 2021

This has just been released in fpdf2.4.3

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