' Copyright (c) 2021 ActivePDF, Inc. ' ActivePDF Toolkit 2017 ' Example generated 01/18/21 Imports System ' Make sure to add the ActivePDF product .NET DLL(s) to your application. ' .NET DLL(s) are typically found in the products 'bin' folder. Public Class Examples Sub Example() Dim strPath As String, intOpenOutputFile As Integer, intOpenInputFile As Integer, StampFontName As String, _ StampFontSize As Single, StampeFontText As String, StampLocationX As Single, StampLocationY As Single, _ TotalPages As Integer, CurrentPage As Integer, PageRotation As Integer, intGetBoundingBox As Integer, _ PageHeight As Integer, PageWidth As Integer, intCopyForm As Integer strPath = AppDomain.CurrentDomain.BaseDirectory ' Instantiate Object Dim oTK As APToolkitNET.Toolkit = New APToolkitNET.Toolkit() ' Create the new PDF file intOpenOutputFile = oTK.OpenOutputFile(strPath & "new.pdf") If intOpenOutputFile <> 0 Then ErrorHandler("OpenOutputFile", intOpenOutputFile) End If ' Open the template PDF intOpenInputFile = oTK.OpenInputFile(strPath & "8rotations.pdf") If intOpenInputFile <> 0 Then ErrorHandler("OpenInputFile", intOpenInputFile) End If ' 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 Then ' Error getting page count of input file ErrorHandler("NumPages", TotalPages) Else ' Loop through all pages of the input file For CurrentPage = 1 To TotalPages ' Get the current page width, height and rotation PageRotation = oTK.GetInputPageRotation(CurrentPage) intGetBoundingBox = oTK.GetBoundingBox("", CurrentPage) If intGetBoundingBox <> 0 Then ErrorHandler("GetBoundingBox", intGetBoundingBox) End If 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 Select Case PageRotation Case 0 oTK.PrintText(StampLocationX, StampLocationY, StampeFontText, CurrentPage) Case 90 oTK.PrintText(PageWidth - StampLocationY, StampLocationX, StampeFontText, CurrentPage) Case 180 oTK.PrintText(PageWidth - StampLocationX, PageHeight - StampLocationY, StampeFontText, CurrentPage) Case 270 oTK.PrintText(StampLocationY, PageHeight - StampLocationX, StampeFontText, CurrentPage) Case Else ErrorHandler("Page Rotation", PageRotation) End Select ' Copy the current page to the output file intCopyForm = oTK.CopyForm(CurrentPage, CurrentPage) If intCopyForm <> 1 Then ErrorHandler("CopyForm", intCopyForm) End If Next End If ' Close the new file to complete PDF creation oTK.CloseOutputFile() ' Release Object oTK.Dispose() ' Process Complete WriteResults("Done!") End Sub ' Error Handling ' Error messages written to debug output Sub ErrorHandler(ByVal strMethod, ByVal RtnCode) WriteResults(strMethod + " error: " + rtnCode.ToString()) End Sub ' Write output data Sub WriteResults(content As String) ' Choose where to write out results ' Debug output 'System.Diagnostics.Debug.WriteLine("ActivePDF: * " + content) ' Console Console.WriteLine(content) ' Log file 'Using tw = New System.IO.StreamWriter(AppDomain.CurrentDomain.BaseDirectory & "application.log", True) ' tw.WriteLine("[" + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "]: => " + content) 'End Using End Sub End Class