Send PDF file path to client to download after covnersion in WeasyPrint
<p>In my Django app, I'm using WeasyPrint to convert html report to pdf. I need to send the converted file back to client so they can download it. But I don't see any code on WeasyPrint site where we can get the path of saved file or know in any way where the file was saved. </p>

<p>If I hard code the path, like, <code>D:/Python/Workspace/report.pdf</code> and try to open it via javascript, it simply says that the address was not understood.</p>

<p>What is a better way to apporach this issue?</p>

<p>My code:</p>

<pre><code> HTML(string=htmlContent).write_pdf(fileName,
        stylesheets=[CSS(filename='css/bootstrap.min.css')])
</code></pre>

<p>This is all the code related to WeasyPrint that generated PDF file.</p>

<p>You didn't even bothered to post the relevant code, but anyway:</p>

<p>If you're using the Python API, you either specify the output file path when calling <code>weasyprint.HTML().write_pdf()</code> or get the PDF back as bytestring, <a href="http://weasyprint.readthedocs.io/en/latest/api.html#weasyprint.HTML.write_pdf" rel="nofollow">as documented here</a> - and then you can either manually save it to a file somewhere you can redirect your user to or just pass the bytestring to django's <code>HttpResponse</code>. </p>

<p>If you're using the commandline (which would be quite surprising from a Django app...), you have to specify the output path too... </p>

<p>IOW : I don't really understand your problem. FWIW, the whole documentation is here : <a href="http://weasyprint.readthedocs.io/en/latest/" rel="nofollow">http://weasyprint.readthedocs.io/en/latest/</a> - and there's a quite obvious link on the project's homepage (which is how I found it FWIW).</p>

<p><em>EDIT</em> : now you posted your actual code: the answer is written in plain in the <a href="http://weasyprint.readthedocs.io/en/latest/api.html#weasyprint.HTML.write_pdf" rel="nofollow">FineManual(tm)</a>:</p>

<blockquote>
  <p>Parameters:    target â A filename, file-like object, or None
  Returns:<br>
  The PDF as byte string if target is not provided or None, otherwise None
  (the PDF is written to target.)</p>
</blockquote>

<p>IOW, either you choose to pass the filename for the generated to be generated and serve this file to the user, or you can just pass your Django <code>HttpResponse</code> as target, cf <a href="https://docs.djangoproject.com/en/1.10/howto/outputting-pdf/" rel="nofollow">this example</a> in Django's doc.</p>

python django weasyprint