Reputation: 1467
[Note this might be similar to https://stackoverflow.com/questions/48138874/can-make-print-js-print-a-variable, but I don't know PHP]
I have an ASP.Net core action that creates a PDF on the fly. I currently have the PDF download to the client, like so:
<a asp-controller="Home" asp-action="Pdf">Download PDF</a>
and the controller action
public IActionResult Pdf()
{
using (MemoryStream ms = new MemoryStream())
{
...
return File(ms.ToArray(), "application/pdf", "file.pdf");
}
}
Instead, I would like it to go to the print preview dialog of the browser, for which I was planning to use printjs
. But I have to specify a server-based file (such as "docs/file.pdf"). The printjs
sample is:
<button type="button" onclick="printJS('docs/file.pdf')">Print PDF</button>
Is there a way to cause the printJS
file to download the pdf file without needing to save it somewhere?
Upvotes: -1
Views: 946
Reputation: 1467
Doh. Too easy:
<a onclick="printJS('/home/Pdf')">Print PDF</a>
Instead of supplying an href to a file, have the onclick function call printJS with the action name which will execute and download the PDF.
Upvotes: 0