Running via PHP

Introduction to StampPDF Batch via PHP

StampPDF Batch can easily be run from user-written php code using the AppligentStampPDF Class. (.ZIP download includes all available Appligent PHP classes and sample code).

The class is freely available to any trial or licensed user of StampPDF Batch.

This page documents the class, and is updated as the StampPDF Batch application is updated.

How to call StampPDF Batch with PHP

The AppligentStampPDF class is a “wrapper” function, packaged to allow the PHP developer to easily run StampPDF Batch from any PHP script.

Here’s an example PHP script including the AppligentStampPDF class:

<?php
	error_reporting(E_ALL);
	ini_set('display_errors',true);

	require_once('AppligentStampPDF.php');

//
//this a sample code to demonstrate how to
//use the AppligentStampPDF class
//

//instantiate an instance of the PhpStamp class
	$myStamper = new AppligentStampPDF();

//specify the path to the StampPDF application
	$myStamper->SetApplicationPath('./');

//specify parameters to be passed to the application
	$myStamper->SetStampFile('stampfile.txt');
	$myStamper->SetInputFile('infile.pdf');
	$myStamper->SetOutputFile('outfile.pdf');
	$myStamper->SetLogFile('log.txt');
	$myStamper->SetShowProgress(true);
	$myStamper->SetNoPrint(true);
	$myStamper->SetEncrypt(true);
	$myStamper->SetNewOwnerPass('me');
	$myStamper->SetNewUserPass('you');

//enable the line below to examine the command line
	//$myStamper->SetDebugMode(true);

//run StampPDF Batch
	$appRet = $myStamper->Run($appOutput);

//output information about the run
	if ($appRet == 0)
		print "success\n";
	else
		print "failure\n";

	print "application output:\n";
	print_r($appOutput);
?>

To use the AppligentStampPDF class functions, one must first indicate that the class is to be included in the current module; we perform this with the require_once statement:

require_once('AppligentStampPDF');

Next we instantiate the AppligentStampPDF class with php’s new function:

$myStamper = new AppligentStampPDF();

AppligentStampPDF Methods Overview

Free PHP classesThe AppligentStampPDF object needs information about what needs to be done. There are several built in methods of the class listed in the following table. A detailed description of each method follows the table.

Process Options (details)

Method Function Required
SetStampFile Specify the text stamp file Yes*
SetRemoveOldStamps Remove stamps with UndoLabel No
SetBatesCharCount Specify number of characters in Bates numbers No

* – SetStampFile is mutually-exclusive with SetRemoveOldStamps

Security Options (details)

Method Function Required
SetEncrypt Encrypt output file No
SetKeylength Specify key length No
SetNewOwnerPass Specify new owner password No
SetNewUserPass Specify new user password No
SetNoPrint Do Not Allow Printing No
SetNoModify Do Not Allow Modifying the Document No
SetNoCopy Do Not Allow Copying text or graphics No
SetNoNotes Do Not Allow Adding or changing notes or form fields No
SetNoFill Do Not Allow Fill or Sign of Form Fields No
SetNoAccess Do Not Allow Accessibility No
SetNoAssembly Do Not Allow Document Assembly No
SetNoHighRes Do Not Allow High Resolution Printing No

General Options (details)

Method Function Required
SetApplicationPath Specify the location of the StampPDF Batch product. Yes
SetInputFile Specify the input pdf document Yes
SetOutputFile Specify the output pdf document Yes
Run Run the StampPDF Batch application with the parameters provided Yes
SetOwnerPass Specify owner password to open this document No
SetIncrementalSave Save using an incremental save No
SetLinearize Linearize to support byte serving across the web No
SetOptimize Optimize the output file to try to reduce file size No
SetNocomp Do not compress using Object Streams No
SetComp Compress using Object Streams No
SetIso32000 Set file for ISO 32000 compliance No
SetLicenseCode Specify the license code for StampPDF Batch No**
SetLogFile Specify the log file No
SetOptionalCmds Pass command-line style optional commands to object No
SetDebugMode Enable debugging features No
SetShowProgress Show progress information No
SetShowVersion Show application version No
SetCommandLine Pass entire command line to object. No

** – This method is not required if StampPDF Batch has been installed using the standard installation mechanism (as of version 5.0). 

AppligentStampPDF Method Descriptions

Process Options

SetStampFile

Specify the stamp file, a text file that specifies how stamps are to be applied to your document.  Stamp files include two main components; an options block specifying general stamp properties and one or more stamp items that contain parameters describing a particular stamp.

Syntax:

 void SetStampFile(string $path-to-stamp-file)

Returns: nothing

Example:

$myStamper->SetStampFile('stampfile.txt');

SetRemoveOldStamps

Remove old stamps with UndoLabel

Syntax:

void SetRemoveOldStamps(string $undo-label)

Returns: nothing

Example:

$myStamper->SetRemoveOldStamps('undo_label');

SetBatesCharCount

Specify number of characters in Bates numbers

Syntax:

void SetBatesCharCount(int $num-chars)

Returns: nothing

Example:

$myStamper->SetBatesCharCount(4);

Security Options

SetEncrypt

Encrypt output file using standard Acrobat security.

Syntax:

void SetEncrypt(bool $flag)

Returns: nothing

Example:

$myStamper->SetEncrypt(true);

SetKeylength

Specify encryption key length. Valid options are 40 and 128.  Default is 128.

Syntax:

void SetKeylength(int $keylen)

Returns: nothing

Example:

$myStamper->SetKeylength(128);

SetNewOwnerPass

Specify new owner password

Syntax:

void SetNewOwnerPass(string $ownerPass)

Returns: nothing

Example:

$myStamper->SetNewOwnerPass('ownerpass');

SetNewUserPass

Specify new user password

Syntax:

void SetNewUserPass(string $userPass)

Returns: nothing

Example:

$myStamper->SetNewUserPass('userpass');

SetNoPrint

Do not allow printing

Syntax:

void SetNoPrint(bool $flag)

Returns: nothing

Example:

$myStamper->SetNoPrint(true);

SetNoModify

Do not allow modifying the document

Syntax:

void SetNoModify(bool $flag)

Returns: nothing

Example:

$myStamper->SetNoModify(true);

SetNoCopy

Do not allow copying text or graphics

Syntax:

void SetNoCopy(bool $flag)

Returns: nothing

Example:

$myStamper->SetNoCopy(true);

SetNoNotes

Do not allow adding or changing notes or form fields

Syntax:

void SetNoNotes(bool $flag)

Returns: nothing

Example:

$myStamper->SetNoNotes(true);

SetNoFill

Do not allow fill or sign of form fields

Syntax:

void SetNoFill(bool $flag)

Returns: nothing

Example:

$myStamper->SetNoFill(true);

SetNoAccess

Do not allow accessibility

Syntax:

void SetNoAccess(bool $flag)

Returns: nothing

Example:

$myStamper->SetNoAccess(true);

SetNoAssembly

Do not allow document assembly

Syntax:

void SetNoAssembly(bool $flag)

Returns: nothing

Example:

$myStamper->SetNoAssembly(true);

SetNoHighRes

Do not allow high resolution printing

Syntax:

void SetNoHighRes(bool $flag)

Returns: nothing

Example:

$myStamper->SetNoHighRes(true);

General Options

SetApplicationPath

Specify the location of the StampPDF Batch product.

Syntax:

void SetApplicationPath(string $path-to-product)

Returns: Nothing

Example:

$myStamper->SetApplicationPath('/usr/local/bin/');

Note: The given string should be an absolute path to the product location, and must contain the trailing ‘/’ character.

SetInputFile

Specify the input pdf document

Syntax:

void SetInputFile(string $path-to-input-doc)

Returns: nothing

Example:

$myStamper->SetInputFile('infile.pdf');

SetOutputFile

Specify the output pdf document

Syntax:

void SetOutputFile(string $path-to-output-doc)

