Hi!
I'm an absolute beginner when it comes to PHP and Javascript.
How do I print a report (outputted as a PDF) directly to the printer?
Thanks in advance!
--Jonathan
Welcome to the nuBuilder forums!
Please register and login to view forums and other content only available to registered users.
Please register and login to view forums and other content only available to registered users.
How to print directly to the printer?
Re: How to print directly to the printer?
Johnathon,
You can't print directly to the printer from a browser without some kind of 3rd party product. (http://www.meadroid.com/scriptx/)
The best you can do with JavaScript is use window.print().
This will bring up a dialog box, but you still have to click print.
(If you could, people could create malicious web pages that would use up all the paper in your printer)
Steven
You can't print directly to the printer from a browser without some kind of 3rd party product. (http://www.meadroid.com/scriptx/)
The best you can do with JavaScript is use window.print().
This will bring up a dialog box, but you still have to click print.
(If you could, people could create malicious web pages that would use up all the paper in your printer)
Steven
If you like nuBuilder, how about leaving a nice review on SourceForge?
-
- Posts: 23
- Joined: Wed Apr 07, 2010 10:32 am
-
- Posts: 2
- Joined: Wed Apr 04, 2012 11:08 am
Re: How to print directly to the printer?
I just encountered this "problem" and solved it for me. Maybe it is also useful for others.
Printing of PDFs can be automatically started via javascript.
Please note that JavaScript in PDF is much different from Javascript in HTML. The first is executed by (usually) Acrobat while second uses the API of the Webbrowser.
One condition is that the user has not disabled Javascript in Acrobat.
There's a little addon which allows to add Javascript in PDFs when using FPDF:
http://www.fpdf.de/downloads/addons/36/
I downloaded the zip and placed fpdf_js.php in the FPDF subfolder of nubuilder.
Then I changed "run_report_pdf_v2.php": (make a backup copy of this file before altering)
After the line
I added this line:
I changed this line:
To:
Then I added the following method (can be pasted above "function __construct ...")
Finally I added the following line in the function "build_report" below "$pdf = new nuPDF(..."
This should Acrobat let show automatically the Print Dialog when any PDF is generated via nuBuilder.
To suppress the Print-Dialog pass "false" to the Autoprint function.
Maybe there's a more elegant way to implement this (without patching the source). I would be happy to read about this.
Printing of PDFs can be automatically started via javascript.
Please note that JavaScript in PDF is much different from Javascript in HTML. The first is executed by (usually) Acrobat while second uses the API of the Webbrowser.
One condition is that the user has not disabled Javascript in Acrobat.
There's a little addon which allows to add Javascript in PDFs when using FPDF:
http://www.fpdf.de/downloads/addons/36/
I downloaded the zip and placed fpdf_js.php in the FPDF subfolder of nubuilder.
Then I changed "run_report_pdf_v2.php": (make a backup copy of this file before altering)
After the line
Code: Select all
require('fpdf/fpdf.php');
Code: Select all
require('fpdf/pdf_js.php');
Code: Select all
class nuPDF extends FPDF{
Code: Select all
class nuPDF extends PDF_Javascript{
Code: Select all
function AutoPrint($dialog=true)
{
$param=($dialog ? 'true' : 'false');
$script="print($param);";
$this->IncludeJS($script);
}
Code: Select all
$pdf->Autoprint(true);
To suppress the Print-Dialog pass "false" to the Autoprint function.
Maybe there's a more elegant way to implement this (without patching the source). I would be happy to read about this.