Trick How To Print Report Without Open New Tab Page With Javascript

The simple trick to print reports without opening a new tab page or open a PDF file in a new tab in the browser. Usually for web applications if you want to print reports, web programmers make PDF reports using class libraries such as FPDF which are then displayed in a new tab. The problem is how do we display the print dialog without opening the report page. Of course using javascript. Okay, just follow the short tutorial below.

How To Print Report Without Open New Tab In Browser

I am not the first person to invent this technique, I get this way from the site stackoverflow.com. The basic concept of this way is browser will load the report pages that will be printed into a hidden iframe. hen on page report, will add JQuery code to open the print dialog.

Please see the following video preview of how this script works:

Tutorial print report without open new page with Javascript

1. Create an index.php file and copy the following code :

2. Create 2 pieces of files with names invoice.php, invoice2.php

3. Copy the following code and copy to the invoice.php

5. Please copy the invoice template from https://github.com/WesCossick and paste to the invoice2.php

6. Put index.php, invoice.php, invoice2.php in one folder

7. Open a browser and run index.php

Finished , please run it on your browser

References:
http://stackoverflow.com/questions/8240472/printing-a-web-page-using-just-url-and-without-opening-new-window

http://stackoverflow.com/questions/585254/how-to-remove-the-url-from-the-printing-page

Similarly, a brief article about how to print the report without open new page with javascript

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Latest posts by Sigit Prasetya Nugroho (see all)

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.