• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Silent printing in IE using activeX

Community Beginner ,
Mar 04, 2019 Mar 04, 2019

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

TOPICS
Acrobat SDK and JavaScript

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 07, 2019 Mar 07, 2019

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.

Votes

Translate

Translate
Community Expert ,
Mar 07, 2019 Mar 07, 2019

Copy link to clipboard

Copied

Try embedding the code in the actual file, instead of doing it via the HTML page.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 07, 2019 Mar 07, 2019

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 07, 2019 Mar 07, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 07, 2019 Mar 07, 2019

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 07, 2019 Mar 07, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 07, 2019 Mar 07, 2019

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 07, 2019 Mar 07, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 07, 2019 Mar 07, 2019

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 07, 2019 Mar 07, 2019

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 07, 2019 Mar 07, 2019

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 07, 2019 Mar 07, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 08, 2019 Mar 08, 2019

Copy link to clipboard

Copied

LATEST

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines