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


  • administrators

    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 here

    async 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)
    
    }
    

    0_1649361036825_Captura de pantalla 2022-04-07 a la(s) 2.50.26 p. m..png


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.