Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Jérome Perrin
erp5
Commits
0791c269
Commit
0791c269
authored
May 20, 2024
by
Jérome Perrin
Committed by
Arnaud Fontaine
Jul 15, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dms: more html2pdf fixes
parent
51ef1e36
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
4 deletions
+30
-4
bt5/erp5_dms/TestTemplateItem/portal_components/test.erp5.testDms.py
...s/TestTemplateItem/portal_components/test.erp5.testDms.py
+24
-0
bt5/erp5_web/ModuleComponentTemplateItem/portal_components/module.erp5.TransformHtmlToPdf.py
...eItem/portal_components/module.erp5.TransformHtmlToPdf.py
+6
-4
No files found.
bt5/erp5_dms/TestTemplateItem/portal_components/test.erp5.testDms.py
View file @
0791c269
...
...
@@ -1694,6 +1694,30 @@ class TestDocument(TestDocumentMixin):
self
.
assertEqual
(
builder
.
extract
(
'Pictures/%s.png'
%
image_count
),
converted_image
,
failure_message
)
def
test_HTML_to_PDF
(
self
):
web_page
=
self
.
portal
.
web_page_module
.
newContent
(
portal_type
=
'Web Page'
,
text_content
=
u'<p>héhé</p>'
)
# ERP5 convert API
_
,
pdf_data
=
web_page
.
convert
(
'pdf'
)
pdf
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'PDF'
,
data
=
pdf_data
)
self
.
assertEqual
(
pdf
.
asText
().
strip
(),
u'héhé'
)
# portal_transforms convert API
pdf_data
=
self
.
portal
.
portal_transforms
.
convertTo
(
'application/pdf'
,
orig
=
u'<p>héhé</p>'
,
context
=
self
.
portal
,
mimetype
=
'test/html'
).
getData
()
pdf
=
self
.
portal
.
document_module
.
newContent
(
portal_type
=
'PDF'
,
data
=
pdf_data
)
self
.
assertEqual
(
pdf
.
asText
().
strip
(),
u'héhé'
)
def
test_addContributorToDocument
(
self
):
"""
...
...
bt5/erp5_web/ModuleComponentTemplateItem/portal_components/module.erp5.TransformHtmlToPdf.py
View file @
0791c269
# -*- coding: utf-8 -*-
import
six
from
Products.PortalTransforms.interfaces
import
ITransform
from
zope.interface
import
implementer
from
erp5.component.module.TransformLib
import
DocumentConversionServerTransform
@
implementer
(
ITransform
)
class
TransformHtmlToPdf
(
DocumentConversionServerTransform
):
"""
...
...
@@ -19,13 +21,13 @@ class TransformHtmlToPdf(DocumentConversionServerTransform):
# (https://lab.nexedi.com/nexedi/cloudooo/merge_requests/20)
return
'html'
if
mimetype
==
'text/html'
else
'pdf'
def
convert
(
self
,
*
args
,
**
kwargs
):
def
convert
(
self
,
orig
,
*
args
,
**
kwargs
):
# wkhtmltopdf handler currently requires conversion_kw (hack in convertFile())...
if
'conversion_kw'
not
in
kwargs
:
kwargs
[
'conversion_kw'
]
=
{
'encoding'
:
'utf-8'
}
# raise RuntimeError
return
DocumentConversionServerTransform
.
convert
(
self
,
*
args
,
**
kwargs
)
if
six
.
PY3
and
isinstance
(
orig
,
str
):
orig
=
orig
.
encode
()
return
DocumentConversionServerTransform
.
convert
(
self
,
orig
,
*
args
,
**
kwargs
)
def
register
():
return
TransformHtmlToPdf
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment