NumberOfPages displaying null in Meta



  • The pdf generates fine but the meta for report.Meta.NumberOfPages is returning null. Is there something else I have to do to get the number of pages once the file is generated?

    var report = await pdfService.RenderAsync(new RenderRequest
    {     
         Template = new jsreport.Types.Template
         {
              Recipe = Recipe.ChromePdf,
              Engine = Engine.Handlebars,
              Name = "Violation Letter"
         },
         Data = data
    });
    


  • The report.Meta.NumberOfPages unfortunately doesn't work with the chrome recipe.
    It was working with phantomjs some long time ago, but it isn't supported now.
    I will remove it from the jsreport.Types.

    The solution needs to employ the pdf utils now.
    Here is the demo
    https://playground.jsreport.net/w/anon/NjyiLidA

    In c# without a stored template it would be something like this:

    var customReport = rs.RenderAsync(new RenderRequest()
    {
        Template = new Template()
        {
            Content = "Helo world",
            Engine = Engine.Handlebars,
            Recipe = Recipe.ChromePdf,
            Scripts = new List<Script>
        {
            new Script
            {
                Content = @"const jsreport = require('jsreport-proxy')
    async function afterRender(req, res) {
        let $pdf = await jsreport.pdfUtils.parse(res.content)
        res.meta.headers.numberOfPages = $pdf.pages.length
    }"
            }
        }
        }
    }).Result;
    Console.WriteLine(customReport.Meta.RawDictionary["numberofpages"]);
    


  • That worked perfectly! I had to change the last line to match the case of the meta parameter. I created a script file and imported that into the templates I needed it on.


Log in to reply
 

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