Commit 540a14cf authored by Jérome Perrin's avatar Jérome Perrin

dms: more html2pdf fixes

parent d7e8d205
......@@ -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):
"""
......
# -*- 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment