Currently, I have a controller action that outputs a PDF (as a Response.OutputStream.Write()) and this is working just as it should.
However, I am interested in outputting another script section along with the PDF to “automatically print” (or simply perform a window.print();) on the PDF.
Is this possible, or is there another method to solve this issue that I may not be aware of?
Controller Action:
public ActionResult PrintPDF(string ID)
{
//Population of Model
//Output Result
return PdfResult(model);
}
PDF Result:
var buffer = byteArrayStream.toByteArray();
response.OutputStream.Write(buffer, 0, buffer.Length);
//Is it possible to output something like the following:
response.Output.Write("<script type='text/javascript'>window.print();</script>");
You will most likely not be able to mix PDF-data with JavaScript, so what you need to is embed the PDF-file using the
<embed>-tag and then use javascript to print whatever is inside the<embed>-tag.Here’s some information that someone else got working. Basicly this is the code that is outputted (from the previous source but edited a little bit):