Copy link to clipboard
Copied
Hello
I'm trying to pritn using adobe acrobat activeX
here is my code
<!DOCTYPE html>
<html>
<head>
<title>Print Test</title>
<meta charset="utf-8" />
<script>
function startPrinting() {
var acrobatObj = document.createElement('object');
acrobatObj.width = '500';
acrobatObj.height = '500';
acrobatObj.classid = 'clsid:CA8A9780-280D-11CF-A24D-444553540000';
document.body.appendChild(acrobatObj)
acrobatObj.src = 'test.pdf';
window.setTimeout(
function () {
acrobatObj.print();
}, 1000); // how big timeout?
}
window.onload = startPrinting;
</script>
</head>
<body>
<div id="ext-gen289"></div>
</body>
</html>
It works nicelly
Now the question- if user has low bandwidth, the setTimeout to 1 second is not enough.
In fact soem of users need to wait 1 minute to donlload respective file. While the others on stronger network, can print normally withoin one second
Is there a wya how the activeX would notify me "i have whole content"
I tried to play with cache, cookies sent prom the server, buffered reponse or session with no luck so far
Thanks
Zdenek
What I mean is add the printing code to a doc-level function of the PDF, like this:
this.print();
That way, when the file is opened (in a viewer that supports scripts correctly), the print dialog will immediately appear.
Copy link to clipboard
Copied
Try embedding the code in the actual file, instead of doing it via the HTML page.
Copy link to clipboard
Copied
Hello
what you mean by "embedding the code in the actual file"
I need to print from browsers (our app is in the browser, above is simplifed example)
How would that explain that it works in FF/Chrome and not in IE?
Thanks
Copy link to clipboard
Copied
What I mean is add the printing code to a doc-level function of the PDF, like this:
this.print();
That way, when the file is opened (in a viewer that supports scripts correctly), the print dialog will immediately appear.
Copy link to clipboard
Copied
Hello
Do you have working solution please?
I tried to add following snippet to the viewer.html from the solution above
<script src="viewer.js"></script>
<script>
window.onload = function(){
var printContentWindow = function () {
if (window!=null && window.PDFViewerApplication !=null
&& window.PDFViewerApplication.overlayManager
&& window.PDFViewerApplication.pdfViewer.pageViewsReady) {
console.info('pdf loaded and ready for printing');
window.print();
} else {
console.info('frame not ready for printing yet');
window.setTimeout(printContentWindow,1000);
}
}
printContentWindow.call(this);
}
</script>
with exactly the same result as before ( so the whole IE screenshot is printed)
as before works fine on Chrome/FF
Copy link to clipboard
Copied
I told you what my suggestion is. You don't seem to want to try it, which is fine, but I can't help you beyond that.
Copy link to clipboard
Copied
what do you mean by "you don't seem to want to try"
I did exactly what you told me, at least how I understand
and I received the same result
you said "in a viewer that supports scripts correctly" - so OK I add that to the viewer (i..e viewer.html)
if I understand it wrongly please tell where I'm wrong, or alternativelly please provide me working example
Thanks
Copy link to clipboard
Copied
The "viewer" is the PDF plugin used to open the file, not an HTML page.
What I suggested is to embed JavaScript code in the PDF. It has nothing to do with HTML or ActiveX. You just adjusted your ActiveX code, which is not what I meant at all... If you want to do what I suggested open your file in Acrobat, go to Tools - JavaScript - Document JavaScripts and create a new item (call it "scripts") with the code I provided above. Then save the file and upload to your web-server, and post a normal link to it, without any additional code.
Copy link to clipboard
Copied
Ok thanks, sorry I mixed two thread about similar topic
Now I start to understand.
So you are saying that if I load modified PDF document (with this.print script inside) in the AdobeActiveX, it will automatically print once the activeX will download the document, right?
Thanks a lot
Copy link to clipboard
Copied
I don't know why you insist on using ActiveX. It's enough to simply open
the file and the script (should) execute.
It will not print the file, but it will open the Print dialog.
On Thu, 7 Mar 2019 at 22:54, zdenekh25139748 <forums_noreply@adobe.com>
Copy link to clipboard
Copied
AciveX will automate process ( so it will open the file automatically, users do not want to open file themselves)
You have already answered original question, just in addition - what tool would you recomend to add such pdf dynamically
Means - our system has many (thousands ) of documents and I would like to modify pdf document (by adding javascript) right after the user try to print it (means click print button on our UI, rest should be automatic)
(so before server send pdf file to browser)
Thanks
Copy link to clipboard
Copied
There are various PDF libraries out there, and I'm sure most of them can do it. If you're inclined to use Java I recommend PDFBox.
Copy link to clipboard
Copied
Hello
This works nicelly as long as javascript API is enabled (I used PDFReader library)
So there is no way how to deal with that if javascript api is disabled?
As a additional question - is there a chance how to infrom parent page that this.print was called?
Like firing even from pdf document javascript and handling it over the ActiveX on the parent page?
(so I can hide progress bar informng user that application is still doing something)