Acrobat/PDF Tip: Converting a Document to PDF

Have you ever needed a PDF version of a document, but you either did not have the correct source application (e.g. MS Word, PowerPoint, …), or you didn’t have access to a PDF converter (even though the free PrimoPDF is just a mouse click away). Or, did somebody email you a PowerPoint presentation, but you don’t have access to PowerPoint? But you do have access to a PDF viewer (either the free Adobe Reader, or Preview.app on the Mac). How would you convert a Word, Excel or PowerPoint document to PDF?

Google Docs to the rescue! Did you know that Google Docs can import a number of standard file formats into it’s word processor, spread sheet and presentation applications? Once you have imported your document, you just select to print… That’s it. Oh, I probably should explain that Google converts your document to PDF for printing purposes and then downloads that PDF to your computer. So just open that PDF file, and there is your document, now converted to a portable, easy to open file.

Posted in PDF | Tagged , , , , , | 2 Comments

More Interactive Dynamic Stamps in Seven Easy Steps

A while ago I tried to create an interactive dynamic stamp in Acrobat. These are dynamic stamps (like for example a stamp that automatically puts the current date into a field that is part of the stamp), but with a UI component that pops up and queries the user for some information that also gets embedded as part of the stamp (e.g. a phone number or a name).

I was not very successful. I could not figure out how to make sure that the UI only gets triggered when the stamp gets applied, and not when the stamp file gets loaded by Acrobat.

Continue reading

Posted in Acrobat, PDF | Tagged , , , , | 30 Comments

Acrobat Plug-Ins

If you’ve seen my resume – or talked to me lately, you know that I create Acrobat plug-ins for a living. When people hear that, they usually think something like “Don’t forget to pick up the dry cleaning” or “I need to bring my cat to the vet for the rabies shot”… Yes, I understand, this may not be the most exciting topic, but probably only because you don’t know enough about what these “plug-ins” are, so let me explain.

Conservatory-038

 

Adobe Acrobat is a very powerful tool, more powerful that most users actually realize. I wont go into any details about how powerful exactly – at least not today. Lets just say that it has something for everybody. However, you may need something in addition to what Adobe provides, something that still is in the general area of PDF. Adobe may not have considered your needs because either the target market for “your” feature is too small, or to far out there… Or you are so far ahead of everybody else that they have not even thought about that feature yet.

Adobe did however do a very interesting thing: They created an interface that allows 3rd party developers to create solutions based on Adobe Acrobat – using plug-ins. It is a very powerful interface, and hence not something that you can pick up in an afternoon. There are several thousand pages of API documentation that one needs to understand before a plug-in should be written.

A plug-in is – from a technical point of view – a module or library that gets loaded dynamically at runtime. Acrobat will scan it’s plug-ins directory and will load any modules it finds. Once loaded, such a plug-in can extend Acrobat by e.g. adding menu items, toolbuttons, or event handlers (e.g. a function that gets executed whenever a documents gets loaded).

Conservatory-013

 

Interestingly enough, the plug-ins directory of a fresh Adobe Acrobat installation is not empty… A lot of Acrobat’s functionality is actually implemented as plug-ins. You can verify that on a Windows system by temporarily disabling all plug-ins by holding down the Shift key when bringing up Acrobat. That will load the application without any plug-ins. When you compare the toolbar or the menu bar with a fully loaded application, you’ll see what portion of the Acrobat core functionality is actually implemented in plug-ins.

The plug-in interface has different abstraction levels (COS, PDE, AV, …). If there is enough interest, I will provide information about how to navigate that API, and how to structure a plug-in.

The Acrobat SDK is available for free from Adobe’s Acrobat Development Center.

Here are a few examples of commercially available plug-ins that I’ve used:

  • Enfocus PitStop Professional:
    This is a preflight tool.
  • Quite Imposing Plus:
    The best PDF based imposition tool that I am aware of.
  • Enfocus Browser:
    Allows to review and change the internal structure of a PDF file.
Posted in Acrobat, PDF, Photos, Programming | Tagged , , , , | 7 Comments

Splitting PDF Pages

