<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Is it possible to use jsreportonline api in node and save pdf instead of triggering download]]></title><description><![CDATA[<p>Hi All,</p>
<p>I now have a google function that triggers a download to the browser. I'm looking if it is possible to instead create a function that downloads and stores the pdf file on google cloud storage.</p>
<ul>
<li>Is this possible with jsreportonline or do i need to run my own server?</li>
<li>Can i use jsreport-client in combination with jsreportonline server and how do i authenticate etc?</li>
<li>Or can i just adjust my existing code so that instead of triggering a browser download i get a stream that i can save to disk or something?</li>
</ul>
<p>I'm now doing this which is working bu i rather save the pdf on the server without triggering the download:</p>
<pre><code class="language-js">export const generatePdf = async (req: any, res: any) =&gt; {
  try {

    const data = {
      template: { shortid: 'XXX' },
      data: {test: 'test'},
      options: {'Content-Disposition': `attachment; filename=test.pdf`}
    };

    const options = {
      method: 'POST',
      headers: {
        'Authorization': 'Basic xxxxxxx',
        'Content-Type': 'application/json',
      },
      uri: 'https://xxx.jsreportonline.net/api/report',
      json: data
    };

    request(options).pipe(res);
  } catch(err) {
    console.log(`Error creating pdf ${err} `)
    return res.sendStatus(500)
  }
}
</code></pre>
<p>Thanks,<br />
Mark</p>
]]></description><link>https://forum.jsreport.net/topic/852/is-it-possible-to-use-jsreportonline-api-in-node-and-save-pdf-instead-of-triggering-download</link><generator>RSS for Node</generator><lastBuildDate>Sun, 08 Mar 2026 10:52:29 GMT</lastBuildDate><atom:link href="https://forum.jsreport.net/topic/852.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 13 Dec 2018 20:35:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Is it possible to use jsreportonline api in node and save pdf instead of triggering download on Invalid Date]]></title><description><![CDATA[<p>Hi All,</p>
<p>I now have a google function that triggers a download to the browser. I'm looking if it is possible to instead create a function that downloads and stores the pdf file on google cloud storage.</p>
<ul>
<li>Is this possible with jsreportonline or do i need to run my own server?</li>
<li>Can i use jsreport-client in combination with jsreportonline server and how do i authenticate etc?</li>
<li>Or can i just adjust my existing code so that instead of triggering a browser download i get a stream that i can save to disk or something?</li>
</ul>
<p>I'm now doing this which is working bu i rather save the pdf on the server without triggering the download:</p>
<pre><code class="language-js">export const generatePdf = async (req: any, res: any) =&gt; {
  try {

    const data = {
      template: { shortid: 'XXX' },
      data: {test: 'test'},
      options: {'Content-Disposition': `attachment; filename=test.pdf`}
    };

    const options = {
      method: 'POST',
      headers: {
        'Authorization': 'Basic xxxxxxx',
        'Content-Type': 'application/json',
      },
      uri: 'https://xxx.jsreportonline.net/api/report',
      json: data
    };

    request(options).pipe(res);
  } catch(err) {
    console.log(`Error creating pdf ${err} `)
    return res.sendStatus(500)
  }
}
</code></pre>
<p>Thanks,<br />
Mark</p>
]]></description><link>https://forum.jsreport.net/post/4129</link><guid isPermaLink="true">https://forum.jsreport.net/post/4129</guid><dc:creator><![CDATA[marksmits]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Is it possible to use jsreportonline api in node and save pdf instead of triggering download on Invalid Date]]></title><description><![CDATA[<p>hi!</p>
<blockquote>
<p>Is this possible with jsreportonline or do i need to run my own server?</p>
</blockquote>
<p>yes, this is possible with both jsreportonline and your own server</p>
<blockquote>
<p>Can i use jsreport-client in combination with jsreportonline server and how do i authenticate etc?</p>
</blockquote>
<p>yes, you can use <a href="https://jsreport.net/learn/nodejs-client" rel="nofollow">jsreport nodejs client</a> with jsreportonline too, using it will look something like this:</p>
<pre><code class="language-js"> // instead of &quot;https://bjrmatos9.jsreportonline.net/&quot; put here the URL of your jsreportonline account, and your credentials
const client = require('jsreport-client')('https://bjrmatos9.jsreportonline.net/', 'admin', 'password')

client.render({
    ...your options here...
  }).then((response) =&gt; {
   // response is a stream, you can use it and save it to disk
   response.pipe(fs.createWriteStream('/some/path/to/store.pdf'))
  }).catch((err) =&gt; console.error(err))
</code></pre>
<blockquote>
<p>Or can i just adjust my existing code so that instead of triggering a browser download i get a stream that i can save to disk or something?</p>
</blockquote>
<p>i think you just need to change this part of your code</p>
<pre><code class="language-js">request(options).pipe(res);
</code></pre>
<p>to this</p>
<pre><code class="language-js">request(options).pipe(fs.createWriteStream('/some/path/to/store.pdf'))
</code></pre>
<p>of course if this is your production code, make sure to add correct error handling when handling the streams</p>
]]></description><link>https://forum.jsreport.net/post/4130</link><guid isPermaLink="true">https://forum.jsreport.net/post/4130</guid><dc:creator><![CDATA[bjrmatos]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Is it possible to use jsreportonline api in node and save pdf instead of triggering download on Sun, 16 Dec 2018 20:12:00 GMT]]></title><description><![CDATA[<p>Thanks a lot!</p>
<p>For anyone who want to try it on firebase</p>
<pre><code class="language-js">import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'

admin.initializeApp()

import * as express from 'express'
import * as path from 'path'
import * as jsreport from 'jsreport-client'

const app = express()

const jsreportAdmin = functions.config().jsreport.admin;
const jsreportPassword = functions.config().jsreport.password;
const client = new jsreport('https://xxxxx.jsreportonline.net/', jsreportAdmin, jsreportPassword);

const generatePdf = async () =&gt; {
  
  const response = await client.render({
    template: { shortid: 'xxxxx' },
    data: { name: 'dasdasd'},
  })

  const metadata = {
    contentType: 'application/pdf'
  };

  const bucket = admin.storage().bucket();
    
  const fileName = `test.pdf`;
  const filePath = path.join(path.dirname('/test'), fileName);

  // Create upload stream
  const uploadStream = bucket.file(filePath).createWriteStream({metadata});
  response.pipe(uploadStream);
  
  return new Promise((resolve, reject) =&gt; uploadStream.on('finish', resolve).on('error', reject));
}

app.get('/generate', async (req, res) =&gt; {

  try {
    await generatePdf();
    return res.status(200).json({});
  } catch (error) {
    console.error(error);
    return res.sendStatus(500);
  }
  
});

exports.app = functions.https.onRequest(app);
</code></pre>
]]></description><link>https://forum.jsreport.net/post/4132</link><guid isPermaLink="true">https://forum.jsreport.net/post/4132</guid><dc:creator><![CDATA[marksmits]]></dc:creator><pubDate>Sun, 16 Dec 2018 20:12:00 GMT</pubDate></item></channel></rss>