PDF Snake Scripting Tutorial

 

PDF Snake home

scripting reference

table of contents

My First Script

Please copy this code into your own text file, and save it as MyFirst.py.

import
acrobat doc
=
acrobat
.
documentOpen
(
r
'C:\PDFSnake\PDFSnake\docs\tutorial\template.pdf'
)
doc
.
forceVisible
(
)

And now let's break it down line by line:

import
acrobat

This line is needed somewhere in the beginning of all your scripts. It imports the PDF Snake library. This script can only be run from within Acrobat. If you attempt to run this script just using the Python interpreter, this line will throw an exception.

doc 
=
acrobat
.
documentOpen
(
r
'C:\PDFSnake\PDFSnake\docs\tutorial\template.pdf'
)

This line calls the acrobat.documentOpen() function, in order to open a PDF document. If the document exists and is a valid PDF document, then a document object is returned. If the document does not exist or is invalid, then an exception is raised. For those new to Python, note the little r in front of the string which essentially lets us type the path name without worrying about escaping \ (backslash) characters.

doc
.
forceVisible
(
)

Even though this code will open the document, it will not be visible in the Acrobat Viewer. In this case, we want to show it to the user, so we just call the forceVisible() method. If the document is already visible, then this method does nothing.

Next Page >>