JSREPORT specific file name to store



  • Hi All

    Is want to store pdf in a specific directory with custom file name.i want to give my own file name.Is there any way to do it.


  • administrators

    hi! can you describe more the flow that you are using to generate the pdf? for example what options are you using, are you calling jsreport via http or with node.js sdk? or something else? if it is possible try to share some lines of code, so i can tell where to put the code to save the filename. there are different options to set a custom filename depending on the way that you are using it.


  • administrators

    ah ok, according to this topic you are referring to report templates

    as said in the linked topic, you can use dataDirectory config to save your templates in another directory, this directory will be the name of the root folder that will contain all your templates. the name of your templates will always be the names of the directories there, there is no other way to customize it, both will always match because that is the design of the store.



  • hi.. try this way i stored my pdf file in my directory by using nodejs using fileSystem 'fs'

    jsreport.render({
    template: {
    content:'<h1>hi {{:foo}}</h1>',
    engine: 'jsrender',
    recipe: 'phantom-pdf'
    },
    data: {foo:welcome}

    })
        .then(function (res) {
        var read = fs.createWriteStream('files/reports' + 'report.pdf');
        res.stream.pipe(read);
    });


  • Hi @bjrmatos thanks for your answer

    Here is my dev.config.json file in which i have following settings
    "dataDirectory": "D:\test",
    "tempDirectory":"D:\test"
    Now every report is generated according to my configured directory in Storage folder under this directory.On frontend implementataion i am adding options in form body as given blow
    addBody("template", template);

        addBody("options", options);
        addBody("data", JSON.stringify(data));
        //addBody("options", JSON.stringify('"reports": { "save": true }'))
    
        var headers = jsreport.headers;
        headers["host-cookie"] = document.cookie;
        headers["content-type"] = "application/json";
        addBody("headers", headers);
        
        document.body.appendChild(mapForm);
        mapForm.submit();
    

    Is there any possible override available for file name i want to set user defined filename.


  • administrators

    "dataDirectory": "D:\test",
    "tempDirectory":"D:\test"

    first i would say that it is not a good idea to use the same directory for dataDirectory and tempDirectory, try to make tempDirectory its own custom folder, specially reserved to contain temp files (example: "D:\test\temp" or ""D:\temp").

    Now every report is generated according to my configured directory in Storage folder under this directory.On frontend implementataion i am adding options in form body as given blow
    addBody("template", template);

    about report (pdf files) storage, currently we don't have a way to customize the filename of the report that it is saved, this is because we use the filenames as the id that uniquely identifies the report generated, if we provide an option to customize the name then there will be the chance that report files in the storage get duplicated and overwritten. your best option is to serve the report with another filename when user will download it, this can be done with custom server side code on your app.



  • Thanks @bjrmatos can i get generated file name after report generation??


  • administrators

    @aftabrehman1001 probably the only way to get the name of the generated report is by saving the report with the async option, you will find the id of the report in the Location header of the jsreport server response, just note that you will get an URL in the following format: http://jsreport-host/reports/id/status then you would need to extract the id of the url and then have the filename of the report by doing: id + '.pdf'. Also note that saving report in async way has other kind of flow to really know when the rendering has finished, so be sure to check the docs and prepare your app accordingly


Log in to reply
 

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