<?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[Download pdf or xlsx response so that I can email it.]]></title><description><![CDATA[<p>Quick background. I'm using jsreportonline. I'm creating a bunch of custom templates on the fly based off various user  data. I'm doing all of this in JavaScript as the whole program is client-side.  So, all of the solutions that use NodeJS are no good. I am currently viewing the pdf in a new window where the user can download it. Now, if the user wants to email the file I think my best bet is to download the file temporarily then attach that file and email it over sendgrid like I do normally. But I can't find a way to save the file to a specific path instead of downloading it to the computer in the browser.</p>
<p>This is my current code to view the pdf. Any direction on where to go from here on downloading the pdf so I can email it.</p>
<pre><code>var request = {
    template: {
        content: header + contentString,
        name: &quot;invoice-main&quot;,
        engine: engine,
        recipe: recipe,
        helpers: helpers,
        chrome: {
            landscape: isLand,
            marginTop: '20px',
            marginRight: '20px',
            marginBottom: '20px',
            marginLeft: '20px'
        },
        reports: {
            save: true
        }
    },
    data: aa
};
jsreport.renderAsync(request).then(function(res) {
    console.log( &quot;in async....&quot; );
    var html = '&lt;html&gt;' +
        '&lt;style&gt;html,body {padding:0;margin:0;} iframe {width:100%;height:100%;border:0}&lt;/style&gt;' +
        '&lt;body&gt;' +
        '&lt;iframe type=&quot;application/pdf&quot; src=&quot;' +  res.toDataURI() + '&quot;&gt;&lt;/iframe&gt;' +
        '&lt;/body&gt;&lt;/html&gt;';

    var a = window.open( &quot;&quot; , &quot;&quot;, &quot;wReport', top=2, left=2, &quot; +
        &quot;toolbar=no, menubar=no, location=1, height=900, &quot; +
        &quot;width=960, scrollbars=yes&quot; );

    a.document.write(html);
    a.document.title = title;
    a.onload = function()
    {
        parent.close();
    }
    a.document.close();
})</code></pre>
]]></description><link>https://forum.jsreport.net/topic/1310/download-pdf-or-xlsx-response-so-that-i-can-email-it</link><generator>RSS for Node</generator><lastBuildDate>Mon, 08 Jun 2026 11:55:24 GMT</lastBuildDate><atom:link href="https://forum.jsreport.net/topic/1310.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 23 Oct 2019 18:43:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Download pdf or xlsx response so that I can email it. on Invalid Date]]></title><description><![CDATA[<p>Quick background. I'm using jsreportonline. I'm creating a bunch of custom templates on the fly based off various user  data. I'm doing all of this in JavaScript as the whole program is client-side.  So, all of the solutions that use NodeJS are no good. I am currently viewing the pdf in a new window where the user can download it. Now, if the user wants to email the file I think my best bet is to download the file temporarily then attach that file and email it over sendgrid like I do normally. But I can't find a way to save the file to a specific path instead of downloading it to the computer in the browser.</p>
<p>This is my current code to view the pdf. Any direction on where to go from here on downloading the pdf so I can email it.</p>
<pre><code>var request = {
    template: {
        content: header + contentString,
        name: &quot;invoice-main&quot;,
        engine: engine,
        recipe: recipe,
        helpers: helpers,
        chrome: {
            landscape: isLand,
            marginTop: '20px',
            marginRight: '20px',
            marginBottom: '20px',
            marginLeft: '20px'
        },
        reports: {
            save: true
        }
    },
    data: aa
};
jsreport.renderAsync(request).then(function(res) {
    console.log( &quot;in async....&quot; );
    var html = '&lt;html&gt;' +
        '&lt;style&gt;html,body {padding:0;margin:0;} iframe {width:100%;height:100%;border:0}&lt;/style&gt;' +
        '&lt;body&gt;' +
        '&lt;iframe type=&quot;application/pdf&quot; src=&quot;' +  res.toDataURI() + '&quot;&gt;&lt;/iframe&gt;' +
        '&lt;/body&gt;&lt;/html&gt;';

    var a = window.open( &quot;&quot; , &quot;&quot;, &quot;wReport', top=2, left=2, &quot; +
        &quot;toolbar=no, menubar=no, location=1, height=900, &quot; +
        &quot;width=960, scrollbars=yes&quot; );

    a.document.write(html);
    a.document.title = title;
    a.onload = function()
    {
        parent.close();
    }
    a.document.close();
})</code></pre>
]]></description><link>https://forum.jsreport.net/post/6081</link><guid isPermaLink="true">https://forum.jsreport.net/post/6081</guid><dc:creator><![CDATA[Matthew Ward]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Download pdf or xlsx response so that I can email it. on Invalid Date]]></title><description><![CDATA[<p>hi! hmm i think saving the file to specific path using just client-side javascript is not possible, maybe the answer to this problem is in some sendgrid docs, how do you communicate with sendgrid from your client-side app? do they have some kind of browser sdk? (i can't find it)  if yes, please share a link to their docs, if they support some kind of browser sdk i guess there must be some demos about sending attachments and with that, i can give you an idea how to extract the report file from the jsreport response to be included in the sendgrid http call.</p>
]]></description><link>https://forum.jsreport.net/post/6085</link><guid isPermaLink="true">https://forum.jsreport.net/post/6085</guid><dc:creator><![CDATA[bjrmatos]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Download pdf or xlsx response so that I can email it. on Mon, 28 Oct 2019 17:45:47 GMT]]></title><description><![CDATA[<p>I figured it out.</p>
<p>var file = res.toDataURI();</p>
<p>That gives me the base64 encoded pdf in a string. So, once I put that in the variable I just did an ajax call in javascript where I then handle the rest in .php.</p>
<p>$f = str_replace('data:application/pdf;base64,', '', $f);<br />
file_put_contents( EMAIL_ATTACHMENTS .$file, $f);<br />
$fp = fopen(EMAIL_ATTACHMENTS . $file, 'wb');<br />
fwrite($fp, base64_decode($f));<br />
fclose($fp);</p>
<p>That saves the pdf to the attachments file where I temporarily store the file to attach to emails using sendgrid.</p>
]]></description><link>https://forum.jsreport.net/post/6114</link><guid isPermaLink="true">https://forum.jsreport.net/post/6114</guid><dc:creator><![CDATA[Matthew Ward]]></dc:creator><pubDate>Mon, 28 Oct 2019 17:45:47 GMT</pubDate></item></channel></rss>