Skip to Content
Menu
This question has been flagged
1 Reply
13221 Views

Hello everyone,

In Odoo v 11.0, I'd like to print pdf watermark like the module report_qweb_pdf_watermark (odoo 10.0) , so I override  the report_qweb_pdf() method this is a part of the code:

res = super(IrActionsReport, self).render_qweb_pdf(docids, data=data)
....................................................................

for page in PdfFileReader(BytesIO(res)).pages:

watermark_page = pdf.addBlankPage(page.mediaBox.getWidth(), page.mediaBox.getHeight())

watermark_page.mergePage(pdf_watermark.getPage(0))

watermark_page.mergePage(page)

pdf_content = BytesIO()

pdf.write(pdf_content)



Then When I try to print the report I get this error:

for page in PdfFileReader(BytesIO(res)).pages:
TypeError: a bytes-like object is required, not 'tuple'

Can youl help me to solve this isuue?
Avatar
Discard
Best Answer

Method render_qweb_pdf returns tuple (pdf_content, 'pdf'), res[0] is expected content.

Avatar
Discard
Author

Hi,

When I put res[0], I get this error:

Traceback (most recent call last):

File "/home/odoo11/odoo-dev/odoo/addons/web/controllers/main.py", line 1639, in report_download

response = self.report_routes(reportname, docids=docids, converter='pdf')

File "/home/odoo11/odoo-dev/odoo/odoo/http.py", line 512, in response_wrap

response = f(*args, **kw)

File "/home/odoo11/odoo-dev/odoo/addons/web/controllers/main.py", line 1589, in report_routes

pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))]

TypeError: object of type 'int' has no len()

I do not know all your code. You probably have another mistake.

In your examples, you enter:

for page in PdfFileReader(BytesIO(result)).pages

in another row:

for page in PdfFileReader(BytesIO(res)).pages:

result or res in your code?

Author

It res, it's just mistake when typing.

Look for a bug in other place.

PS. In odoo 11 is predefined PDF layout with backgroud, see external_layout_background - Document Template in General menu settings

Author

Thanks,

But in the settings you can' upload your own watermark pdf, just select a template