Example code is for an older version of Toolkit, newer code is available.
<!-- Copyright (c) 2021 ActivePDF, Inc. -->
<!-- ActivePDF Toolkit 2017 -->
<!-- Example generated 02/26/21 -->
<!-- Example uses the .NET DLL which requires -->
<!-- Coldfusion 8 or above -->
<CFSCRIPT>
// Get current path
strPath = ExpandPath(".") & "\";
// Instantiate Object
oTK = CreateObject(".NET", "APToolkitNET.Toolkit", "C:\Program Files\activePDF\Toolkit\DotNetComponent\2.0\APToolkitNET.dll");
// Create the new PDF file
intOpenOutputFile = oTK.OpenOutputFile(strPath & "new.pdf");
if(intOpenOutputFile != 0) {
Error("OpenOutputFile", intOpenOutputFile);
}
// Open the template PDF
intOpenInputFile = oTK.OpenInputFile(strPath & "8rotations.pdf");
if(intOpenInputFile != 0) {
Error("OpenInputFile", intOpenInputFile);
}
// Font and Text variables
StampFontName = "Helvetica";
StampFontSize = 12;
StampeFontText = "Confidential";
StampLocationX = 72;
StampLocationY = 24;
// Get the page count of the input file
TotalPages = oTK.NumPages("");
if(TotalPages < 1) {
// Error getting page count of input file
Error("NumPages", TotalPages);
} else {
// Loop through all pages of the input file
CurrentPage = 1;
for (CurrentPage; CurrentPage <= TotalPages; CurrentPage=CurrentPage + 1)
{
// Get the current page width, height and rotation
PageRotation = oTK.GetInputPageRotation(CurrentPage);
intGetBoundingBox = oTK.GetBoundingBox("", CurrentPage);
if(intGetBoundingBox != 0) {
Error("GetBoundingBox", intGetBoundingBox);
}
PageHeight = oTK.Get_BBHeight();
PageWidth = oTK.Get_BBWidth();
// Set font properties and text rotation
oTK.SetFont(StampFontName, StampFontSize, CurrentPage);
oTK.SetTextColor(255, 0, 0, 0, CurrentPage);
oTK.SetTextRotation(PageRotation);
// Depending on the rotation of the page, adjust coordinates
// This only accounts for rotations of 0, 90, 180, 270
switch(PageRotation)
{
case 0:
oTK.PrintText(StampLocationX, StampLocationY, StampeFontText, CurrentPage);
break;
case 90:
oTK.PrintText(PageWidth - StampLocationY, StampLocationX, StampeFontText, CurrentPage);
break;
case 180:
oTK.PrintText(PageWidth - StampLocationX, PageHeight - StampLocationY, StampeFontText, CurrentPage);
break;
case 270:
oTK.PrintText(StampLocationY, PageHeight - StampLocationX, StampeFontText, CurrentPage);
break;
default:
Error("Page Rotation", PageRotation);
break;
}
// Copy the current page to the output file
intCopyForm = oTK.CopyForm(CurrentPage, CurrentPage);
if(intCopyForm != 1) {
Error("CopyForm", intCopyForm);
}
}
}
// Close the new file to complete PDF creation
oTK.CloseOutputFile();
// Release Object
oTK = 0;
// Process Complete
WriteOutput("Done!");
// Error Handling
Function Error(method, outputCode) {
WriteOutput("Error in " & method & ": " & outputCode);
}
</CFSCRIPT>