简体   繁体   中英

Print a list of PDF files to Client's printer

I am writing a web application that will, amongst a lot of other things, produce a list of PDF files:

public JsonResult BulkPrintExemptions()
        {
            List<FileContentResult> retValues = new List<FileContentResult>();
            var results = db.Permits.Where(m => m.Year == DateTime.Now.Year).Where(e => e.RecordDeleted == false).ToList();
            foreach (var result in results)
            {
                retValues.Add(GetPDF(result, "Exemption"));
            }
            return Json(retValues, JsonRequestBehavior.AllowGet);
        }

The list will be a minimum of about 400 PDF documents, and the user wants to automatically print them without any interaction on her part.

Once I return that List of FileContentResults, how do I automagically send it to the user's default printer?

I am fairly certain I just need to loop through the list and call Acrobat Reader for each one; I'm just at a loss as to how to do that through javascript.

How do I do that? Or, alternatively, I'm open to better options.

Full disclosure, to assist with options:

This is an MVC application in C#. The enduser has Adobe Acrobat Reader (at least) installed, as it's a default on the "Office Desktop" image.

Edit to add: The PDF files are coming from SSRS, if that makes any difference.

First, that sounds like a terrible idea on your user's part. This could potentially lead to locking up her computer while it processes that many print requests.

Second, it is possible. This SO question has some options listed, and it looks like Print.js is probably your best bet. Some comments there said it didn't open the print dialog, so it may not require interaction on your user's part; but I sincerely hope it does, because allowing a website unlimited access to a printer with no user interaction sounds like a terrible idea.

Alternatively, if it prompts for every single one of those 400+ PDFs, if you can concatenate them into one 400+ page document then you'd only have one print dialog. Still probably slow/lock up her PC while processing that request.

There are strict limits regarding what your WebPage can do on/to the Computer showing the WebPage. We used to be more lax. It was abused the heck out off. So it was fixed. But I doubt anyone was mad enough to ever allow JavaScript to send Print orders.

That being said it should be possible, using a Progamm or possibly even a Addon/Extension installed on the Client side.

You can register Programms with specific Protocolls , same way you would with File Extensions. Indeed that is how those Steam Links on the Desktop work - they are URL's with the custom "steam:" Protocoll. And all browser register both the common Filenames and the common Protocolls.

That is about the best answer I can give you with such a broad question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM