'-------------------------------------------------------------------------------- ' Copyright (c) 2001-2008 by PDFTron Systems Inc. All Rights Reserved. '-------------------------------------------------------------------------------- Imports System Imports System.Runtime.InteropServices Module Module1 Public Delegate Function PageMasterCallback(ByVal mode As Integer, ByVal msg As String, ByVal user_data As IntPtr) As Int32 ' The following three lines import the PageMaster functions from pagemaster.dll (via PInvoke). _ Public Function PageMasterInit(ByVal user_name As String, ByVal company As String, ByVal license_key As String) As Integer End Function _ Public Function PageMasterRun(ByVal command_str As String, ByVal funct As PageMasterCallback, ByVal user_data As IntPtr) As Integer End Function ' Return Error codes for PDF2ImageRun function. Dim PAGEMASTER_OK As Integer = 0 ' No errors Dim PAGEMASTER_ERR As Integer = 1 ' Unspecified error Dim PAGEMASTER_ERR_BADKEY As Integer = 2 ' Bad license key Dim PAGEMASTER_ERR_DIRCREATE As Integer = 3 ' Failed to create the output directory Dim PAGEMASTER_ERR_BADFILENAME As Integer = 4 ' Bad input filename or path Dim PAGEMASTER_ERR_NOOUTFILE As Integer = 5 ' Output file not specified Dim PAGEMASTER_ERR_READINGPDF As Integer = 6 ' error reading the input document Dim PAGEMASTER_ERR_PASSWORD As Integer = 7 ' document is secured. bad password. Dim PAGEMASTER_ERR_WRITE As Integer = 8 ' error writing an output file or folder Dim PAGEMASTER_ERR_NOINPUTFILES As Integer = 9 ' no input files found ' You can modify the following lines with your registration information. Dim username As String = "John Doe" Dim company As String = "My Company" Dim lic_key As String = "my license key" Dim PAGEMASTER_ERROR As Integer = 1 ' Show the error message Dim PAGEMASTER_MSG As Integer = 2 ' Report the message Dim PAGEMASTER_GETPASS As Integer = 3 ' Get the password Dim PAGEMASTER_OUT_FILENAME As Integer = 4 ' Get the saved filenames ' A custom callback that can be used to report errors and other messages. Public Function MyCallback(ByVal mode As Integer, ByVal msg As String, ByVal user_data As IntPtr) As Int32 If mode = PAGEMASTER_ERROR Then Console.WriteLine("Error: {0}", msg) ElseIf mode = PAGEMASTER_MSG Then Console.Write("{0}", msg) 'gl_pass = Console.ReadLine(); ' return gl_pass.c_str(); ElseIf mode = PAGEMASTER_GETPASS Then ElseIf mode = PAGEMASTER_OUT_FILENAME Then If user_data.ToInt32 <> 0 Then Dim gch As GCHandle = GCHandle.op_Explicit(user_data) Dim list As ArrayList = CType(gch.Target, ArrayList) list.Add(msg) End If End If Return 0 End Function Sub Main(ByVal args() As String) Dim mycbk As PageMasterCallback mycbk = AddressOf MyCallback PageMasterInit(username, company, lic_key) ' Variable used to switch between different code samples. Dim example As Integer = 1 If example = 1 Then ' The simplest PDFSecure program: Pass an explicit command-line string. ' ' This example will secure all PDF documents in 'TestFiles' using ' 128-bit encryption. The password required to open processed files is ' 'secret'. ' ' - The ‘-o’ parameter is used to specify the output folder/file. ' - The ‘-s’ parameter specifies that the output document should be encrypted ' using 128-bit RC4 encryption. ' - The ‘-u’ parameter specifies the password required to access the secured ' document. ' ' For a detailed explanation of all commands, please refer to PDFSecure ' User Manual. Dim str As String = "-s --digits 2 -o TestOutput/test1/ TestFiles/bookmark.pdf" PageMasterRun(str, mycbk, New IntPtr(0)) ElseIf example = 2 Then ' An example of how to use PDFSecure SDK to implement a command-line ' application for processing of PDF documents. Dim s As String = "" Dim arg As String For Each arg In args s += arg s += " " Next PageMasterRun(s, mycbk, New IntPtr(0)) ElseIf example = 3 Then Dim linearized_output As Boolean = True Dim aes_encryption As Boolean = False Dim output_file As String = "TestOutput/test3/test.pdf" Dim open_password As String = "mypass" Dim title As String = "My Title" Dim author As String = "Joe Doe" Dim subject As String = "My Subject" Dim keywords As String = "key1 key2 key2" Dim creator As String = "PDFTron PDFNet" Dim producer As String = "PageMaster" ' Permissions Dim printing As Boolean = False Dim high_rez_printing As Boolean = False Dim doc_modifications As Boolean = True ' Changing the document Dim content_extraction As Boolean = True Dim commenting As Boolean = True Dim forms_editing As Boolean = True Dim accessibility As Boolean = True Dim document_assembly As Boolean = True ' Given the above settings build a command string. Dim s As String = "" 'specify the merge option s += "-m " If Not (output_file = "") Then s += "-o " + output_file + " " End If If Not (open_password = "") Then s += "--userpass " + open_password + " " End If If aes_encryption Then s += "--AES " End If ' Set the permissions. s += "-e a -d """ If printing = False Then s += "p" End If If high_rez_printing = False Then s += "h" End If If doc_modifications = False Then s += "m" End If If content_extraction = False Then s += "c" End If If commenting = False Then s += "o" End If If forms_editing = False Then s += "f" End If If accessibility = False Then s += "x" End If If document_assembly = False Then s += "s" End If s += """ " If linearized_output Then s += "-l " End If ' Set document information. If Not (title = "") Then s += "--settitle """ + title + """ " End If If Not (author = "") Then s += "--setauthor """ + author + """ " End If If Not (subject = "") Then s += "--setsubject """ + subject + """ " End If If Not (keywords = "") Then s += "--setkeywords """ + keywords + """ " End If If Not (creator = "") Then s += "--setcreator """ + creator + """ " End If If Not (producer = "") Then s += "--setproducer """ + producer + """ " End If ' specify input files and folders... s += "TestFiles/Bookmark.pdf,1-15 " s += "TestFiles/secured.pdf|test " s += "--verb 10" 'An ArrayList to store the paths of saved files Dim saved_files As New ArrayList 'Get a handle for the ArrayList so that it 'can be used in the MyCallback function Dim gch As GCHandle = GCHandle.Alloc(saved_files) ' Execute the command string. PageMasterRun(s, mycbk, GCHandle.op_Explicit(gch)) gch.Free() 'print the saved file(s) Console.WriteLine("The Saved Files Are:") For i As Integer = 0 To saved_files.Count - 1 Console.WriteLine(saved_files(i)) Next End If Console.WriteLine("Done.") End Sub End Module