No, this is not about my patent pending idea of a sheet splitter that turns duplex documents into simplex documents… This post is about a problem that comes up every now and then: When you scan a book or a magazine, chances are that you end up with two physical pages on your scanned image, and your document looks something like this:

JoinedPages.png

Pages one and two are on the same scan, three and four are, and five and six and so on.

How can we split such a combined page into it’s two parts?

There are of course different solutions to this problem, some more complicated than others, some producing better results than others.

The most straight forward approach would be to write an Acrobat plug-in or a standalone application (e.g. using the iText library) that takes the source page, determines what needs to be copied to the new page that should represent the left half of the original page, and then just copy those page elements. With a scanned source document, this would potentially mean that the scanned image needs to be cropped and placed on the target page. Sounds complicated, and it is complicated. Is there an easier way to accomplish the same results?

Continue reading

Posted in Acrobat, PDF, Programming | Tagged , , , | 65 Comments

More PDF Tools

As promised, here are some PDF related tools that I don’t use, but either have used, have played with, or just know about how good they are. These are the tools that I recommend when somebody asks me “what would you use to do XYZ?”.

PrimoPDF

The best free PDF generator. Just see my previous blog post. If you need a PDF generator, download that program.

NitroPDF

From the friendly people who bring you PrimoPDF. This is a package that competes with Acrobat. It can edit PDFs, create forms, fill forms, create PDFs, … And it’s cheaper than Acrobat. There is a free eval version available. Download it, play with it and see if it covers all your PDF needs. If not, there is always Acrobat. An upcoming release will have OCR support (after release 6).

PDF Enhancer

The PDF Enhancer is a very powerful tool to “enhance” PDFs. Enhancement in this case can mean a lot of different things: Make them smaller, fix common PDF problems, embed fonts, add or modify color management information, … There are different versions available, even a server version. Apago also has a free eval version that you can download to see if it fits your needs.

Enfocus PitStop Professional

PitStop is a preflight tool that I used in my previous job. In addition to preflight capabilities, it also implements the Enfocus Certified PDF Workflow that allows a PDF file to contain an audit trail of all operations that were performed on it. In addition to PitStop Professional, Enfocus also offers the PitStop server, which can do anything Pitstop Professional can do in an automated fashion.

Quite Imposing Plus

This is simply the best imposition tool for PDFs. If you need to impose a PDF, Quite Imposing Plus can do it. It is not the easiest tool to work with. One of the best features of it is that you can create sample PDF files with page numbers to figure out how exactly an imposition scheme needs to be set up. Once you’ve figured that out, you can just re-run the same process again on your real document.

PDFLib

PDFLib is a great tool to programatically create PDF files. I’ve used an older version a few years ago. I’ve followed the development of the library over the years, and I still can recommend it as an alternative to iText.

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

My PDF Toolbox (Updated)

What tools am I using to create/process/debug PDF documents? Here is list of my top tools and why I like them.

Adobe Acrobat Pro

This of course is the mother ship, the ultimate tool for creating, processing, editing PDF documents. It’s the solution to problems you did not even know you had… Most people only use a small fraction of the features that Acrobat provides. It’s not cheap, but if you require any of the features that no other tool provides, it’s worth it.

Here are a few tasks that I use Acrobat for:

  • Create
  • If you want the best quality PDF document, how can you go wrong with the Distiller from the people who invented PDF? There are many ways to create PDF files, but for high quality press work, I would not trust any other application.

  • Edit and Process
  • Optimize, preflight, manage colors, insert pages, extract pages, remove pages, change page boxes, create interactive forms… Do I need to say more? Pretty much anything that’s possible with a PDF document can be done with Acrobat. Sure, there are other tools that can do some of these tasks as well, but there is no other tool that covers the broad range of features available in Acrobat.

  • Debug
  • The preflight tool allows to check for syntax errors in PDF files, traverse the internal structure of PDF documents, look at fonts, …

  • Programming
  • I also write software for Acrobat. That’s either done as a plug-in or as JavaScript, for demo purposes I occasionally also write sample VB programs that utilize Acrobat’s Inter-application Communication API.

