jsreport / jsreport-phantom-pdf

jsreport recipe which is rendering pdf from html using phantomjs
GNU Lesser General Public License v3.0
11 stars 8 forks source link

no longer allowed to pass margin config as object in version 2.x #29

Closed abenhamdine closed 6 years ago

abenhamdine commented 6 years ago

Hi and thx for this useful module.

I just upgraded to jsreport with the following updates :

-    "jsreport-core": "1.5.1",
-    "jsreport-handlebars": "1.1.2",
-    "jsreport-phantom-pdf": "1.4.6",
-    "jsreport-templates": "1.2.2",
-    "jsreport-xlsx": "1.4.2",
+    "jsreport-core": "2.0.3",
+    "jsreport-handlebars": "2.0.0",
+    "jsreport-phantom-pdf": "2.0.2",
+    "jsreport-templates": "2.0.0",
+    "jsreport-xlsx": "2.0.0",

With version 1.x, I was passing margin configuration as an object and it used to work :

 margin: {
    top: '25px',
    left: '1cm',
    right: '1cm',
    bottom: '5px'
}

(see https://github.com/jsreport/jsreport-phantom-pdf/pull/17 for this possibility)

but with version 2.x, It's seems no more possible to pass a string, I'm getting a validation error :

 stack: 'Error: template input in request contain values that does not match the defined schema. schema validation errors: template.phantom.margin should be string\n    at module.exports (/home/arhia/Documents/projects/payroll-app/node_modules/jsreport-core/lib/util/createError.js:9:13)\n    at Reporter.createError (/home/arhia/Documents/projects/payroll-app/node_modules/jsreport-core/lib/reporter.js:258:12)\n    at module.exports (/home/arhia/Documents/projects/payroll-app/node_modules/jsreport-core/lib/render/render.js:125:24)\n    at Reporter.render (/home/arhia/Documents/projects/payroll-app/node_modules/jsreport-core/lib/reporter.js:250:12)

I don't understand why. Edm type line https://github.com/jsreport/jsreport-phantom-pdf/blob/bf7768ede54aeba9b1f0dc05e0ff66a5c48f58cb/lib/phantom.js#L30 seems inconsistant with code line https://github.com/jsreport/jsreport-phantom-pdf/blob/bf7768ede54aeba9b1f0dc05e0ff66a5c48f58cb/lib/phantom.js#L131
but it was already the case in version 1.x

Thx by advance.

abenhamdine commented 6 years ago

I eventually managed to make the config work by passing the config in json :

margin: '{"top": "25px","left": "1cm","right": "1cm","bottom": "5px"}'

It would be a good thing to update the docs accordingly.

abenhamdine commented 6 years ago

PR sent for the docs : #30

pofider commented 6 years ago

Thank you for full description.

I think both string and json should be supported. It is likely rather a bug in validation. @bjrmatos can you confirm?

bjrmatos commented 6 years ago

thanks @abenhamdine for the description of the problem

I think both string and json should be supported. It is likely rather a bug in validation. @bjrmatos can you confirm?

yes, object type was missing in validation, this is now fixed with these changes and available in new version 2.1.1