Batch print files stored on the server from the website

I have an asp.net site hosted on AWS.

On this website, I need to select several PDF files from the list stored in the AWS window, and then print them.

Currently, my process allows you to print only one PDF file, redirecting them to the path to the PDF file in the browser, and then manually print it manually, but this process will become tedious if they have many print options. A.

Anyone have any ideas on how I can achieve this?

+4
source share
2 answers

Actually a very quick way is to simply copy the file to the path to the printer.
This works for both word docs and pdf. However, this involves a couple of things:

1.) Documents are stored where you could copy them.

2.) You have the printer driver installed on your web server.

3.) Adobe Reader must be installed on the web server. (otherwise printers sometimes do not recognize PDF).

So what I am doing is requesting printers on the server using ManagementObjectSearcher to find the default printer or any other that you want to capture for the path to the printer, and then copy the file to the path. That's all. The code is really simple.

public static class PrinterHelper { public class PrinterSettings { public string Name { get; set; } public string ServerName { get; set; } public string DeviceId { get; set; } public string ShareName { get; set; } public string Comment { get; set; } public bool Default { get; set; } } /// <summary> /// Sends the file to printer. /// </summary> /// <param name="filePathAndName">Name of the file path and Name of File.</param> /// <param name="printerName">Name of the printer with Path. EI \\SFDPRINT2.raven.ravenind.net\P14401</param> public static void SendFileToPrinter(string filePathAndName, string printerName) { FileInfo file = new FileInfo(filePathAndName); file.CopyTo(printerName); } /// <summary> /// Gets all printers that have drivers installed on the calling machine. /// </summary> /// <returns></returns> public static List<PrinterSettings> GetAllPrinters() { ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Printer"); ManagementObjectSearcher mos = new ManagementObjectSearcher(query); List<PrinterSettings> printers = new List<PrinterSettings>(); foreach (ManagementObject mo in mos.Get()) { PrinterSettings printer = new PrinterSettings(); foreach (PropertyData property in mo.Properties) { if (property.Name == "Name") printer.Name = property.Value == null ? "" : property.Value.ToString(); if (property.Name == "ServerName") printer.ServerName = property.Value == null ? "" : property.Value.ToString(); if (property.Name == "DeviceId") printer.DeviceId = property.Value == null ? "" : property.Value.ToString(); if (property.Name == "ShareName") printer.ShareName = property.Value == null ? "" : property.Value.ToString(); if (property.Name == "Comment") printer.Comment = property.Value == null ? "" : property.Value.ToString(); if (property.Name == "Default") printer.Default = (bool)property.Value; } printers.Add(printer); } return printers; } } 

This is how to use an assistant. i.e.

  var printer = PrinterHelper.GetAllPrinters().FirstOrDefault(p => p.Default); PrinterHelper.SendFileToPrinter(printer.Name, "C:\\Users\\Public\\Documents\\Form - Career Advancement Request.pdf"); 
0
source

You made a small mistake, how to use the helper, the arguments have changed. Pass the file name first and then the printer name.

0
source

All Articles