Solved

Print a PDF without any user intervention

Posted on 2004-08-23
9
570 Views
Last Modified: 2013-12-25
I have the following requirement :

There is a button say "pressMe", which when clicked should print a PDF file (whose path is known). However, the print operation should not pop-up any window and wait for the user to click on it. Also, if there is any pop-up window, it should close automatically once the PDF document is fully printed.

I am using Javascript. Right now, I am trying to simulate an operation which closes the Print Dialog that comes up before printing.

Please suggest solutions.

0
Comment
Question by:Sumanta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 11872970
Hi

First, I must say that users will probably dislike this fact (that you have disabled the print dialog). Use it only if you dare. You can use ScriptX, check out this link: http://www.experts-exchange.com/Web/Q_21068168.html



Regards,
Zyloch
0
 

Author Comment

by:Sumanta
ID: 11873273
Hi Zyloch,

I applied your solution and it worked.
But I need to customize it to my problem.

I have an array of checkboxes (which point to PDF files). The user selects some of the checkboxes and clicks the "pressMe" button. This should silently print the PDF's onto the printer (in a loop). For this reason, I do not want the print pop-up dialog to come up for each invocation of print.

Currently I am displaying the PDF's in 'iframes' in the same HTML page. These iframes are invisible and hold the PDF documents.
 <iframe name="bugsframe" src="c:\testhtml\bugs.pdf" width="0%">

How do I fire a print on these iframes when "pressMe" button is clicked ? [ more particularly -   how to call stopDialog.DoPrint(false); ]

Thanks in advance for your help.
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11873664
Because this is pdf, I would recommend you use server side coding, possibly something like this using PHP:

holdpdf.php
================
<?php
$myfile = "about:blank";
if (isset($_REQUEST['myfile'])) {
   $myfile = $_REQUEST['myfile'];
}
?>
<html>
<head>
<script language="javascript" type="text/javascript">
<!--
function printThis() {
  stopDialog.DoPrint(false);
}
// -->
</script>
<body onload="printThis();">
<object id="stopDialog" style="display:none"
classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" viewastext codebase="http://www.meadroid.com/scriptx/ScriptX.cab#Version=6,1,431,8">
</object>
<?php include($myfile); ?>
</body>
</html>


Then, your iframe would be:

<iframe name="bugsframe" src="holdpdf.php?myfile=c:\testhtml\bugs.pdf" width="0%">
0
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

 

Author Comment

by:Sumanta
ID: 11875787
I understand your point.
But I do not want to print the whole page.

I am interested in printing only the contents of the iframe.
And i cannot call  -   bugsframe.printThis();

So I am still searching for the solution ........
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 11877546
Yes, my above example will load the pdf into a new page to print (of course you need PHP). The other option would be to have an iframe of fixed width and fixed height and print only part of the page.
0
 

Author Comment

by:Sumanta
ID: 11894006
Just to add more comments to my recent trial ......

This is following Zyloch's pointers -
In the site,
http://www.meadroid.com/scriptx/docs/printdoc.htm#clientSideBasic

they have given some examples of basic printing (which does not require hassles of licenses etc).
They have demonstrated iframe printing which works only when there is a HTML file inside that.

However if I put a PDF file inside the iframe, it does not print the content (the PDF file).

I do not want to go through licensing issues as all clients would be required to download and install the advanced features offered by MEADROID:-(

Any workarounds offered are welcome ! :-)
0
 
LVL 36

Accepted Solution

by:
Zyloch earned 125 total points
ID: 11959227
Sorry, I was away. Yes, you need HTML in it, which is the main concern. No matter what, you can't do it unless you put the <object> there.

As to the downloading of Meadroid, they provide to you a free version with limited functions, and you can link to it from within your object tag remotely.
0
 

Author Comment

by:Sumanta
ID: 11963730
Yes, I am aware that Meadroid provides a free version - but that is not good enough to have my PDF printed without the pop-up print dialog.

They, of course, do have a BatchPrintPDF API to print a PDF - but that is licensed !! And so, that solution is not acceptable to me.

Another work around which I initially thought was using the following snippet in a Java code (this also prints silently)-
"C:\\Program Files\\Adobe\\Acrobat 6.0\\Reader\\AcroRd32.exe", "/p", "/h", "PDFfilename".

But I do not know how to run this Java program at the client side from the browser.

I am now looking into writing a Activex control myself .... Yeah, I know that it is a big task to do a small thing :-(
0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to dynamically set the form action using jQuery.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question