Commit Graph
12 Commits
Author SHA1 Message Date
Nicolas (vin) 08e9798d74 [FIX] [base, account_edi_facturx]: Fix pdf export
There is an issue when exporting pdf using edi documents created before
the PDF/A commit. With the subtype now included, the system would try
to use the subtype given by the ir.attachment which would not be formated
as expected by the pdf file format.

The attachment may get neutered by the ORM, so we may have to force
the mimetype when embedding it.

This fix in two parts will allow to force a subtype when adding an
attachment into a pdf, as well as parse the subtype of ir.attachment
to give them the right format.

xxx/xxx should become /xxx#2Fxxx

opw-2714040

closes odoo/odoo#81898

X-original-commit: 880d7a1c8474a3bee4fd05474788fbd4a63f4ae7
Signed-off-by: Laurent Smet <las@odoo.com>
2021-12-24 13:11:50 +00:00
Nicolas (vin) 62954aaaf5 [IMP] [base, account_facturx]: Add PDF/A(-3B) support
Improve the factur-x export in two ways: make the exported PDF
PDF/A-3B compliant, and add the factur-x XMP metadata inside the file.

The added .ICC profile comes from https://www.color.org/srgbprofiles.xalter
License terms can be found here: https://www.color.org/profiles2.xalter#license

Task id # 2668919

closes odoo/odoo#80741

X-original-commit: 3a9a685fc360fee7fe10ed7fdb768414697673b2
Signed-off-by: Laurent Smet <las@odoo.com>
2021-12-04 21:45:04 +00:00
wan 2fcfa2cc18 [FIX] tools: support malformed more malformed pdf
We do not want to fail ever if loading the attachment fails.
We still log a warning in every case though.

Some malformed PDFs lead to seeking the wrong bytes while looking for
some parts, raising a ValueError

closes odoo/odoo#68171

X-original-commit: f4cc0579a3e0ee9c117c7dd0f6090edc6e94384d
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
Signed-off-by: William André (wan) <wan@odoo.com>
2021-03-19 19:41:02 +00:00
nie 23233a7051 [FIX] tools: try decrypting PDF with empty password
Steps:
- Install accounting
- On the dashboard, try to upload an "encrypted" PDF like this one https://launchpadlibrarian.net/24827090/DS-0157.pdf

Bug:
Traceback:
PyPDF2.utils.PdfReadError: file has not been decrypted

Explanation:
In 13.0, these errors were caught in a catch all `except` as shown here: https://github.com/odoo/odoo/blob/4e089041252c25cc197a30f9e285d82f7162d809/addons/account_facturx/models/account_move.py#L303-L328

From this SO comment: https://stackoverflow.com/questions/52047944/pdfbox-extracting-blanks-from-pdf-encrypted-with-no-password#comment91054285_52047944

> A PDF can be encrypted with two passwords: a user password and an owner password. When a PDF is encrypted with a user password, you can't open the document in a PDF viewer without entering that password. When a PDF is encrypted with an owner password only, everyone can open a PDF without that password, but some restrictions may be in place.

From time to time, we get a PDF encrypted with an owner password. The
content is still readable, but PyPDF2 fails because it thinks the PDF is
encrypted. With this fix, we try to unwrap the PDF by providing an empty
user password. This way, PyPDF2 thinks the content is now decrypted.

However, PyPDF2 only supports decrypting versions 1 and 2 of the
encryption implementation. If the version is different, we skip reading
the attachments and carry on to allow the user to upload the document.

opw:2375993

closes odoo/odoo#64320

X-original-commit: 851fe64f7789bb398383c22e3ebbaebb051791f6
Signed-off-by: backspac <backspac@users.noreply.github.com>
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
2021-01-11 10:56:43 +00:00
Xavier Morel 7051a628c8 [FIX] core: PyPDF2 suppresses warnings
By default, PdfFileReader will monkeypatch the `warnings` module even
if it has no reason whatsoever to do so and suppress the
`captureWarnings` behavior.

This means as soon as we've loaded a PDF file, `warnings.warn` don't
trigger `logging` warnings anymore, and become invisible.

This can lead to non-deterministic behaviors depending as warnings may
or may not be suppressed depending when they occur relative to loading
a PDF e.g. load a module which runs a test which loads a PDF before a
module triggering a warning and the warning won't be visible, other
way around it will.

Except ofc while we have an override to PdfFileReader it's not
used *everywhere*, so need to monkeypatch the init.

closes odoo/odoo#60132

X-original-commit: 6b04dbcd4204a75d6bd68fc0b3010a2297779b32
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-10-15 17:34:57 +00:00
Benjamin Frantzen (bfr) ae15f89f73 [FIX] tools.pdf: do not crash when PDF has no attachments
In the PDF, `DictionaryObject` can be wrapped in `IndirectObject`. For nested
dictionaries, using `get` on a `DictionaryObject` will unwrap the result if it's
an `IndirectObject`, but not `__getitem__` so when trying to futher call `get`
on the result will cause an error: we need to unwrap the object first.
Instead, we patch `DictionaryObject.get()` for it to unwrap the object in case
it's an `IndirectObject`.

This is a follow-up commit of fece5ab1bf2fef043b131f1bd0886f0841116103

closes odoo/odoo#53269

X-original-commit: 189a0b28ec7fdb7472f936450cfd7b4bfd6912ed
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
Signed-off-by: bfr-o <bfr-o@users.noreply.github.com>
2020-06-18 16:49:32 +00:00
Benjamin Frantzen (bfr) b1d19c61b1 [FIX] tools.pdf: do not crash when PDF has no attachments
Depending on the PDF version and the presence of embedded files, the PDF
document catalog `trailer["/Root"]` may not have any Name Dictionary
`["/Names"]`, and the latter may not have any `EmbeddedFiles` entry.

In that case `getAttachments()` should return an empty list rather than
raising a `KeyError`.

closes odoo/odoo#52312

Ref: Section 7.7.2, 7.7.4 and 7.11.4 of [PDF 1.7 spec](https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf)
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
2020-06-03 14:08:37 +00:00
Benjamin Frantzen (bfr) 0226901ec7 [IMP] base, tools: manage multiple attachments on PDF files 2020-05-29 07:16:30 +00:00
Xavier Morel 43f10313c6 [IMP] *: automatically brand PDFs (from PyPDF2) as Odoo
To avoid having to fixup half a dozen places where we're creating PDF
writers, and possibly ending up with new ill-configured writers in
the future, patch PyPDF2's own writer with a subclass setting /Creator
and /Producer.

Note that this will not affect non-post-processed PDFs generated by
wkhtmltopdf. wkhtmltopdf does not allow setting these properties[0][1], so
to fix this issue we'd have to alter _run_wkhtmltopdf to pass the
result through PyPDF2 in order to alter its metadata.

[0] https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2000
[1] https://bugreports.qt.io/browse/QTBUG-44451

closes odoo/odoo#29460

Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
2020-03-23 14:41:52 +00:00
jbm-odoo 568b258c43 [IMP] tools: rotate PDF
Task ID 1251

closes odoo/odoo#45764

Related: odoo/enterprise#8569
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2020-03-11 09:57:55 +00:00
Christophe Simonis eceb173653 [P3] *: stop using cStringIO 2017-08-24 15:17:24 +02:00
Mehul Patel f205bfcd4d [ADD] tools: utility to merge pdf files 2017-08-14 14:23:50 +02:00