I am having a look at printing (to an actual printer) using CEF, with the aim of being able to print not just webpages, but also PDF files, as when running server-side, I would tend to trust more Chromium when it comes to security than the various PDF components out there.
Interactive printing works fine, but I have a few issues for automated printing
[*] there is an interactive printer selection/settings dialog
[*] the various OnPrint events do not seems to fire, and the code that calls these events does not seem to be called either
[*] therefore there is no feedback on the progress of printing
[*] when printing from a console browser (ConsoleBrowser2) there is only a gray bar on top getting printed
The print dialog should be solvable with a hack (sending windows messages directly to it to simulate user actions) in case there is no way to disable it, not ideal, but I could live with that.
Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
Silent printing
- salvadordf
- Posts: 4016
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Silent printing
Hi,
The GlobalCEFApp.OnPrint* events only work in Linux.
Silent printing is not supported by CEF but you can try these workarounds :
The GlobalCEFApp.OnPrint* events only work in Linux.
Silent printing is not supported by CEF but you can try these workarounds :
- Print to a PDF file with TChromium.PrintToPDF and then print the PDF. Use the TChromium.OnPdfPrintFinished event to know when it's finished.
- Take a screenshot from the browser and print the image.
- Build the CEF binaries with these modifications : https://magpcss.org/ceforum/viewtopic.php?f=6&t=12567&p=27604#p24370
- Use DDetours to intercept the call to show the printer dialog : https://github.com/MahdiSafsafi/DDetours
Re: Silent printing
Thank,
Printing the PDF with something else is the particular step I would like to avoid, mostly because of security risks posed by the usual PDF printing (tools (Acrobat, FoxIt...)
At the moment merely dismissing the print dialog would not be enough: while normal PDF / image "printing" works in the console browser, normal printing does not, even when manually validating the printer dialog.
Printing the PDF with something else is the particular step I would like to avoid, mostly because of security risks posed by the usual PDF printing (tools (Acrobat, FoxIt...)
At the moment merely dismissing the print dialog would not be enough: while normal PDF / image "printing" works in the console browser, normal printing does not, even when manually validating the printer dialog.
- salvadordf
- Posts: 4016
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Silent printing
Thanks for reporting this!
I'll take a look at the normal printing issue as soon as I have time.
I'll take a look at the normal printing issue as soon as I have time.
- salvadordf
- Posts: 4016
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Silent printing
I tried to print the webpage with the ConsoleBrowser2 demo and it worked correctly.
I added a call to TChromium.Print and let the thread sleep for a few seconds while I selected the Microsoft PDF printer, clicked OK and the browser printed the page contents. I set the event and exit the program after that delay.
The "sleep" call with the printer delay must done in the thread context and not in a CEF thread or inside a CEF event.
I added a call to TChromium.Print and let the thread sleep for a few seconds while I selected the Microsoft PDF printer, clicked OK and the browser printed the page contents. I set the event and exit the program after that delay.
The "sleep" call with the printer delay must done in the thread context and not in a CEF thread or inside a CEF event.