问题
I have a web app that creates a pdf using Websupergoo's ABCPDF. Right now after the user clicks the CreatePDF button the browser just downloads the created PDF. Instead I would like the print dialog to open so that the user can choose a printer and then print the PDF.
How can this be accomplished?
Please let me know if you need to see any of my code in the comment area and I will oblige.
回答1:
You can either return an html page and using javascript print function show a print dialog or ask the user to download a pdf.
In your case, a good option would be 2 buttons: "Download pdf" and "Print". When the user clicks on Print, (s)he can choose the printer that could be a PDF Printer.
See related: Can a PDF file's print dialog be opened with Javascript?
回答2:
I think what you're essentially asking to do is to ask the application that opens the PDF to print, which unless there are proprietary hooks that certain applications use, is not possible (and outside of Adobe, probably won't be very cross-platform friendly).
Javascript's print
function is a "standardized" method to tell browsers to print, and so generally that is safe to perform, but both PDF applications and the plugins they provide to browsers so they may display a PDF "in-browser" don't seem to have hooks to do so.
Once the PDF has been opened, that control scheme is outside of your domain of control. As @jorgebg mentioned, either print an HTML page, or let them download the PDF so they can do whatever they please with it. Unfortunately there's no clear way to do both.
来源:https://stackoverflow.com/questions/10216517/print-created-pdf-automatically-after-creation