Returns: nothing

Example: 

$myStamper->SetOutputFile('outfile.pdf');

Run

Run the StampPDF Batch application with the parameters previously provided

Syntax:

int Run($appOutput)

Parameters: $appOutput – an array created by the Run() method that, upon completion, will contain any messages generated by the application.

Returns: an integer value returned by the application to the command shell.  A value of zero indicates normal execution of the product.  A non-zero value means the application encountered errors during processing, in which case the $appOutput array will contain error messages and other relevant information.

Example:

$appRet = $myStamper->Run($appOutput);
if ($appRet == 0)
//successful completion
else
//an error occurred - the $appOutput array should be examined for details

SetOwnerPass

Specify owner password to open this document. This method is required when processing PDF files that have open password security enabled.

Syntax:

void SetOwnerPass(string $passwordStr)

Returns: nothing

Example:

$myStamper->SetOwnerPass('ownerpass');

SetIncrementalSave

Save using an incremental save.  This method is faster, but results in a larger PDF file.

Syntax:

void SetIncrementalSave(bool $flag)

Returns: nothing

Example:

$myStamper->SetIncrementalSave(true);

SetLinearize

Linearize to support byte serving across the web.  This function is also known as “Fast Web View”.

Syntax:

void SetLinearize(bool $flag)

Returns: nothing

Example:

$myStamper->SetLinearize(false);

SetOptimize

Optimize the output file to try to reduce file size.

Syntax:

void SetOptimize(bool $flag)

Returns: nothing

Example:

$myStamper->SetOptimize(true);

SetNocomp

Do not compress using Object Streams. (compatible with all versions of Adobe Acrobat and Reader)

Syntax:

void SetNocomp(bool $flag)

Returns: nothing

Example:

$myStamper->SetNocomp(true);

SetComp

Compress using Object Streams. (Output PDFs require Acrobat 6.x and later)

Syntax:

void SetComp(bool $flag)

Returns: nothing

Example:

$myStamper->SetComp(false);

SetIso32000

Set file for ISO 32000-1 compliance.

Syntax:

void SetIso32000(bool $flag)

Returns: nothing

Example:

$myStamper->SetIso32000(false);

SetLicenseCode

Specify the license code for StampPDF Batch.  If the standard installation method (version 5.0 and later) has been used, this method is not required.

Syntax:

void SetLicenseCode(string $product-license-code)

Returns: nothing

Example:

$myStamper-> SetLicenseCode('xxxx-xxxx-xxxx-xxxx-xxxx-xxxx');

SetLogFile

Specify the log file

Syntax:

void SetLogFile(string $path-to-log-file)

Returns: nothing

Example:

$myStamper-> SetLogFile('logfile.txt');

SetOptionalCmds

Pass command-line style optional commands to object

Syntax:

void SetOptionalCmds(string $cmd-to-product)

Returns: nothing

Example:

$myStamper->SetOptionalCmds('-p -l logfile.txt');

SetDebugMode

Enable debugging features. When debug mode is enabled, rather than execute the StampPDF application, the Run() method, when called, will output the fully assembled command line to the terminal for examination.

Syntax:

void SetDebugMode(bool $mode);

Returns: nothing

Example:

$myStamper-> SetDebugMode(true);

SetShowProgress

Show progress information.

Syntax:

void SetShowProgress(bool $flag);

Returns: nothing

Example:

$myStamper->SetShowProgress(true);

SetShowVersion

Show application version

Syntax: 

void SetShowVersion(bool $flag);

Returns: nothing

Example:

$myStamper-> SetShowVersion(true);

SetCommandLine

Pass entire command line to object. For those already familiar with the command line syntax of StampPDF Batch, this method allows the user to pass a command line into the object. Please refer to the description of the Run method above for more information.

Syntax:

void SetOptionalCmds(string $cmd-to-product)

Returns: nothing

Example:

$myStamper->SetOptionalCmds('-o outfile.pdf stampfile.txt infile.pdf');
$appRet = $myStamper->Run($appOutput);