Changing report name



  • Is there an agreed upon way of changing the report name from the guid to something else?

    0_1672802769459_Screen Shot 2023-01-04 at 2.24.37 pm.png

    There are a number of different (unresolved?) questions on this forum and the solution in the documentation does not seem to work.



  • Just for context, is a script like this supposed to work?

    0_1672804585399_Screen Shot 2023-01-04 at 2.55.35 pm.png



  • The request options.reportName just affects the content-disposition header. In case you display pdf in page using object url the viewer doesn't use this. What you need to set is req.template.pdfMeta.title.

    Example

    <object id="pdfPreview" data="" width="800" height="500"> 
    </object>
    
    <script>
        async function preview() {        
            const report = await jsreport.render({
                template: {
                    name: 'mytemplate'
                    pdfMeta: {
                        title: 'my report'
                    }       
                }             
            })
            document.getElementById('pdfPreview').data = await report.toObjectURL()
        }
    
        preview().catch(console.error)
    </script>
    


  • Hi Jan,

    I got part of the way.

    Adding to the pdfMeta will fix how the title appears in the pdf viewer, and will change the title - any idea how to change the file name itself?

    0_1672982087497_Screen Shot 2023-01-06 at 4.13.50 pm.png



  • We don't know how to do that.
    The pdf.js, browsers use to display pdf, guess the file name from the url, but in the case of displaying pdf from javascript blob object, there is no way to adapt the url.
    https://stackoverflow.com/a/31990944/1660996

    What you can do is use synchronous jsreport.openInNewWindow or jsreport.download which uses form submit, in case you use the browser client.

    In case you fetch the pdf from your app server, just do a post to the iframe with url ending http://yourapp/some-path?desiredFilename.

    Or you can try using your own https://mozilla.github.io/pdf.js/ instead of letting the browser display the pdf.

    We will appreciate is anyone will find out some way out of this so we can document it for others.


Log in to reply
 

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