Acrobat JavaScripts – Where do they go?

JavaScripts in Acrobat can either be attached to a document – for example to validate a form field – or they can be loaded directly into the application as a folder level script. It’s pretty straight forward to figure out where to put a script that should run when a button is pressed in a form, but where do you install folder level scripts?

In my blog posts, I usually just list one of the paths that you would use for Acrobat running on Windows (e.g. in Splitting PDF Pages). This means that the Mac users are usually left out – which is a bit strange because I am a Mac user. Most Acrobat users are running it on Windows, so that’s why I can take that shortcut without upsetting too many people.

But where would you store these folder level scripts on a Mac – or on Windows if you just want them to be available for one user?

There is an app for that!

Acrobat provides a JavaScript function that returns configuration paths: app.getPath()
The JavaScript for Acrobat API Reference provides information about the getPath function. From that document we learn that there are two different kinds of paths: application level and user level. An application level path would be for all users on a certain computer, whereas a user level path is for one specific user. We can also see that Acrobat can report a number of different paths: root, eBooks, preferences, sequences, documents, javascript, stamps, dictionaries, plugIns, spPlugIns, help, temp, messages, resource and update.

So, to report the application level JavaScript path, we would run the following command in the JavaScript console (and if you want to run this on an Apple laptop, you need the information at “Developing Acrobat JavaScript on a MacBook” to execute a script in the console):

app.getPath("app", "javascript");

And, that command running in Acrobat 9 on a Mac would produce the follwing output:

/Macintosh HD/Applications/Adobe Acrobat 9 Pro/Adobe Acrobat Pro.app/Contents/MacOS/JavaScripts/

So, with this little script, you can find out where to save your JavaScripts regardless of what system you are using – and, you can also find out about other configuration paths in Acrobat.

OK, so it’s not really an app, but it’s easier to use than some apps I’ve seen.

Posted in Acrobat, JavaScript, mac, PDF, Programming | Tagged , , , , | 7 Comments

The X Files: Acrobat Edition

A New Version of Acrobat

Have you noticed that it’s been more than two years since the release of Adobe Acrobat 9? Usually, Adobe releases a new version every 18 to 24 months, so a new version has been overdue. Today they let the cat out of the bag, and announced Acrobat X. There is already a lot of information available about what it is, and to some extend also how it is different from previous releases.

Take a look at the press release to get a quick overview of what’s new, or browse over two Adobe TV and watch the Acrobat X Tips & Tricks episodes. There is a lot of information available to give you a pretty good idea about what’s new and different.

User Interface

If you’ve attended one of my training seminars about Acrobat, you know that one of my pet peeves has always been that Adobe added to the UI clutter with every new release of Acrobat. Yes, every now and then they tried to clean it up, but at the end, it just caused more and more confusion among both novice, but also experienced users.

This time around, they took a completely new approach and ripped out the old menu and toolbar system and replaced it with something completely new. I am still trying to wrap my head around where things are now located, but in general, the new layout is a good idea. It will be much easier for the novice user to explore the UI and find new features that they might want to use, but for users who’ve worked with Acrobat since the early days of the product (in my case since Acrobat 3), it will take a while until we find all the tools that we’ve known by heart. But in the long run, I think it’s a good move, and I am more than willing to go through the learning process to get to know the new UI.

Plug-Ins

Every time Acrobat changed it’s UI in the past, there were major ripple effects through the plug-in community – things just did not work anymore, or not quite right, and we plug-in developers had some work to do to modify our plug-ins so that users could rely on these 3rd party components again.

If you have not yet tested your own plug-ins on an Acrobat X pre-release, don’t waste any time. Chances are that your code needs to be modified to work seamlessly with Acrobat X. If you need help with that, get in touch with me, I am a seasoned plug-in developer and I can certainly assist you with those efforts.

Favorite Feature

I don’t have a favorite new feature, but I have two favorite updated features:

Number one is what Adobe has done with Portfolios. In my opinion, Portfolios were one of the most underused features in Acrobat 9, and I hope that the updates to the Portfolio system will help to give that feature the necessary exposure so that we see more and more of these compound documents.

My number two updated feature is the much improved export function to other file formats. Whenever I had to create a MS Word document out of a PDF file in the past, it was always a hit-or-miss job – some documents worked reasonably well, others didn’t work at all. But regardless of how well it worked, there was always some editing necessary after the export to make the Word file look like the original PDF document. With the new export in Acrobat X, I get Word documents that look exactly like the PDF file. Great job, Adobe!

Posted in Acrobat, PDF | Tagged , , , , | 1 Comment

Reading And Modifying PDF Form Fields with VBA

