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

How to print static image as watermark for every page in pdf document #201

Open
eruiz67 opened this issue Feb 22, 2023 · 0 comments
Open

Comments

@eruiz67
Copy link

eruiz67 commented Feb 22, 2023

I need to be able to use a static image as watermark when printing a pdf from a django template. How can I do it using django-wkhtml2pdf?
I was trying using the following code, but the document has several pages and the background does not apply to every page individually. Instead it tries to apply the background to the whole document, and as a result the images takes a bigger size, covering all pages. How can I apply the image as a background to every page individually? Here is my code:

Defining a background using CSS

body { background-image: url("{{ watermark_logos }}"); background-size: cover; }

Generating a pdf with django-wkhtml2pdf. Note that the "cmd_options" represent the parameters for wkhtmltopdf
response = PDFTemplateResponse(request=request,
                                  template=template_to_use,
                                  filename="Ficha proyecto {}.pdf".format(project.get_numero_trabajo),
                                  context= data,
                                  show_content_in_browser=False,
                                  cmd_options={  
                                   'margin-top':0,
                                   'margin-bottom':0,
                                   'margin-left':0,
                                   'margin-right':0,
                                  "zoom":1,
                                  "viewport-size" :"1366x513",
                                  'javascript-delay':1000,
                                  'enable-local-file-access':True,
                                  'footer-center' :'[page]/[topage]',
                                  "no-stop-slow-scripts":True},
                                  )

Here is the watermark I want to use for every page

MARCA-DE-AGUA-SIN-LOGOS-02

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

1 participant