Thanks
For now, my application is in development, so later i will convert templates to chrome-pdf
poiou
@poiou
Posts made by poiou
-
RE: Phantom PDF - page numbers inside content
-
RE: Phantom PDF - page numbers inside content
No, because the template is of an invoice, an so it may have several versions (original, duplicate, triplicate), and each one may have several pages of products.
And i'm using a for loop to iterate trough the pages of each version.
This for loop is nested inside a each loop that iterates trough the versions.
The ideal thing would be access {#pageNum} and {#numPages} inside the template. -
Phantom PDF - page numbers inside content
I have a template where trough the data i give the number of pages that it will have, and trough a loop i generate each page.
So i want to know if there is some way to have access to the number of pages and the current page.My idea is using an if to define some things that should not appear on the last page.
On header and footer i have access to {#pageNum} and {#numPages} but i want to access it outside footer and header.
Ps: I'm using jsreport 3.0.1, handlebars and phantom-pdf.
-
RE: Error 400
Now doesn't work again, and both, json and html from template are valid
-
RE: Error 400
I'm doing the request to report, wrote it wrongly.
It's strange because i had errors on html (it worked previously, i don't know why now those error make problems) that cause the PDF not rendered and correct it, now it generates the PDF correctly, but the error keeps apearing -
RE: Error 400
If i do a POST through my app i get the 400 end the jsreport error.
But if i post through postman and with exactly the same body the report is generated successfuly and without error. -
Error 400
I installed a jsreport instance on ubuntu as is in your site to generate PDF for my application.
On my application i make requests to /api/report with the data to generate those PDF, but my application gives HTTP error 400, and on jsreport log it shows:2020-06-29T09:02:12.013Z - error: Error during processing request at http://localhost:5488/api/report, details: Unexpected token { in JSON at position 15642, stack: SyntaxError: Unexpected token { in JSON at position 15642 at JSON.parse (<anonymous>) at parse (/home/prog3/Downloads/jsreportapp/node_modules/body-parser/lib/types/json.js:89:19) at /home/prog3/Downloads/jsreportapp/node_modules/body-parser/lib/read.js:121:18 at invokeCallback (/home/prog3/Downloads/jsreportapp/node_modules/raw-body/index.js:224:16) at done (/home/prog3/Downloads/jsreportapp/node_modules/raw-body/index.js:213:7) at IncomingMessage.onEnd (/home/prog3/Downloads/jsreportapp/node_modules/raw-body/index.js:273:7) at emitNone (events.js:106:13) at IncomingMessage.emit (events.js:208:7) at endReadableNT (_stream_readable.js:1064:12) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9)
and the content of the POST (with the content type application/json) request that i sent to /api/render is:
{ "data":{ "dataemissao":"29/6/2020", "empresa":"SOF", "filtradapor":"Código", "listagem":"Listagem", "ordenadapor":"", "terceiros":{ "0":{ "f1":"", "f2":"ccc" }, "1":{ "f1":"", "f2":"ccc" } } }, "template":{ "chrome":{ "printBackground":"true" }, "content":"<html> <head> <meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\"> </head> <body style=\"font-size:11px;\"> <h1>{{empresa}}</h1> <h2>{{listagem}}</h2> <div id=\"divActivites\" name=\"divActivites\" style=\"width:100%; border:1px solid black;\"> Filtrada por: {{filtradapor}}<br> Ordenada por: {{ordenadapor}}<br> Data de emissão: {{dataemissao}} </div> <br> <table style=\"width:100%\"> <thead> <tr> <th>Código</th> <th>Nome</th> <th>Localidade</th> <th>Código postal</th> <th>País</th> </tr> </thead> <tbody> {{#each terceiros}} <tr> <th> {{f1}} </th> <th> {{f2}} </th> </tr> {{/each}} </tbody> </table> </body></html>", "engine":"handlebars", "phantom":{ "footer":"<div>Pág. {#pageNum} de {#numPages}<br></div>", "footerHeight":"2cm" }, "recipe":"phantom-pdf" } }
PS: the original json was edited but is valid.
-
for loop with var
"""
"data":{
"copies":5,
"products":{
"1"{
"code":"123"
},
"2"{
"code":"456"
}
}
}'''"""
The goal of the previous sample is print 5 times "123" and then print 5 times "456".
I'm using handlebars and chrome-pdf.
How can i do it?
I already tryed with this topic, but i don't know how to use the copies var from the data sent, instead of a fixed value.