I’ve written about VBA and Acrobat JavaScript before, and I’ve also mentioned that you can combine VBA and JavaScript to access PDF form fields, but I still owe a sample for that. I had to answer another question today about how to exactly do that, so I whipped up a quick sample program that demonstrates the use of the JavaScript Object (JSO) to read and write AcroForm fields.

We start the same way as in my old VBA sample to create a VBA program that references the Acrobat TLB and to add a button to a document. When we now use the following script as the button handler, we can work with form fields:

Private Sub CommandButton1_Click()
    Dim AcroApp As Acrobat.CAcroApp
    Dim theForm As Acrobat.CAcroPDDoc
    Dim jso As Object
    Dim text1, text2 As String

    Set AcroApp = CreateObject("AcroExch.App")
    Set theForm = CreateObject("AcroExch.PDDoc")
    theForm.Open ("C:\temp\sampleForm.pdf")
    Set jso = theForm.GetJSObject

    ' get the information from the form fields Text1 and Text2
    text1 = jso.getField("Text1").Value
    text2 = jso.getField("Text2").Value

    MsgBox "Values read from PDF: " & text1 & " " & text2

    ' set a text field
    Dim field2 As Object
    Set field2 = jso.getField("Text2")

    field2.Value = 13   ' assign the number 13 to the fields value

    ' get the information from the form fields Text1 and Text2
    text1 = jso.getField("Text1").Value
    text2 = jso.getField("Text2").Value

    MsgBox "Values read from PDF: " & text1 & " " & text2

    theForm.Close

    AcroApp.Exit
    Set AcroApp = Nothing
    Set theForm = Nothing

    MsgBox "Done"
End Sub

This program requires a PDF file with text fields called “Text1” and “Text2” to be stored as C:\temp\sampleForm.pdf. With the explanation in the previous two blog posts, it should not be hard to understand what’s going on here. The only new command introduced is the getField() function, which returns a form field. The form field object has a property “value” which contains the actual value that’s assigned to the field. Give it a try and let me know how it works for you. The updated form field is not saved (because the document does not get saved) – I’ll leave that up to the reader to figure out.

Also, this program will not work with XFA forms (the ones you create in Designer). For those, you need to use the XFA DOM to access the form data. For anybody interested in XFA forms, the LifeCycle Designer ES Scripting Reference is a must read.

Posted in Acrobat, JavaScript, PDF, Programming | Tagged , , , , | 74 Comments

Best Way to Learn Acrobat Scripting

Every now and then I come across the question “What is the best way to learn scripting for Adobe Acrobat? Are there any books or other resources averrable?”. After doing some research, I think I finally found the best resource for beginners and for seasoned Acrobat JavaScript programmers that need a quick tip or a recipe to copy&paste into a project:

PDFScripting.com

The site offers content for both paying members and the general public. If you are new to scripting, and you don’t want to spend the money for a membership (yet), take a look at the free content at ?http://www.pdfscripting.com/public/department40.cfm – it walks you through creating your first AcroForm script, but also offers a number of videos that explain more complicated concepts. For the really good stuff however, you have to pay.

Ever wondered how to hook up a PDF form with an Excel spread sheet? Wonder no more! The article series “Acrobat, PDF and Excel Spreadsheets” teaches you more than you ever wanted to know about that subject.

You may remember my post about dynamic stamps in Acrobat. The PDFScripting.com site has a lot more information about dynamic forms and provides a number of very interesting samples (video link).

There is a ton more information available for both AcroForm and LiveCycle Designer scripting. This information comes in form of articles, videos, a copy&paste script library and downloadable sample files that illustrate a subject.

To get familiar with the web site, Thom Parker has recorded a video tour that helps to navigate the site, but also gives a pretty good overview about what’s available both for free and for paying members at “?Take a tour of the PDFScripting.com website!” (video link).

So, no need to ask me for a good Acrobat scripting resource anymore, just go to PDFScripting.com and sign up for a year – it’s well worth the membership fee (and as Thom says in his tour video, no surprise at the end of the year, the membership does not automatically renew).

Posted in Acrobat, JavaScript, PDF, Programming | Tagged , , , , , | 1 Comment

Is Your Acrobat Plug-in Still Using ADM?

For a few years now Adobe has been telling 3rd party developers that the ADM (Adobe Dialog Manager) will be discontinued, and that existing plug-ins may have to be ported to something else. If I remember correctly, this started with Acrobat 7 or 8, but back then it was a soft threat – everything still worked, and there wasn’t much incentive to start porting plug-ins. However, with the release of the Acrobat 9 SDK the ADM related header files were gone, but ADM based plug-ins were still working (at least some of them).

The removal of the header files does send a strong signal, but what was an even stronger signal for me was that one of the ADM based plug-in I was working on was no longer working correctly on some versions of Windows.

