« Older Entries Newer Entries » Subscribe to Latest Posts

23 Sep 2010

Reading PDF Form Fields with VBA

Posted by khk. 26 Comments

Update:

Please visit the same post on my business site. The comments are closed here, so if you want to comment, you have to head over to http://khkonsulting.com/2010/09/reading-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.

18 Aug 2010

Multiple Flickr Publishing Services in Lightroom 3

Posted by khk. No Comments

One day you need your Flickr uploads resized to 1000×1000 pixels, the next day you need to allow only friends and family access to your uploads – is there a way to make the Flickr upload more streamlined from within Lightroom?

Since the release of Lightroom 3 there is a convenient Flickr publishing service built right into the application, and with a few mouse-clicks users can upload any selection of images stored in the Lightroom catalog.

Thanks to the foresight of the designers of the application (or the beta testers), it is possible to set up multiple Flickr publishing services with different settings. In the following tutorial I will demonstrate how that is done. At first we’ll look at the long and complicated (no, not really) method – which you need to create your initial Flickr publishing service, but can also be used for the second, third and so on service. Then we’ll use a shortcut to create the “other” publishing services.

It does not matter if you’ve already set up one Flickr publishing service, or if you are starting from scratch, the process is the same. When you look at the left panel in Lightroom, you will see the “Publish Services” category with a little “+” sign to the right of the category title – plus a small triangle that indicates that there is a menu hidden behind the plug sign.

Lightroom_Flickr_Export_1.png

Once you click on that plus sign, the menu will be displayed. Select the “Go to Publishing Manager…” menu item, which will display the …

Lightroom_Flickr_Export_2.png

… “Lightroom Publishing Manager” dialog.

Lightroom_Flickr_Export_3.png

Right below the list of “Publish Services” on the left side is the “Add” button to add new services to the list. Click on that and specify the details for the new service.

Lightroom_Flickr_Export_4.png

That’s it. Now just drag&drop your images on one of the Flickr publishing services, and once you are done, select to actually publish the images by right-clicking on the Photostream (or your custom photo set) and select to “Publish Now”:

Lightroom_Flickr_Export_6.png

So, now that we know the long way, here is a shortcut: Once you have your first Flickr publishing service installed, just right-click on that publishing service and select “Create Another Publish Service via ‘Flickr'”:

Lightroom_Flickr_Export_5.png

After that, just follow the instructions above to setup the service.

18 Aug 2010

Best Way to Learn Acrobat Scripting

Posted by khk. Comments Off on Best Way to Learn Acrobat Scripting

Update:

Please visit the same post on my business site. The comments are closed here, so if you want to comment, you have to head over to http://khkonsulting.com/2010/08/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).

7 Jun 2010

Crocosmia

Posted by khk. 1 Comment

Crocosmia

17 May 2010

The Small Show Is Back!

Posted by khk. Comments Off on The Small Show Is Back!

It’s this time of the year again: The Small show at the High Falls Art Gallery in Rochester, NY Is about to open. Join the artists for the public reception on Sunday, May 23rd from 3 to 6pm.

Swoosh

Here is a link to the PDF version of the invitation.

If you don’t want to download the PDF invitation, here is the important information from the document:

High Falls Art Gallery

Small Works of art no larger than twelve inches

Public Reception Sunday May 23, 2010 3-6pm

Music by Reilly Taylor-Cook and Hershel Mikel Jazz Duo 

7 May 2010

LinkedIn Pet Peeve

Posted by khk. Comments Off on LinkedIn Pet Peeve

Do you let LinkedIn post your tweets automatically as your LinkedIn updates? Here is a reason why that might be a bad idea: If you tweet too much, I may just hide your status updates in LinkedIn completely – not just your tweets, all your status updates!

Chains

In my opinion, when LinkedIn tried to get on the Twitter band wagon, they made a big mistake: When you connect a Twitter account to a LinkedIn account, you have a choice of either automatically posting every tweet to your LinkedIn status, or just the ones that are tagged with the #in or #li hash tag:

