Print pdf file in JavaScript - IE and Chrome

Print pdf file in JavaScript - IE and Chrome

<!DOCTYPE html>
<html >
<head>
  <script type="text/javascript">

 function printPDF()
  {
  if (navigator.appName == 'Microsoft Internet Explorer') {

     //Wait until PDF is ready to print    
    if (typeof document.getElementById("pdfDocument").print == 'undefined') {

        setTimeout(function(){printPDF("pdfDocument");}, 1000);

      } else {

        var x = document.getElementById("pdfDocument");
        x.print();
     }

   } else{

    PDFIframeLoad();  // for chrome 
  }
 }

//for Chrome 
function PDFIframeLoad() {
var iframe = document.getElementById('iframe_a');
   if(iframe.src) {
        var frm = iframe.contentWindow;

            frm.focus();// focus on contentWindow is needed on some ie versions  
            frm.print();
            return false;
    }
}

</script>



</head>
<body>
 PRINT PDF IN IE AND CHROME 
<table>
<tr>
<td>
<iframe id="iframe_a" name='iframe_a' src="PDF.pdf"    width="50%"    height="50%"   ></iframe>        <!-- for Chrome -->

<embed    type="application/pdf"    src="PDF.pdf"    id="pdfDocument"    width="0%"    height="0%" >
</embed> <!-- for IE - u can display  setted to  0% width and height-->

<input type="submit"  value="Print"name="Submit" id="printbtn"onclick="printPDF()" />
</td></tr><tr>
<td>
</td>
</tr></table>
</body>
</html>
View Answers

June 27, 2013 at 12:45 PM

