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

Allow / Enable presentation hints #38

Open
jm-lamotte opened this issue Apr 5, 2022 · 3 comments
Open

Allow / Enable presentation hints #38

jm-lamotte opened this issue Apr 5, 2022 · 3 comments

Comments

@jm-lamotte
Copy link

Hello,
Thanks for the code, it allowed me to very quickly render PDF in Django.
One thing I could not do with your latest release is to resize images in a PDF. I looked around, and found the presentation_hints parameter that can be passed in the "HTML" or "write_pdf". I updated the last lines of renders.py file from

html = select_template(template).render(context)
HTML(string=html, base_url="not-used://", url_fetcher=url_fetcher,).write_pdf(
    target=file_,
)

to

html = select_template(template).render(context)
HTML(string=html, base_url="not-used://", url_fetcher=url_fetcher,).write_pdf(
    target=file_, presentation_hints = True,
) 

And now I can use width / height to resize the images that are included in my template.

I'll leave it to you to update or add another setting somewhere to allow this.

Thanks again.

@WhyNotHugo
Copy link
Owner

I don't see the presentation_hints argument in the weasyprint docs. Is this still required, or is it fixed?

Usually, setting the image via width="X" or via CSS should work fine, did that not work for you?

@jm-lamotte
Copy link
Author

Hello, thanks for the feedback.
It is actually presentationAL_hints (https://doc.courtbouillon.org/weasyprint/stable/api_reference.html).

My html file had the width setting on the images, but when rendering the PDF, it would not work (images were the original size, and out of bounds). So I found this setting, and changed my "renders.py" file.
This https://stackoverflow.com/questions/48988707/pdf-output-using-weasyprint-not-showing-images-django allowed me to find the setting to add.

So I'm good with my edit to the code, only have to remember this if I upgrade django-renderpdf.
Up to you to add a setting in renderpdf to activate presentational_hints in weasyprint.

Thanks again.

@WhyNotHugo
Copy link
Owner

So without presentation_hints = True images ignore the width= attribute?

Lemme experiment with this a bit, but it seems like an addition that would make sense. Though I think I have some logos in some documents where I specify the size and it works, so want to double check what's up there.

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

No branches or pull requests

2 participants