Reputation: 53
I am creating pdf files in an asp.net project that is being stored on the server in a folder. When a user wants to print this file, I need the user to specify which printer among all the label printers on the network since it may contain numeral laser printers as well. I have tried creating a print process but this send the pdf file straight to the default printer. is there any way to display the print dialog so that users can select the required printer?
printjob.StartInfo.FileName = pdfFileName;<br/>
printjob.StartInfo.Verb = "Print";<br/>
printjob.StartInfo.CreateNoWindow = false;<br/>
printjob.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
PrinterSettings setting = new PrinterSettings();<br/>
printjob.Start();
Upvotes: 0
Views: 1965
Reputation: 46
This can be achieved by Spire.pdf.dll reference. To install this Open package manager console and type Install-Package Spire.pdf. this will install spire.pdf. Now the following code will help you print the pdf files.
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("D:\\sample.pdf");
//Use the default printer to print all the pages
//doc.PrintDocument.Print();
//Set the printer and select the pages you want to print
PrintDialog dialogPrint = new PrintDialog();
dialogPrint.AllowPrintToFile = true;
dialogPrint.AllowSomePages = true;
dialogPrint.PrinterSettings.MinimumPage = 1;
dialogPrint.PrinterSettings.MaximumPage = doc.Pages.Count;
dialogPrint.PrinterSettings.FromPage = 1;
dialogPrint.PrinterSettings.ToPage = doc.Pages.Count;
if (dialogPrint.ShowDialog() == DialogResult.OK)
{
doc.PrintFromPage = dialogPrint.PrinterSettings.FromPage;
doc.PrintToPage = dialogPrint.PrinterSettings.ToPage;
doc.PrinterName = dialogPrint.PrinterSettings.PrinterName;
PrintDocument printDoc = doc.PrintDocument;
dialogPrint.Document = printDoc;
printDoc.Print();
}
Upvotes: 1