Adobe Reader

This one is pretty straight forward: I use it to make sure that PDFs created in Adobe Acrobat work correctly when opened in a web browser or directly in Reader. Especially when dealing with forms submission or electronic comments, it is necessary to make sure that Reader behaves correctly.

Ghostscript

Oftentimes it is beneficial to have a non-Adobe PDF renderer. When a PDF file is not behaving correctly, I run the file through Ghostscript to see if it fails in the same way, or if I can get more detailed error messages out of that application. The error messages Acrobat provides are not very verbose, Ghostscript can give me a stack dump, and if necessary I can even run it in the debugger to figure out exactly what’s going on.

XPDF

The same reasons I gave for Ghostscript also apply to XPDF. In addition to that, XPDF also comes with a bunch of tools to extract text or images from a PDF file. Sometimes that functionality comes in handy.

iText

This is a very powerful PDF library for Java. In addition to being very powerful, it’s also relatively easy to use. I have not done anything serious in Java in years (a decade?), but it does not take me long to take iText and whip something up that can almost perform miracles with PDF files. There is also a .NET port available as iTextSharp.

pdftk

pdftk is an application that’s based on iText. Sid Steward took the iText Java source code and run it through a compiler to create a native binary for Windows, Mac OS and Linux. Because of that, pdftk does not require Java anymore. All that’s needed is a supported operating system.

It is a tool to do a number of things with PDF files (concatenate files, break a multi-page file into individual page documents, flatten forms, …). Take a look at the page that lits pdftk sample command lines to learn more about what is supported.

There is a small problem with pdftk: It’s no longer supported, and it cannot handle PDF files that use some of the newer PDF features. Also, there are (at least) two versions that are currently getting distributed: Get the newest one from http://www.pdfhacks.com/pdftk and not the one from AccessPDF. (Update: Both links now have the same version).

Mac OS X

Yes, the Mac operating system does provide some PDF related tools. There is the Preview.app application to display and manipulate PDF files, and there is the “Save as PDF” feature built into the print dialog. Not only can you save “normal” PDF files with just one mouse click, you can create press standards conform PDF/X files.

Enfocus Browser

The Enfocus Browser is two things:

  • An Acrobat plug-in
  • A standalone application

And, it’s these two things for two operating systems: Windows and Mac OS. This tool is indispensable when you are working with the structure of a PDF file. Enfocus released version three of this tool a while ago. I mentioned this tool a couple of times already on my blog:

My Favorite Acrobat 8 Feature

The Enfocus Browser is Back

One of the best features of the Browser is that it allows you to actually modify the PDF structure, however, you better hold back on that until you’ve read the PDF spec a couple of times. It’s very easy to break a PDF file by making just a few changes.

One of the biggest advantages of the standalone version is that I can look at a PDF file that may not open in Acrobat and find out why.

There are a number of other applications that I don’t user personally, but that I do recommend to others because I know how good these apps are. More about that in a future post.

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

Acrobat, JavaScript and VB walk into a bar…

OK, let’s just forget about that old joke and concentrate on how to combine all three into something that is quite useful.

As I’ve described in one of my previous posting, it is quite easy to automate Acrobat from VB or VBA. So how does JavaScript fit into this picture? As you may know, Acrobat comes with a very powerful JavaScript engine that provides access to a lot of functionality – more functions actually than what you have access to from your VB program. So, if you want to access some of these features, but you are stuck with VB, how can you do that?

Adobe provides a VB/JavaScript bridge with Acrobat – the JSObject, and the Acrobat SDK describes how to use that feature.

There is quite a bit of good information in the documentation. When you access the online documentation, expand the tree to “Acrobat Interapplication Communication > Developing Applications Using Interapplication Communication > Using OLE > Using the JSObject interface”.

JavaScript

In this example, I want to illustrate how you can create a folder level JavaScript function, instantiate the JSObject, and then call the custom function and display the result in VB. My plan was to use the JavaScript code from my last posting, but I found one small problem in the way I wrote the code (it works fine as a standalone JavaScript program, but we cannot use it in the VB context), so here is it’s replacement:

function CountBookmarks(bkm, nLevel)
{
    var count = 0;
    if (bkm.children != null)
    {
        count = bkm.children.length;
        for (var i = 0; i < bkm.children.length; i++)
        {
             count += CountBookmarks(bkm.children[i], nLevel + 1);
        }
    }

    return count;
}


function CountAllBookmarks()
{
    console.clear(); console.show();
    var n = CountBookmarks(this.bookmarkRoot, 0);
    console.println("Number of bookmarks found: " + n);

    return n;
}

// add the menu item
app.addMenuItem({
     cName: "countBookmarks",
     cUser: "Count Bookmarks",
     cParent: "Document",
     cExec: "CountAllBookmarks();",
     cEnable: "event.rc = (event.target != null);"
});

Save this JavaScript program as a folder level JavaScript file and make sure that it works.

So, why can't we just implement the whole algorithm with the JSObject? The problem is with how VB handles objects that are actually JavaScript objects - in this case the root bookmark object. I cannot figure out how to access it's "children" property through the JSObject. That's the reason why I'm "cheating" by calling our custom JavaScript function - being able to do that is pretty cool IMHO.

The VB Part

We start out just like with any other VB program, by declaring some objects, initializing them and then it gets interesting...

Here is some sample code that shows how to initialize the JSObject, and how to call our own JavaScript function.

Create a button on an Excel spreadsheet again, and put the following code into the button handler callback (just like before).

Dim gApp As Acrobat.CAcroApp
Dim gPDDoc As Acrobat.CAcroPDDoc
Dim jso As Object

Sub Button1_Click()
    Set gApp = CreateObject("AcroExch.App")
    Set gPDDoc = CreateObject("AcroExch.PDDoc")
    If gPDDoc.Open("c:\temp\test.pdf") Then
        Set jso = gPDDoc.GetJSObject
        MsgBox (jso.CountAllBookmarks())
    End If
End Sub

Now just make sure that you have a file c:\temp\test.pdf that has some bookmarks in it.

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

Counting Bookmarks

Let’s assume you have a PDF document, and you want to know how many bookmarks you have in that document, how would you approach that?

The JavaScript API has methods to traverse the bookmark tree. Here is a short program that – once installed in Acrobat’s JavaScript folder – will add a menu item “Count Bookmarks” to the “Document” menu, and when executed will print the number of bookmarks encountered in the JavaScript console.

function CountBookmarks(bkm, nLevel)
{
    var count = 0;
    if (bkm.children != null)
    {
        count = bkm.children.length;
        for (var i = 0; i < bkm.children.length; i++)
        {
             count += CountBookmarks(bkm.children[i], nLevel + 1);
        }
    }

    return count;
}


function DoIt()
{
    console.clear(); console.show();
    var n = CountBookmarks(this.bookmarkRoot, 0);
    console.println("Number of bookmarks found: " + n);
}



// add the menu item
app.addMenuItem({
     cName: "countBookmarks",
     cUser: "Count Bookmarks",
     cParent: "Document",
     cExec: "DoIt();",
     cEnable: "event.rc = (event.target != null);"
});

Save this program in a file in e.g. C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Javascripts (for Acrobat 9) and restart Acrobat. You should now find a new menu item in the Document menu. Load a file with bookmarks in it, and execute the menu item.

I have not implemented the privileged execution context that is required to make this work in all instances, so you have to go into your JavaScript preferences in Acrobat and check the setting for "Enable menu items JavaScript execution privileges":

PreferencesJavaScript.png
Posted in Acrobat, JavaScript, PDF, Programming | Tagged , , , | 5 Comments

Security Patch for Adobe Acrobat 9 and Reader 9

This is hot off the press: Adobe recommends that you upgrade your Adobe Acrobat 9 or Adobe Reader 9 installation to 9.1: Security Updates available for Adobe Reader 9 and Acrobat 9

Here is what Adobe has to say (among other things) about this patch: “Adobe categorizes this as a critical issue and recommends that users apply the update for their product installations.” More information is available on the page I linked to.

Upgrade! Really!

Posted in Acrobat, PDF | Leave a comment