Asset styles.css not found



  • Hi,
    Got some problem with assets after upgrading every jsreport library to the newest version.
    Can't generate my report with phantom-pdf recipe. I got an error:
    Error: Asset styles.css not found
    I use my style.css and and image file in my hbs template where i include {#asset} ... cant figure out what I might be missing..

    My template:

    <style>
        {#asset styles.css @encoding=utf8}
    </style>
    
    <table cellpadding="0" cellspacing="0" style="width: 100%; padding:10px">
      <tr>
        <td colspan="2">
          <table>
            <tr>
              <td class="title">
                <img src="{#asset logo.png @encoding=dataURI}" style="width:100%; max-width:300px;" />
              </td>
              <td>
                Piperings report
                <br> Created: {{now}}
              </td>
              <td>
                Portfolio: {{portfolioCode}}
                <br> Module: {{moduleCode}}
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
    

    Congfig:

    exports.jsreport = jsreportcore({
      tasks: { strategy: 'in-process' },
      express: { app: app, server: server },
      appPath: "/report",
      assets: {
        allowedFiles: "**",
        publicAccessEnabled: true,
        searchOnDiskIfNotFoundInStore: true,
      },
      phantom: {
        allowLocalFilesAccess: false
      },
      scripts: {
        allowedModules: "*"
      }
    });
    

    Controller:

    exports.generateReportPDF = async function(req, res) {
      var data = await exports.fetchSomeImportantData(req, res);
      var filePath = path.join(__dirname, "pdfTest.pdf");
      generateReport(data, './report_templates/piperings/piperings.hbs', 'portrait', 'phantom-pdf')
          .then((resp) => {
            fs.writeFile(filePath, resp.content, function (err) {
              console.log("done");
            });
            res.contentType('application/pdf');
            res.send(resp.content);
          })
          .catch(err => {
            console.log('ERROR', err);
            //next(err);
          });
    }
    
    function generateReport(data, filePath, orientation, recipe) {
      return server.jsreport.render({
        template: {
          content: fs.readFileSync(path.join(__dirname, '..', '..', '..', filePath)).toString(),
          engine: 'handlebars',
          recipe: recipe,
          phantom: {
            orientation: orientation
          },
          helpers:
            `function now() {
              return new Date().toLocaleDateString()
            }` +
            `function itemNo(index) {
              return index + 1;
            }` +
            `function getPageNumber(pages, pageIndex) {
              if (!pages || pageIndex == null) {
                  return ''
              }
    
              const pagesToIgnore = pages.reduce((acu, page) => {
                  const shouldIgnore = page.items.find((p) => p.ignorePageInCount === true) != null
    
                  if (shouldIgnore) {
                      acu.push(page)
                  }
    
                  return acu
              }, []).length
    
              const pageNumber = pageIndex + 1
    
              return pageNumber - pagesToIgnore
            }` +
            `function getTotalPages(pages) {
              if (!pages) {
                  return ''
              }
    
              const pagesToIgnore = pages.reduce((acu, page) => {
                  const shouldIgnore = page.items.find((p) => p.ignorePageInCount === true) != null
    
                  if (shouldIgnore) {
                      acu.push(page)
                  }
    
                  return acu
              }, []).length
    
              return pages.length - pagesToIgnore
            }`
        },
        data: data
      });
    }
    

  • administrators

    since that you were using jsreport v1 and you upgraded to v2 but you forgot to update the format of your configuration options.

    please check this page https://jsreport.net/blog/jsreport-v2-released to know what you need to change.

    hint: you will need something like this in the end

    exports.jsreport = jsreportcore({
      templatingEngines: { strategy: 'in-process' },
      appPath: "/report",
      phantom: {
        allowLocalFilesAccess: false
      },
      extensions: {
        express: { app: app, server: server },
        assets: {
          allowedFiles: "**",
          publicAccessEnabled: true,
          searchOnDiskIfNotFoundInStore: true,
        },
        scripts: {
          allowedModules: "*"
        }
      }
    });
    

Log in to reply
 

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