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
140
Merge Requests
140
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
4d100221
Commit
4d100221
authored
May 20, 2024
by
Jérome Perrin
Committed by
Arnaud Fontaine
Jul 31, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dms: more html2pdf fixes
parent
e7d60688
Changes
2
Show 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 @
4d100221
...
@@ -1694,6 +1694,30 @@ class TestDocument(TestDocumentMixin):
...
@@ -1694,6 +1694,30 @@ class TestDocument(TestDocumentMixin):
self
.
assertEqual
(
builder
.
extract
(
'Pictures/%s.png'
%
image_count
),
self
.
assertEqual
(
builder
.
extract
(
'Pictures/%s.png'
%
image_count
),
converted_image
,
failure_message
)
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
):
def
test_addContributorToDocument
(
self
):
"""
"""
...
...
bt5/erp5_web/ModuleComponentTemplateItem/portal_components/module.erp5.TransformHtmlToPdf.py
View file @
4d100221
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import
six
from
Products.PortalTransforms.interfaces
import
ITransform
from
Products.PortalTransforms.interfaces
import
ITransform
from
zope.interface
import
implementer
from
zope.interface
import
implementer
from
erp5.component.module.TransformLib
import
DocumentConversionServerTransform
from
erp5.component.module.TransformLib
import
DocumentConversionServerTransform
@
implementer
(
ITransform
)
@
implementer
(
ITransform
)
class
TransformHtmlToPdf
(
DocumentConversionServerTransform
):
class
TransformHtmlToPdf
(
DocumentConversionServerTransform
):
"""
"""
...
@@ -19,13 +21,13 @@ class TransformHtmlToPdf(DocumentConversionServerTransform):
...
@@ -19,13 +21,13 @@ class TransformHtmlToPdf(DocumentConversionServerTransform):
# (https://lab.nexedi.com/nexedi/cloudooo/merge_requests/20)
# (https://lab.nexedi.com/nexedi/cloudooo/merge_requests/20)
return
'html'
if
mimetype
==
'text/html'
else
'pdf'
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())...
# wkhtmltopdf handler currently requires conversion_kw (hack in convertFile())...
if
'conversion_kw'
not
in
kwargs
:
if
'conversion_kw'
not
in
kwargs
:
kwargs
[
'conversion_kw'
]
=
{
'encoding'
:
'utf-8'
}
kwargs
[
'conversion_kw'
]
=
{
'encoding'
:
'utf-8'
}
if
six
.
PY3
and
isinstance
(
orig
,
str
):
# raise RuntimeError
orig
=
orig
.
encode
()
return
DocumentConversionServerTransform
.
convert
(
self
,
*
args
,
**
kwargs
)
return
DocumentConversionServerTransform
.
convert
(
self
,
orig
,
*
args
,
**
kwargs
)
def
register
():
def
register
():
return
TransformHtmlToPdf
()
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