How to make a header responsive?
-
how to make a header responsive as when i hit it through Post-man by passing landscape as true or false such that the pdf header become portrait and landscape accordingly as i was trying it by add the below lines in the script but its not working
const jsreport = require('jsreport-proxy') async function afterRender(req, res, done) { const watermarkRes = await jsreport.render({ template: { name: 'header-template', chrome: { landscape: false } } }) const $pdf = await jsreport.pdfUtils.parse(res.content) const pagesToMerge = new Array($pdf.pages.length).fill(watermarkRes.content) const originalBuffer = Buffer.from(res.content) const withWatermarkBuffer = await jsreport.pdfUtils.merge(originalBuffer, pagesToMerge) res.content = await jsreport.pdfUtils.merge(res.content, watermarkRes.content, mergeToFront = false) done(); }
-
So you have template
header-template
which is normal landscape orientation.
But you want to merge it also as portrait to the left of another template that is portrait orientation?
-
yes actually I have made the template responsive and i am changing its orientation from postman i.e. when i set the landscape =true the header is coming correctly but in case of landscape=false there is the problem
-
Perhaps you could share playground demo replicating the issue? That would help a lot with the further solution.
-
okay
-
hello here is the play ground link https://playground.jsreport.net/w/anon/A1IwPbzb
-
hi @Gayen-M I did not understand which entity I was expected to run, and also did not observe anything about the header template being responsive or changing layout, but anyway i ran the "current-directorship-template" and modified the
afterRender
script a bit to make it run correctly with the pdf utils and the landscape to false, see it hereasync function afterRender(req, res) { const $pdf = await jsreport.pdfUtils.parse(res.content, true) const watermarkRes = await jsreport.render({ template: { name: 'header-template', chrome: { landscape: false } }, data: { ...req.data, $pdf } }) /* const $pdf = await jsreport.pdfUtils.parse(res.content) const headertemplate = new Array($pdf.pages.length).fill(watermarkRes.content) */ /* const originalBuffer = Buffer.from(res.content) const withWatermarkBuffer = await jsreport.pdfUtils.merge(originalBuffer, headertemplate) */ res.content = await jsreport.pdfUtils.merge(res.content, watermarkRes.content, mergeToFront = false) }