As far as Adobe is concerned, ADM is no longer supported – that means there won’t be any bug fixes for it, but the plug-in has to work with Acrobat 9 on any Windows system that’s supported by Acrobat 9. So, what is a developer to do in such a situation?

Adobe does not give us much guidance in what to chose as a replacement for ADM. The most obvious choice is to stick with the native UI framework that comes with the operating system, but the advantage of ADM was that one could write UI code that would run in both Windows and Mac plug-ins. One of the sample plug-ins – wxPlugin – that comes with the Acrobat SDK is based on wxWidgets. To me that was a pretty strong hint that wxWidgets would be a good choice…

However, even though the Mac version of the SDK does come with the wxPlugin code and even contains a XCode project file, it does not compile. After some work, trying to come up with a combination of wxWidget configuration options and wxPlugin project settings, I was able to create an Acrobat plug-in that worked.

In order to “fix” the Mac’s version of the wxPlugin I first had to compile wxWidgets. Use the following configure command line to create the static wxWidget libraries that can be linked with the project:

configure CC=gcc-4.0 CXX=g++-4.0 LD=g++-4.0 --enable-universal_binary \
--disable-shared --with-macosx-sdk=/Developer/SDKs/MacOSX10.4u.sdk \
--with-mmacosx-version-min=10.4 --enable-debug

Just install the libraries and include files according to the instructions provided by Adobe.

A closer inspection of the plug-in code then revealed that the part that actually did anything was commented out for the Mac with #ifndef MAC_PLATFORM statements, so I removed those and the last thing to do was to remove the reference to the libexpat library – it is provided by the operating system and does not have to be provided by wxWidgets.

With a working environment on the Mac, wxWidgets is a viable alternative for ADM for either new Acrobat plug-ins, or existing plug-ins that need to be modified to make them compatible with the current version of Acrobat.

If your Acrobat plug-ins are still using ADM, now would be a good time to think about what to do about that… If you need any help, let me know.

Posted in Acrobat, mac, PDF, Programming | Tagged , , , , , , | 2 Comments

Developing Acrobat JavaScript on a MacBook

Acrobat’s JavaScript is a great tool to extend the application, or to automate reoccurring tasks. There are several ways a JavaScript can be added to the application or a document (e.g. folder level scripts, validation scripts, event handling scripts, …), but regardless of how a script is written, chances are that the developer wants to test parts of the script in Acrobat’s Javascript console. This console window can be shown by either using the “Advanced>Document Processing>JavaScript Debugger…” menu item or Ctrl-J on Windows or Cmd-J on a Mac:

JS_Menu.png

After the console or debugger window comes up, the user can then enter Javascript and execute it…

JS_Debugger.png

… that is, as long as a full keyboard with a numeric keypad is used. In Adobe’s documentation, we find the following instructions to execute Javascript typed into the console window:

The JavaScript console allows you to evaluate single or multiple lines of code. There are three ways to evaluate JavaScript code while using the interactive console:

  • To evaluate a portion of a line of code, highlight the portion and press either the Enter key on the numeric keypad or press Ctrl + Enter.
  • To evaluate a single line of code, make sure the cursor is positioned on that line and press either the Enter key on the numeric keypad or press Ctrl + Enter.
  • To evaluate multiple lines of code, highlight those lines and press either the Enter key on the numeric keypad or press Ctrl + Enter.

That works fine as long as you have access to the numeric keypad, but on a MacBook or a MacBook Pro without that keypad. No key combination involving fn, ctrl, cmd or option with the Return or Enter key will result in the Javascript getting executed.

The virtual keyboard to the rescue: Mac OS comes with a handy keyboard viewer that allows us to send the correct key code to the application. To bring up the keyboard viewer, bring up the Mac OS System Preferences first and select the “Keyboard” category:

KeyboardViewer_1.png

Make sure that the option “Show Keyboard & Character Viewer in menu bar” is selected. Once this is done, you can access the keyboard viewer from the menu bar:

KeyboardViewer_2.png

Now comes the tricky part: Write some Javascript in the console window and place the cursor on the line you want to execute or select the snippet of the Javascript that should be executed. In the following example I’m using code from Adobe’s Javascript API documentation:

	var menuItems = app.listMenuItems()
	for( var i in menuItems)
		console.println(menuItems[i] + "\n")

With the console prepped, bring up the keyboard viewer and start pushing keys – real keys that is: Hold down the “fn” and the “control” key, then move the mouse pointer to the “Enter” key on the keyboard viewer and click it…

JS_Debugger_6.png

… and voila, the script gets executed:

JS_Debugger_7.png

This is not the most straight forward method, but at least it’s possible to use the Javascript console to execute code when using a MacBook.

Posted in Acrobat, Apple, JavaScript, mac, PDF, Programming | Tagged , , , , , | 9 Comments

