Why isn't the index increasing In .net core mvc ?



  • I see your link
    https://playground.jsreport.net/w/admin/kMI4FBmw

    .net core code

    razor code

    {{#each $pdf.pages}}
     {{#if 0}}
       <div style="page-break-before: always;"></div>
     {{/if}}
     <main class="main"> 
       <header class="header">
         Header
       </header>
       <footer class="footer">
           <span>Page {{getPageNumber 0}} of {{getTotalPages ../$pdf.pages}}</span>
       </footer>
     </main>
    {{/each}}
    

    I cloned jsreport-dotnet-example-webapp from your github.

    index continues to be 0
    Only when PdfOperationType merging
    It doesn't happen when append prepend.
    0_1705648473204_screenshot.png



  • The shared code of your .net call would make it more clear, but I believe you need to set MergeWholeDocument = true.
    https://github.com/jsreport/jsreport-dotnet-types/blob/master/jsreport.Types/Request/PdfOperation.cs#L15



  • Thanks it works very well
    But I want to create a toc based on the page created above.
    What should I do?
    .net core code

    var pdfReport = await JsReportMVCService.RenderAsync(new RenderRequest
    {

     Template = new Template()
     {
         Content = result,
         Engine = Engine.Handlebars,
         Recipe = Recipe.ChromePdf,
         PdfOperations = new List<PdfOperation>()
         {
             new PdfOperation()
           {
               Template = new Template
               {
                     Content = toc,
                    Engine = Engine.Handlebars,
                    Recipe = Recipe.ChromePdf
                },
                Type = PdfOperationType.Prepend
             },
             new PdfOperation()
             {
                 Type = PdfOperationType.Merge,
                 MergeWholeDocument = true,
                 Template = new Template
                 {
                     Content = header,
                     Helpers = @"
                                     function getPageNumber (pageIndex) {
                                     if (pageIndex == null) {
                                             return ''
                                     }
                                     const pageNumber = pageIndex + 1
                                     return pageNumber
                                 }
    
                                 function getTotalPages (pages) {
                                     if (!pages) {
                                         return ''
                                     }
                                     return pages.length
                                 }",
                     Engine = Engine.Handlebars,
                     Recipe = Recipe.ChromePdf,
                 }
             }
         },
     }
    

    });



  • Here you can find a demo of ToC in .net core razor webapp
    https://github.com/pofider/jsreport-dotnet-example-webapp-toc/blob/master/Controllers/HomeController.cs#L124

    Based on this playground
    https://playground.jsreport.net/w/admin/tV6sVKbV

    However, I am not sure if it is the right approach to have jsreport locally in the .net app. It is quite complex and it looks to me like you should rather have a full-blown jsreport server doing this and you communicate with it using jsreport.Client.


Log in to reply
 

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