Printing a PDF via Acrobat Javascript

Hi -
I have a need to print a PDF programmatically, via Javascript.  The PDF is embedded in a Web page.  I use postMessage to communicate with the PDF.
I've created a simple HTML page with an embedded PDF, and a Javascript link to call my "Print" function. Here's a code snippet:
<body>
         <a href="javascript:doPrint();">Print</a>
         <object id="PDFObj" data="testPDF.pdf" type="application/pdf" width="400" height="400" />     
</body>
In the HTML document's HEAD, I've added the following Javascript which posts the message to the PDF:
<script language="JavaScript">
        function doPrint() {
            pdfObject = document.getElementById("PDFObj");
            alert("Hello from Javascript...");
            pdfObject.postMessage(["Print", "Print"]);
</script>
Finally, I've added an Acrobat Javascript function in the PDF document to listen for the postMessage event:
function myOnMessage(aMessage)
    app.alert("Hello from the PDF");
       // print routines here
var msgHandlerObject = new Object();
msgHandlerObject.onMessage = myOnMessage;
msgHandlerObject.onError = myOnError;
msgHandlerObject.onDisclose = myOnDisclose;
function myOnDisclose(cURL,cDocumentURL)
return true;
function myOnError(error, aMessage)
app.alert(error);
this.hostContainer.messageHandler = msgHandlerObject;
Here's my problem: when I test this code and click the HREF Javascript link, I see "Hello from Javascript..." and "Hello from the PDF," so I know the postMessage event is working.  However, I've tried every print command I know in the myOnMessage function, and nothing seems to work:
app.execMenuItem("Print"); // doesn't seem to work
this.print(); // doesn't seem to work, even when I pass in all the params, etc
I've also tried getting print params and passing those in, nothing seems to work.  Am I missing something?  Environement is Acrobat 9 Pro, browser's tested include Chrome 2.0, IE6.  I've attached two files, the HTML bit and the PDF I'm trying to print.  Any help is greatly appreciated!

You have to be careful when using the ActiveX control to communicate with system functions like printing.  Because it can be embedded in anything that supports ActiveX, some functionality is limited from being called from JavaScript as it may interfere with the host application.
Check out the IAC API Reference (also included with the SDK) and the methods under AxAcroPDFLib.AxAcroPDF.  There are some print functions in there (like PrintAll) that you can call on the ActiveX control directly, as in from your doPrint() method in your HTML page without using the hostContainer.  You would basically just call:
pdfObject = document.getElementById("PDFObj");
pdfObject.PrintAll();
These methods were designed specifically to work with the ActiveX control when embedded in a host application, and can be used to print a PDF embedded in a web page.

Similar Messages

  • Direct Printing PDF via Acrobat 8.0 under Lion

    Direct printing a PDF via Acrobat 8.0 worked under Snow Leopard but no longer under Lion. I have a relatively old installation of CS3 on my MacBookPro and wanted to print a pages document with 12 x 12 cm size onto an A4 page (with integrated cutting marks) - this is not possible with the integrated PDF printer in Lion an so i decided to use Acrobat 8.0.
    The Console says the following:
    Process:         DistillerIntf [30793]
    Path:            /Applications/Adobe Acrobat 8 Professional/Acrobat Distiller.app/Contents/MacOS/DistillerIntf
    Identifier:      DistillerIntf
    Version:         ??? (???)
    Code Type:       X86 (Native)
    Parent Process:  pdf800 [30788]
    Date/Time:       2011-11-05 13:18:36.563 +0100
    OS Version:      Mac OS X 10.7.2 (11C74)
    Report Version:  9
    Crashed Thread:  7
    Exception Type:  EXC_BAD_ACCESS (SIGBUS)
    Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000000
    VM Regions Near 0:
    --> __PAGEZERO             0000000000000000-0000000000001000 [    4K] ---/--- SM=NUL  /Applications/Adobe Acrobat 8 Professional/Acrobat Distiller.app/Contents/MacOS/DistillerIntf
        __TEXT                 0000000000001000-0000000000003000 [    8K] r-x/rwx SM=COW  /Applications/Adobe Acrobat 8 Professional/Acrobat Distiller.app/Contents/MacOS/DistillerIntf
    Has anybody an idea how to solve this problem. Of course i posted this error on the Adobe Help forums but since these guys only want to sell the newest Suites if have no hope, that somebody will respond to my question - and i think it is a Lion issue (CUPS problem).
    http://forums.adobe.com/thread/921666

    This is right, but since the upgrade to Lion was a relatively big one (with many functionalities that i have be missing before) i think i will not go back just to regain a normal-working direct PDF printing. Nevertheless i think, if the very old CS3 worked until Snow Leopard it would be very easy for an Apple Engineer to figure out, which trick would allow Acrobat to direct print again - i don't think the underlying CUPS has changed very much - also i found a lot of similar error reports on the web (mostly Acrobat related after updates from System ) which were solved via correcting some rights in the library (this didn't do the trick for me ...)
    Best problem solving would be, that Adobe Software gets cheaper - i have installed the newest Aperture, iWork, Office, iLife, Mindmanager, ... - if you are not a student but a hobby worker these software packages are quite affordable ...

  • When I print to PDF using Acrobat 11 Pro from any application the acrobat Reader does not launch automatically. Associations are correct. Thx for your help,  Bruce

    When I print to PDF using Acrobat 11 Pro from any application the acrobat Reader does not launch automatically. Associations are correct. Happens from Chrome, IE, Word, Excel, Powerpoint. Previously had deskPDF installed but uninstalled correctly. Can't find a preference setting for the auto launch. Thx for your help,  Bruce

    A simple way is to flatten the form fields, which converts the field appearances to regular page contents. You can do this with JavaScript or PDF Optimizer (Advanced > PDF Optimizer > Discard Objects > Flatten form fields). A very nice script that adds a custom menu item can be found here: http://www.uvsar.com/projects/acrobat/flattener/

  • Printing  a .pdf file by javascript?

    Is it possible to print a .pdf  file  by javascript function or Adobe javascript and how ? I hope that one expert can share me a sample javascript function.
    Thank you very much in advance.

    Hi, thank you for your answer.
    Is it possible for me to reference Acrobat javascript api inside asp.net web application and how ?
    Thank you  and I appreciate your help.

  • Tif files not opening via Acrobat Javascript openDoc() method

    Hi,
    I am trying to open a .tif file via Acrobat Javascript using the following code snippet which I have in config.js file in Acrobat Javascripts folder:
    trustedOpenDoc = app.trustedFunction( function (File)
    app.beginPriv();
      var doc = app.openDoc({
          cPath: File,
          bUseConv: true
    app.endPriv();
    return doc;
    Problem is that openDoc opens up all other images but it has problem with multi page tif files, I mean it does not open some tif files. I have directly tried to open files in Acrobat professional 8/9 from File --> Open but got same result.
    The same happens also with some heavy (above 1 MB) .bmp files but with .bmp files this behaviour is not so frequent, on the other hand .tif files always give the same result.
    Any PDF Gladiator who can save my project deadline!
    Look please; I have this problem for the last 12 days and miserably my project is getting late becoz of this.
    Thanks in advance for the resolution/suggestion.

    You guys are not getting my point.
    I am using Adobe Acrobat Professional 8/9 for creating a PDF that picks up text files and image (Jpg, bmp, tif) files from a network shared folder and inserts them into an empty Template PDF file by making use of Acrobat events through Javascript.
    This all works fine as long I dont include any Tif file and PDF is created successfully.
    Now all other file types including text files, jpgs, gif are opening up but problem is with .tif files.
    You can check this by directly opening image files in Adobe Acrobat Profesional 8/9 from File --> Open menu option.
    Other images will open up but most Tif files won't open in it. Such tif files also not open in "Winodws Picture and Fax Viewer" software but will open in softwares like "Imaging Professional" , "IrfanView" etc, which I think use some special codec for it.
    If you know of any Acrobat plugin that can be incorporated in Acrobat professional and convert these tif files to PDF on the fly, would be of great help or have some any other suggestion you feel is right.
    Thanks

  • Can't print to pdf with Acrobat 7.1.0 in Vista

    I am unable to print to pdf with Acrobat 7.1.0 in Windows Vista.  I used to be able to, now all of a sudden that functionality is gone.  I haven't knowingly done any upgrades since the last time I successfully printed to pdf, but I do have autoupdates enabled, so I can't say what Microsoft may have been up to recently.  When printing to pdf from Internet Explorer 7, the window simply closes.  A printer icon shows up in the system tray but registers 0 print jobs and soon disappears.  When printing to pdf from Word (2003), Word crashes with a series of message boxes saying something about attempting recovery.  Any suggestions?

    AcroTray is running.  Thanks for asking that question, as this is one thing that I have disabled on computers running XP, since disabling it in XP doesn't adversely affect my limited use of Acrobat in any way.  I have not disabled it with Vista.  I tried printing to file, and that also caused the window to close.  I happened to have a second IE7 window open when attempting to print to file, and it did not close, so it only affects the active window.  I don't know if that helps at all; when a program crashes, I typically observe it take with it all open windows associated with that program, so the fact that this is only closing the active window seems potentially useful to me in my ignorance of what is the root cause. 

  • Printing to PDF using Acrobat X Pro - Cannot figure it out!

    I do not have the option to print to pdf and cannot figure out how to perform this function.  Following the user guides there should be an option under file > Print > advanced > print to pdf
    However under the advanced options i do not have the option "print to pdf"
    Furthermore, if i scroll through my printer options this is also not available.
    Please help!

    I tied to print to pdf within Acrobat 10 Pro yesterday trying to solve a printing problem.  It seemed that the application would not print to pdf but required me instead to "save as" pdf to create another pdf copy.

  • Error: "The system cannot find the file specified" when trying to print to PDF w/ Acrobat 9.5

    I get an Error: "The system cannot find the file specified" when trying to print to PDF w/ Acrobat 9.5 using Windows 7.  This just started happening after upgrading to MS 2013 suite and also installed Adobe Reader at that same time.
    I had problems in the past when Reader was installed with Acrobat, so I uninstalled Reader, but the problem still seems to occur.
    any help would be appreciated.

    That link has backslashes (%5C) that need to be changed to forward slashes:
    *http://supportdocs.sonybiz.net/indexes/pi/LFS/May_2004/00035186.pdf

  • Getting errors printing to PDF with Acrobat 8 in Leopard

    I get the following error when trying to print to PDF in Acrobat 8 under 10.5:
    "No %%BoundingBox: comment in header"
    What does this mean and how do I fix it?
    I have updated to 10.5.4 and Acrobat 8.1.2 with the same results. The error remains the same in the PDF print queue, though the job actually disappears now that I upgraded Acrobat. The jobs remained in the queue before, they simply stopped the queue but remained.

    When do you get the error, exactly? This doesn't sound like an Acrobat
    error. Are there any clues (like a title bar, something active in the
    doc) what is putting out the message?
    Aandi Inston

  • Printing a PDF via Air

    Hey!
    With alivePDF I can create and save from Air a PDF-Document. I can also load this document in a new window in Air. But how can I print it from air?
    Printing via htmlLoader-Object raised the same error like in my post about printing a runtime created htmlloader-Object (http://forums.adobe.com/thread/591929?tstart=0).
    I like to use the start2() from Air2Beta2 option for printing without dialog. but how can i send this pdf content to the print-object?
    Is this possible?

    You have to be careful when using the ActiveX control to communicate with system functions like printing.  Because it can be embedded in anything that supports ActiveX, some functionality is limited from being called from JavaScript as it may interfere with the host application.
    Check out the IAC API Reference (also included with the SDK) and the methods under AxAcroPDFLib.AxAcroPDF.  There are some print functions in there (like PrintAll) that you can call on the ActiveX control directly, as in from your doPrint() method in your HTML page without using the hostContainer.  You would basically just call:
    pdfObject = document.getElementById("PDFObj");
    pdfObject.PrintAll();
    These methods were designed specifically to work with the ActiveX control when embedded in a host application, and can be used to print a PDF embedded in a web page.

  • Is there any way to "Print to PDF" from Acrobat?

    In Windows, you can open a PDF in Acrobat and print it to a PDF.  This isn't behavior isn't available in the Mac version—trying to use "Save as PDF" and "Save as Adobe PDF" both produce the following error message:
    Saving a PDF file when printing is not supported. Instead, choose File > Save.
    Is there any way to print to a PDF from Acrobat Pro X on a Mac (running Snow Leopard)?
    Note: There's a utility to being able to print from a PDF to PDF (which I why I suspect it's available in the Windows version), so "You're doing it wrong—just Click File > Save" would not be a very helpful response.  I'm sure there are other uses for the functionality, but in my case in particular I need to split each page of a scanned PDF in which each page contains two pages of the original document.  Printing to a PDF provides an easy way to do this, but I'm open to a more appropriate solution if it's available.
    Any ideas?
    Thanks!

    Adobe removed the ability to "refry" (make a PDF from a PDF) several versions ago.
    what you need is to go to document and choose Remove (delete) pages (if it’s a duplicate Page)
    You can also extract pages, add pages and so on. See this:
    http://screencast.com/t/yn0bYTERp

  • How can I print my PDF to show Javascript?

    I've made a few forms for my work, and I'd like to print them and put them into a portfolio to take to future job interviews and yearly reviews. I'm trying to avoid having to take screenshots and paste them together, but if that's what I have to do, I can. Is there a feature in LC that will allow me to print my PDFs like this?
    Example:
    A portion of the page I designed is on the left with text boxes, etc. shown, and to the right is the code that is affected by the text field it points to.

    Hi,
    I guess this is not possible to do by just showing JavaScript. You can show these things in a JavaScript debugger always but while printing seems not possible. How about making a hidden Text/TextField and put some conditions/directions on how the fields should be filled up and making this Text/TextField visible at the time of printing? Because if someone does not know JavaScript and he needs to access it he will be confused. Makes sense??
    Thanks,
    Bibhu.

  • Can't print to PDF from Acrobat XI

    I'm having trouble printing to a PDF from Acrobat XI Pro (FYI, I'm using OS X 10.8). 
    Here's what's goin on:
    I open the file in Acrobat.
    I hit Cmd-P and in the "Printer" dropdown list I select "Adobe PDF 7.0".
    I click "Print" in the lower right.
    The print monitor icon pops up, but nothing happens. (When I click it to view progress, it just sits there and says "Ready to print", but no matter what I do, nothing happens.)
    To clarify, as far as I can tell, this is only a problem when I try to print using the "Printer" dropdown menu and is universal across all applications (i.e. Acrobat, Word, Chrome, etc.). When I select "Save as PDF" within any of those applications, there is no problem at all.
    You may be asking yourself "Then why don't you just continue to 'Save as PDF' and forget about the 'Printer' option?" The "why" is not important, so I'll save you my reasoning as it has no bearing on fixing this problem. I'll just say that I have a somewhat frequent need to do it in this particular manner and need to have that option available to me. No offense intended, I simply want to solve to problem without running off on an unimportant tangent.
    I'm sure you'll have other questions about my system and what I'm doing/have done, so please ask away.
    Thanks so much

    I've had the same issue on 10.7 (and, I believe 10.6). Although this point may also be contributing to the problem, I don't suspect that it is the only demon at at work here. However, if you are referring to all versions of OS X that would make some sense since the only print drivers I could find on Adobe's downloads section didn't show support for anything newer than OS 9.2.2
    As to your suggestion, I'm not sure I follow what you mean. Here is a screen cap of the dialogue box I'm presented in Acrobat XI. Can you please point out the "PDF Button" you're talking about?
    After reading your comment again, am I correct in assuming that you are suggesting I essentially save the document as a PDF, as is usually present in the print dialogue box for other applications? If that is what you are suggesting, I already explained that that is not an option and doesn't solve the problem.
    Thanks

  • "Print to PDF" w/ Acrobat Pro 8 on Mac 10.6

    I have the following:
    MacBook Pro running OS X 10.6.3
    Adobe Acrobat 8 Professional
    Customer support told me to post my question here, so this is what I am doing.
    I have a 800+ page pdf file open in Acrobat 8 Pro.  I want to "print" several non-consecutive pages from that file to another pdf file.  So, for example, when want to print pages 170, 171-175, 186-197, I select file>print, then type in these selected pages.  Then I change the printer selector to "Adobe PDF 8"  (Note that this name has an exclamation point icon in front of it, which to me is a red flag).  When I hit "print" to create the new pdf, the job is sent to my printer where it sits as paused.  I can't get it to "print to pdf".
    I tried printing to pdf from the web but ran into the same problem.
    I have used Acrobat on Windows for years and I know that I should be able to do what I am trying to do.  Not sure why I can't do it.  Read a post about Snow Leopard blocking the pdf printer, but not sure if that is correct.  If it is correct, there has to be some work-around that will allow me to efficiently do what I want to do.  Or is there something known that Mac support can do to help me?
    This is such a basic function of Acrobat I can't believe that there is not some way to do it.  But if there is not some way to do it, it will be VERY disappointing.
    Thanks in advance for any help you can give me.

    Will this help you:
    http://kb2.adobe.com/cps/509/cpsid_50981.html

  • Can't Print to PDF using Acrobat 8 Prof after deleting demo of v 10

    Hi, I made the mistake of trying version 10 to see if it had any improvements over what I was using v 8.1.5 for, found that there were none, so I deleted it and now I can't print to PDF because it's looking for v 10. Unfortunately had to move recently and can no longer find the original disk to do a new installation. Does anyone know how to redirect the driver to the original v 8? I can open v 8 and everything else seems to work ok, just when I try to print to create a PDF it can't do it.

    Thanks for the quick reply Bill! I had tried that before and tried it again. Finally got things to work by copying all the contents of my Acrobat sub-directory from the v 8 folder to the hollow v 10 folder. Now it works again! Thanks for you help and inspiration to figure this thing out. Am now a very happy camper and didn't need to tear my house appart to find the original disk!

Maybe you are looking for

  • How to redirect the portal Logon page..IMP

    Hi Frndz.. I want to know how i can change the Portal default logon page, means when ur giving url on browser like http://host:port/irj/portal it  will directs us to default portal logon page that we r familiar. As per my requirement when we call the

  • Can we able to create a scenario in XI like, RFC to JDBC

    Hello, I want to know whether  there is any way to create a scenarion like RFC to JDBC. RFC sends a rfc call with some parameters on sender side. JDBC stores the data in the receiver side. Thanks , Prakash

  • Recognizing change in client IP during an ARD session ?

    Let's assume I work on a client computer over the Internet (WAN) by using its hostname (e.g. server1.domain.tld). The computer is not within our LAN and can be only accessed via its hostname (respectively its IP). In the case the IP address of the re

  • Question about message driven bean

    hello i can find tons of tutoriala about developing session bean and entity bean by using jdeveloper,but can't find even one article that tell me how to develop message driven bean and jms by using jdeveloper,who can help me,where can i find such tut

  • PI Clients

    We have 2 clients in PI system. Client 100 & 001 (apart from 000 & 066). We know that 001 is a special client for PI where SAPJSF users and all PI specific roles are available. Soon after installation I created business client 100 and copied users(SA