LI_Twitter.png

For the latter case, a Twitter user who tweets something that might be appropriate for LinkedIn can tag the tweet with #in and have it show up on LinkedIn automatically. That’s not a bad idea, and I’m fine with that. It gives the user control over what gets shared, and what not. Twitter and LinkedIn (or in general, all the social media platforms one uses) serve a different purpose, and in general it’s not a good idea to post the same message to all these platforms -but sometimes, there is something that should be shared across all services. The hash tag approach gives the user that control.

The “annoy all my LinkedIn connections with my most trivial Twitter drivel” option however really annoys me. One of the most attractive features of Twitter is that tweets have a limited life time. When they don’t show up in the small window of the Twitter timeline that I’m looking at, they don’t exist – unless I’m using search. I don’t have to read them, I don’t have to deal with them, I can safely ignore them. And I do! When they show up in my LinkedIn status updates however, I can no longer ignore them, and even more annoyingly, they push real status updates off the end of that page.

I wish LinkedIn would give me an option to hide all Tweets (or at least those that don’t have #in or #li in them). Because I don’t have that control, I do the next best thing: If your tweets on LinkedIn annoy me, I will hide your status updates.

23 Apr 2010

Is Your Acrobat Plug-in Still Using ADM?

Posted by khk. Comments Off on Is Your Acrobat Plug-in Still Using ADM?

Update:

Please visit the same post on my business site. The comments are closed here, so if you want to comment, you have to head over to http://khkonsulting.com/2010/04/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.

23 Mar 2010

Developing Acrobat JavaScript on a MacBook

Posted by khk. 8 Comments

Update:

Please visit the same post on my business site. The comments are closed here, so if you want to comment, you have to head over to http://khkonsulting.com/2010/03/javascript-console/

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.

8 Mar 2010

Rye Bread

Posted by khk. 1 Comment

For a couple of years now, I’ve been looking for the perfect rye bread recipe. I know, “perfect” is a dangerous term to use, but I think I found a recipe that makes beautiful and tasty bread.

This recipe started out as Daniel Leader’s Czech Country Bread from his book Local Breads: Sourdough and Whole-Grain Recipes from Europe’s Best Artisan Bakers. I like whole grains in my bread, so I experimented with adding different kinds of whole grains – starting with replacing the white rye with whole grain rye, but eventually I ended up with replacing half of the bread flour with white whole wheat flour.

Rye Bread

150g refreshed whole grain rye sourdough starter
300g water
100g white rye flour
200g white whole wheat flour
200g unbleached bread flour
1 tsp yeast
1 1/2 tsp sea salt
1 tbsp wheat gluten
1 tbsp diastatic malt powder

Use a stand mixer to knead all the ingredients into dough (about 8-10 minutes on slow).
Cover the dough and let it rest for about two hours (or until doubled in size).
Give the dough a quick knead and form a loaf.
Cover the dough again and let rise for about 1 1/2 hours.
About one hour into the second rise place a pizza stone in oven on middle rack and a cast iron pan at the bottom of the oven and preheat to 475F.
Sprinkle whole wheat flour on a peel and place the loaf on it.
Score loaf with a very sharp knife.
Place loaf on pizza stone.
Add a cup of ice cubes into the cast iron pan close the door.
Reduce temperature to 425F.
Bake for 45 minutes.
Let the bread cool completely before cutting into it. Yes, I understand that’s hard to do, but it’s important. If you want to eat freshly baked (still hot) bread, make baguettes. There is noting better than a fresh piece of bread with some good butter.

8 Mar 2010

Even More PDF Tools

Posted by khk. 2 Comments

Update:

Please visit the same post on my business site. The comments are closed here, so if you want to comment, you have to head over to http://khkonsulting.com/2010/03/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.

Tags: , , ,