<!--Print pdf file  in JavaScript - IE and Chrome (if not working in chrome add this html in war file of your server  
  <script type="text/javascript">

 function printPDF()
  {
  if (navigator.appName == 'Microsoft Internet Explorer') {

     //Wait until PDF is ready to print    
    if (typeof document.getElementById("pdfDocument").print == 'undefined') {

        setTimeout(function(){printPDF("pdfDocument");}, 1000);

      } else {

        var x = document.getElementById("pdfDocument");
        x.print();
     }

   } else{

    PDFIframeLoad();  // for chrome 
  }
 }

//for Chrome 
function PDFIframeLoad() {
var iframe = document.getElementById('iframe_a');
   if(iframe.src) {
        var frm = iframe.contentWindow;

            frm.focus();// focus on contentWindow is needed on some ie versions  
            frm.print();
            return false;
    }
}

</script>









Related Tutorials/Questions & Answers:
how to print pdf format
how to print pdf format  Hi every body iam doing school project iam using backend as oracle front end java .how to print student marks list /attendence in pdf format. please help me. thanks in advance.   Here
how to print HTML using javascript or Jquery
how to print HTML using javascript or Jquery  is there any way to print a document(created using Html and javascript) without using window.print... used Iframe for print, but this only work in chrome, but I have required one
Advertisements
Download PDF file
Download PDF file  How to download PDF file with JSF
pdf file in jsp
pdf file in jsp  i have a pdf, which has to be displayed in a jsp page along with some html tags, the pdf which is to be displayed shold be readonly and wont allow the uer to save too
about pdf file handeling
about pdf file handeling  can i apend something in pdf file using... to handle pdf files. You can find the related examples from the given link: Handling PDF files
about pdf file handeling
about pdf file handeling  i have downloaded a jar file containing packages for writing in pdf files . in which folder i should copy it ? i'm using windowsXP os.pls give whole path
Convert Text File to PDF file
Convert Text File to PDF file  Here is the way how to covert your Text file to PDF File, public class TextFileToPDF { private static void...(inLine); System.out.println("Text is inserted into pdf file
javascript and jquery not working in google chrome and firefox
javascript and jquery not working in google chrome and firefox  <...="text/javascript" src="http://goisearch.gov.in/content/scripts/jquery.1.8.7/jquery-1.4.4.js"></script> <script type="text/javascript" src="http
Convert Text File to PDF file
Convert Text File to PDF file  import java.io.BufferedReader; import...); System.out.println("Text is inserted into pdf file"); document.close... FileReader( Input File)); String inLine = null
how can i display a pdf file in a jtextarea
how can i display a pdf file in a jtextarea  I need to display a pdf file in a jtextfield or in a jtextarea.Atlest i need to displat it in a jframe.I have a button and while clicking on it ,i need to choose the pdf file and need
Java code to convert pdf file to word file
Java code to convert pdf file to word file  How to convert pdf file to word file using Java
Uploading and download pdf or .txt file.
Uploading and download pdf or .txt file.  I want admin user to upload pdf file into database and the users can download those pdf format from database
read restricted pdf file
read restricted pdf file  i have restricted file. package Encryption; import java.io.*; import java.util.*; import com.lowagie.text.*; import...()); } } } pdf given to code is in marathi it gives following output
read restricted pdf file
read restricted pdf file  i have restricted file. package Encryption; import java.io.*; import java.util.*; import com.lowagie.text...."+e.getStackTrace()); } } } pdf given to code
how to dispaly pdf file on browser
how to dispaly pdf file on browser  In my project i have created one pdf file(by pdfwriter) into my local mechine . after that it need to display in browser as a pdf file . but in jsp i can't display by tag can anyone give me
convert an pdf file to html in Java
convert an pdf file to html in Java  Hi all, How to convert an pdf file to html in Java? Currently all my data is generated into a report in pdf and i want to be able to generate it to html page as well. How to go about
upload the pdf file only - Struts
upload the pdf file only  plz tell me,in my web application i want to upload only pdf file.but i m getting the problem when anyone change the extesion of EXE or TEXT with .pdf its also upload.plz give me response ASAP plz
converting html file into pdf - Struts
converting html file into pdf  i want to convert html file into pdf file using java code please help me
Generate pdf file - JSP-Servlet
Generate pdf file   Hi Friends, How to generate the pdf file for the jsp page or in servets  Hi Friend, You need to download itext api. After that set the classpath and try the following code
how to display pdf file on browser
how to display pdf file on browser   In my project i have created one pdf file(by pdfwriter) into my local mechine . after that it need to display in browser as a pdf file . but in jsp i can't display by iframe tag can anyone
'Hello World' file from a servlet (PDF, HTML or RTF).
 'Hello World' file from a servlet (PDF, HTML or RTF...; In this program we are going to tell you how we can create three file rtf,pdf and html files.And we are printing here Hello Word on PDF, HTML, And RTF formate
How to Print Array in JavaScript
How to Print Array in JavaScript In this section you will learn about Array in JavaScript. Array are important part of all programming languages. Array in JavaScript is a variable that can hold more than one value. Array is a collection
how to generate pdf file in struts
how to generate pdf file in struts  I am developing a struts application.I am having one registration form when i am submitting the form the values... be shown as pdf or excel format
how to generate pdf file in struts
how to generate pdf file in struts  I am developing a struts application.I am having one registration form when i am submitting the form the values... be shown as pdf or excel format
Read PDF file
Read PDF file Java provides itext api to perform read and write operations with pdf file. Here we are going to read a pdf file. For this, we have used PDFReader class. The data is first converted into bytes and then with the use
JavaScript array print
JavaScript array print     ...;html> <head> <title> JavaScript array print example <...;/head> <body bgcolor="#ddcdff"> <h2> JavaScript array print
upload only pdf file - Struts
upload only pdf file  in web application,i want to attach only pdf file but if i change the extension of EXE or TXT files with PDF Extension its also upload ,but i want to upload only pdf file not only the extesion but also
CONVERT JTable DATA TO PDF FILE
CONVERT JTable DATA TO PDF FILE  HOW TO CONVERT JTable DATA TO .PDF FILE??PLEASE GIVE ME CODE FOR THAT.   Here is an example that reads the jtable data from the jframe and stored the data into the pdf file in the form
How to insert a single page PDF file into another multipage PDF file using iText? - Java Beginners
How to insert a single page PDF file into another multipage PDF file using iText?  Hi ALL: I have two PDF files. PDF-A.pdf is a multipage PDF file. PDF-B.pdf is a single page PDF file. I want to insert PDF-B into PDF-A only
To send pdf file to email in java
To send pdf file to email in java   Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger at javax.mail.Session.initLogger(Session.java:283) at javax.mail.Session.
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar  How to create pdf file having paragraphs and alignments done using java and itextjar 5.10 version.? hope i get quick response
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar  How to create pdf file having paragraphs and alignments done using java and itextjar 5.10 version.? hope i get quick response
File Upload is working in FireFox & Chrome but not in IE7 using java & jquery
File Upload is working in FireFox & Chrome but not in IE7 using java & jquery  Hi, I have a form which is called on my button click "Upload a file... works fine at FireFox & Chrome,but when I tried to upload the file from Internet
Write Hello in the pdf file
Write Hello in the pdf file     ...;Hello" word in a pdf file irrespective of the fact whether it exists...*, and com.lowagie.text.*. These two package will help us to make and use pdf file in our program.ADS
How to Convert PDF into rtf File Java
How to Convert PDF into rtf File Java  Hi, How could in covert the PDF file to rtf file in Java Programming. Please suggest any online example... uses the itext api for converting PDF file into RTF file. You can find
PDF Copy(File) has many pages.
PDF Copy(File) has many pages.  Dear All, I make Jasper Report it compile ,run and view properly. when i am try to send it pdf format it also sent it it pdf properly. but a that PDF Copy(File) has many pages. single copy
run a batch file through javascript
run a batch file through javascript   How to run a batch file through javascript without prompting
openning the pdf or doc file in same jsp
openning the pdf or doc file in same jsp   **how to open the pdf and doc file in same jsp after clicking the link or button (which is with out moving to the next page). will some body help me on this @simple format please
form field mapping with pdf file using java
form field mapping with pdf file using java   Hai all, I have one requirement that i have one html form.i have to map the form fields with pdf... related to the field in pdf file should marked with a color. can any one give
ModuleNotFoundError: No module named 'miu-print-file'
ModuleNotFoundError: No module named 'miu-print-file'  Hi, My... named 'miu-print-file' How to remove the ModuleNotFoundError: No module named 'miu-print-file' error? Thanks   Hi, In your python
pdf file measurement
pdf file measurement      ... on a pdf file,. To make the program for changing the pdf version firstly we have... in the document. In this example we need iText.jar file, without the jar file we
open pdf file in same jsp page and the pdf file should retrieved from database
open pdf file in same jsp page and the pdf file should retrieved from database  Hai all, I need code to open a pdf file in same jsp page(browser) while click on hyperlink And the file was located in database table. Can any
pdf file is having the 0 KB when generate the pdf file from jsp - JSP-Servlet
pdf file is having the 0 KB when generate the pdf file from jsp  Hi Friend, I am getting OKB pdf file .if i inserting the image into pdf file , i am getting the OKB pdf file now and also not able to open the pdf
JavaScript Open file
JavaScript Open file...; In this section, you will learn how to open and read the file in JavaScript. You can see in the given example, we have created a file component to let the user
JavaScript move file
JavaScript move file... the JavaScript method GetFile() with this object which returns the file...; In this section, we are going to move a file from one folder to another using
Add text into the pdf File - Development process
Add text into the pdf File  Hi friend, How can i insert or Add text into the pdf file from the exsting one in java.. Thanks in Advance...  Hi Friend, Please visit the following links: http
How to adjust a size of a pdf file
How to adjust a size of a pdf file   ... adjust the size of a pdf file irrespective of the fact whether it exists or not. If it exists then its fine, otherwise a pdf file will be created. 
read and write a file using javascript
read and write a file using javascript  How to read and write a file using javascript
read doc and docx file in javascript
read doc and docx file in javascript  How i read doc and docx file in javascript
How to wrap image in the pdf file
How to wrap image in the pdf file   ... insert a image  and wrap it according to your own style in a pdf file...*, and com.lowagie.text.*. These two package will help us to make and use pdf file in our

Ads