I need to automatically print the pdf file generated. First, I save it to the server after generating the pdf file and then download it to client machine. I need to print the pdf file downloaded from the client machine. Is there a way I could get the exact location file where the pdf file is saved after downloaded? Is there a way I can print directly the pdf file using the client/local printer? For now, I have used spire pdf and the problem is it uses the server's printer and i need to fix it to use the client/local printer.
Codes:
window.location.href = "/Orders/Download?file=" + encodeURIComponent(data.fileName);
Controller:
[HttpGet]
[DeleteFileAttribute] //Action Filter, it will auto delete the file after download
public ActionResult Download(string file)
{
//get the temp folder and file path in server
string fullPath = Path.Combine(Server.MapPath("~/Content/PDF"), file);
try
{
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(fullPath);
doc.PrinterName = "HP Deskjet Ink Adv 2010 K010";
//Use the default printer to print all the pages
doc.PrintDocument.Print();
}
catch (Exception e)
{
var message = e.Message;
}
return File(fullPath, "application/pdf", file);
}
Is this code, it will download the pdf file to client/user Downloads or where the user set the location to download and it will print as well however it uses the server's printer which is the problem.