Articles in this section
Category / Section

How to silent print the PDF document in the ASP.NET Classic by using Service?

1 min read

At present, there is no support for silent printing of the PDF document in the ASP.NET. However, you can achieve this by a workaround by using PdfViewer.Windows dll. In the following example, a Service reference is created and the PDF document is printed silently through the default printer.

C#

//Create an instance of PdfDocumentView.
PdfDocumentView view = new PdfDocumentView();
//Load the document in the viewer as stream.
view.Load(new MemoryStream(filestreamarray));
//Silently print the document through the default printer.
view.PrintDocument.Print();

The following code example in Default.aspx.cs accesses the PrintService method in the Service reference.

C#

//Create an object reference for the Serviceclient.
var client = new ServiceReference1.Service1Client("BasicHttpBinding_Service1");
if (System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName).Equals(".pdf"))
{
    //Get the stream of the file uploaded.
    Stream fileStream = FileUpload1.PostedFile.InputStream as Stream;
    MemoryStream memoryStream = new MemoryStream();
    fileStream.CopyTo(memoryStream);
    byte[] byteArray = memoryStream.ToArray();
    //Call the PrintService method in the service with filestream array as the parameter.
    client.PrintService(byteArray);
}

Sample Link:

https://www.syncfusion.com/downloads/support/directtrac/general/PdfViewerWeb281456998.zip

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied