These are chat archives for jsreport/jsreport

29th
Jun 2016
Studira
@Studira
Jun 29 2016 05:57
Hi
Jan Blaha
@pofider
Jun 29 2016 05:58
@Studira Hi
Studira
@Studira
Jun 29 2016 05:59
I am having trouble running jsreport off an express server and using extensions such as static-resources, wkhtmltopdf. The reports render but the css file is not found and with the wkhtmltopdf there is numerous errors?
What should I look out for or do you need more context
Jan Blaha
@pofider
Jun 29 2016 06:01
so step by steps... you attach jsreport to existing express application?
Studira
@Studira
Jun 29 2016 06:02
yes, I do attach it and then pass in an options/config when I require the core, after that I initialize and use the render method
Jan Blaha
@pofider
Jun 29 2016 06:04
ah ok, so you use jsreport-core
what kind of errors you have with the wkhtmltopdf ?
Oops, not sure If I should post links here?
Jan Blaha
@pofider
Jun 29 2016 06:06
ok, I received the code
Studira
@Studira
Jun 29 2016 06:07
I was trying an absolute and relative path for the static resources and neither work
Using jsrender so my template would have the stylesheet re as {{:$staticResources}}/css/blah.css
Jan Blaha
@pofider
Jun 29 2016 06:09
I see, give me a minute
Studira
@Studira
Jun 29 2016 06:09
np
Studira
@Studira
Jun 29 2016 06:21
wkhtmltopdf error: Exit with code 1 due to network error: ProtocolInvalidOperationError
Jan Blaha
@pofider
Jun 29 2016 06:22
The problem here is that static-resources extension resolves the absolute url to the resource using the incoming express request url, if you call just jsreport.render(..), it is not able to resolve the url.... I'm thinking how to solve this, give me a moment please
Studira
@Studira
Jun 29 2016 06:23
Sure
Jan Blaha
@pofider
Jun 29 2016 06:39
ok, static-resources uses http protocol to get the static resource, which won't work when calling jsreport.render, the easiest seems to load the resource using file protocol
  1. remove static-resources extension
  1. add the following
jsjsreport.beforeRenderListeners.add('file-static', function (req, res) { req.data = req.data || {} req.data.$staticResources = process.cwd() + '/static_resources' })
Studira
@Studira
Jun 29 2016 06:41
Oh ok, so we are just adding the path to the incoming request....will do that, thanks
Ito the wkhtmltopdf error?
Jan Blaha
@pofider
Jun 29 2016 06:42
yes exactly
I was not receiving the ProtocolInvalidOperationError from wkhtmltopdf
Studira
@Studira
Jun 29 2016 06:43
What could possibly trigger a protocolinvalid error?
Jan Blaha
@pofider
Jun 29 2016 06:43
let me know if the error occurs also after the change, maybe you will need to add "file:///" or something infront, but it is working for me as I posted
Studira
@Studira
Jun 29 2016 06:44
Ok will do
Studira
@Studira
Jun 29 2016 06:50
2016-06-29T06:49:38.705Z - warn: Extension static-resources was not found.
Request file:///Users/macpro/Desktop/blah/blah/static_resources/css/overides.css timestamp=Wed Jun 29 2016 08:49:43 GMT+0200 (SAST), requestId=1
Studira
@Studira
Jun 29 2016 06:58
I removed the static resources npm package and the reference in the extensions array, now the rendering just hangs?
Jan Blaha
@pofider
Jun 29 2016 07:02
hm, not for me, do you catch the failed promise? does it hang also if you remove the link to css ?
Studira
@Studira
Jun 29 2016 07:04
Still hangs even without the link, I also tried adding done() because I thought it might be blocking, no cigar
Jan Blaha
@pofider
Jun 29 2016 07:05
empty template also blocking? If you remove the beforeRenderListeners code I've sent?
can you share the render call?
Studira
@Studira
Jun 29 2016 07:07
Still hanging after I removed your code, I also tried to startup a new terminal window because sometimes things get wonky
let report = await renderReport({
template: {
content: template,
recipe: ReportRecipe[ReportRecipe['phantom-pdf']],
engine: ReportEngine[ReportEngine.jsrender]
},
data: req.body ? req.body : {},
options: {
reports: { save: true }
}
}, ReportType[ReportType.holdingsReport], 'pdf')
Jan Blaha
@pofider
Jun 29 2016 07:14
This doesn't shed the light, I am using this the test it now
app.get('/', function (req, res, next) {
  jsreport.render({
      template: {
          content: '<link href="{{:$staticResources}}/blah.css" rel="stylesheet"><h1>{{:foo}}</h1>',
          engine: 'jsrender',
          recipe: 'wkhtmltopdf'          
      },   
      data: {
          foo: "hello"
      }
  }).then(function(out) {
      out.stream.pipe(res)
  }).catch(next)  
});
Studira
@Studira
Jun 29 2016 07:16
This message was deleted
This message was deleted
This message was deleted
Studira
@Studira
Jun 29 2016 07:39
Ok I will try that, will come back should I not succeed. Thanks for your response so far
Jan Blaha
@pofider
Jun 29 2016 07:40
sure, the day just started here, so I should be here...
Studira
@Studira
Jun 29 2016 08:12
Thanks
Studira
@Studira
Jun 29 2016 09:08
2016-06-29T09:06:09.023Z - debug: Request file:///%2Fvar%2Ffolders%2F4w%2Fcdyt7lnj4694vp1c2sxtjdt00000gn%2FT%2Fjsreport-temp%2Fb68a0e30-3dd8-11e6-9d21-53aa2ec82253html.html timestamp=Wed Jun 29 2016 11:06:08 GMT+0200 (SAST), requestId=1
2016-06-29T09:06:09.024Z - debug: Request file://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css timestamp=Wed Jun 29 2016 11:06:08 GMT+0200 (SAST), requestId=1
2016-06-29T09:06:09.024Z - debug: Request file:///Users/macpro/Desktop/....this is removed intentionally.../staticResources/css/overides.css timestamp=Wed Jun 29 2016 11:06:08 GMT+0200 (SAST), requestId=1
2016-06-29T09:06:09.025Z - warn: Unable to load resource (#3URL:) timestamp=Wed Jun 29 2016 11:06:08 GMT+0200 (SAST), requestId=1
2016-06-29T09:06:09.025Z - warn: Error code: 301. Description: Protocol "" is unknown timestamp=Wed Jun 29 2016 11:06:08 GMT+0200 (SAST), requestId=1
2016-06-29T09:06:09.033Z - debug: phantom-pdf recipe finished. requestId=1
2016-06-29T09:06:09.036Z - info: Rendering request 1 finished in 2626 ms requestId=1
I have removed all my ES6 code and is running promises .then to see if that has no effect, but I guess not
Jan Blaha
@pofider
Jun 29 2016 13:10
you seems to use the phantom pdf recipe in the last code, is it right?
did you enable allowLocalFilesAccess for it?