Even More PDF Tools

I wrote about my favorite tools around the PDF file format in the past. It’s time to add a couple more items to the list.

Over the last few months I’ve been working with two more products that I can recommend wholeheartedly:

PD4ML

There are a number of HTML to PDF converters available, but if your HTML is anything but basic, chances are that every single one of them does not render one or more features in your documents accurately enough… After looking at a number of them, I came across PD4ML and it looked good right from the first document I fed to it. There were a few problems, but PD4ML’s support was great in helping me out, even though I only had an evaluation license. At the end, all known problems were taken care of in the next formal release I received.

PD4ML is available as either a Java library or a .NET component. The Java JAR can actually be used as an application to get a good idea about how the generated PDF would look.

The library is available in a standard and a Pro version – there are a number of differences, which are listed in the “Products Comparison Chart” – the most important difference for me is that the Pro version supports font embedding.

ABCpdf

As I’ve mentioned before, I’m a fan of iText (mainly because it’s Java based, and I can use it on any system that has a Java VM), but I was looking for a library that had rasterization capabilities. I found ABCpdf, and it’s a great tool that does everything I want a PDF library to do (as long as I can use .NET, ASP or VB). It can read PDF documents, modify them and write them out again, create PDF documents from scratch, convert other formats to PDF (e.g. HTML – even with FLash support, EPS, XPS, SVG). It can even use OpenOffice.org to import MS Office documents. One of the more important features for me is the ability to access low level PDF objects – either to get more information about the PDF file and it’s objects, or to make changes that are not available via other high level calls. ABCpdf also allows me to do that.

ABCpdf comes in two versions, Standard and Professional. The “PDF Component Comparison Chart” on the web site lists the differences between the two versions.

Posted in PDF | Tagged , , , | Leave a comment

Nuance PDF Reader

Nuance (the people behind OmniPage and Dragon Naturally Speaking and a bunch of other things) release a competitor to the free Adobe Reader – the free Nuance PDF Reader (http://www.nuance.com/imaging/products/pdf-reader.asp). The feature list looks very promising:

  • Fill and save PDF forms
  • Annotate PDFs
  • Convert PDF files to Word Excel or RTF
  • Can disable JavaScript
  • 100% compatibility with Adobe Acrobat (we have to wait to see how compatible it really is)
  • Supports PDF Portfolios

Now to the things that it does not do:

  • No support for Mac OS X or Linux
  • No participation in online document reviews

I’ve not spent enough time with it yet to offer a detailed review, but it’s certainly a good alternative to the Adobe Reader. Competition is a good thing, maybe Adobe will take a few cues from Nuance for their next release of Reader.

Posted in Acrobat, PDF | Tagged , , , , , | Leave a comment

AnyBizSoftware PDF To PowerPoint Converter – Free Today – Expired!

Converting PDF documents to PowerPoint presentations is probably not something you need every day. I think I needed it once when the original PowerPoint file of a presentation I needed to give was no longer available, but the PDF file created from that presentation was. I did not have access to AnyBizSoft PDF to PowerPoint Converter back then, so a lot of copy&pasting took place.

Today you can download a free version of that software from GiveAwayOfTheDay.com. I’ve played around with the application a little, and it really does what it promises: PDF elements get converted to editable PowerPoint page elements.

Here is a list of the key features of AnyBizSoft PDF to PowerPoint Converter:

  1. Convert PDF files to PPT presentations quickly and accurately
  2. Retain all the layouts, images, and hyperlinks in the output documents
  3. Produce an editable and dynamic PPT presentation with a few clicks
  4. Convert up to 200 PDF files at the same time
  5. Support Office 2010 and Windows 7

I cannot vouch for the last two list items, but I know that it worked for up to seven files, and that all the other claims are true. If you think you’ll ever need to convert a PDF file to PowerPoint, give AnyBizSoft PDF Converter a try – and if you do it (download and activate) today from GiveAwayOfTheDay.com it will not even cost you a dime.

Posted in PDF | Tagged , , , | 2 Comments

Teaching Adobe Reader a Few New Tricks

Have you ever tried to fill a PDF form in Adobe Reader and to then save that filed document to your hard disk? Did it work? Chances are that it did not.

Have you ever thought about why the Adobe Reader is called “Reader”? The answer is pretty obvious, it’s because it is only reading and displaying (and printing) PDF files – that is, it is not writing them. That also includes that it will not save a modified document. You would need the “Adobe Writer” – or “Adobe Acrobat” as it is called for that.

But regardless of the name, we can “trick” the Reader into writing a filled form to the disk. OK, it’s not really a trick, Adobe did implement this feature, so it’s official, and we are not hacking or cracking anything.

Continue reading

Posted in Acrobat, PDF | Tagged , , , , , | 1 Comment