<?php // Copyright (c) 2021 ActivePDF, Inc. // ActivePDF Toolkit 2018 // Example generated 03/02/21 ?> <?php // Get current path $strPath = dirname(__FILE__) . "\\"; // Instantiate Object $oTK = new COM("APToolkit.Object"); // 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++) { // Get the current page width, height and rotation $PageRotation = $oTK->GetInputPageRotation($CurrentPage); $intGetBoundingBox = $oTK->GetBoundingBox("", $CurrentPage); if ($intGetBoundingBox != 0) { Error("GetBoundingBox", $intGetBoundingBox); } $PageHeight = $oTK->BBHeight; $PageWidth = $oTK->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 = null; // Process Complete echo "Done!"; // Error Handling function Error($method, $outputCode) { echo "Error in " . $method . ": " . $outputCode; } ?>