Example #1
0
 // List the fields for the input PDF. A list of available FieldInfo
 // properties can be found in the online Toolkit SDK documentation.
 public static void WriteFieldInfo(APToolkitNET.FieldInfo FieldInfo)
 {
     if (FieldInfo != null)
     {
         Console.WriteLine($"Field: {FieldInfo.Name}");
         Console.WriteLine($"  Width: {FieldInfo.Width}");
         Console.WriteLine($"  Height: {FieldInfo.Height}");
         Console.WriteLine($"  Lower Left Coordinate: ({FieldInfo.Left}, {FieldInfo.Bottom})");
         Console.WriteLine();
     }
 }
Example #2
0
    public static void Example()
    {
        int    intOpenOutputFile;
        string strPath;
        int    intOpenInputFile;
        int    intCopyForm;
        string memPDF;
        int    intMergeFile;

        strPath = System.AppDomain.CurrentDomain.BaseDirectory;

        // Instantiate Object
        APToolkitNET.Toolkit oTK = new APToolkitNET.Toolkit();

        // Here you can place any code that will alter the output file
        // Such as adding security, setting page dimensions, etc.

        APToolkitNET.FieldInfo oFI = oTK.FieldInfo("name", 1);

        string TKversion = oTK.ToolkitVersion;


        // Create the new PDF file in memory
        intOpenOutputFile = oTK.OpenOutputFile("MEMORY");
        if (intOpenOutputFile != 0)
        {
            ErrorHandler("OpenOutputFile", intOpenOutputFile);
        }

        //convert pdf to byte array
        byte[] bytes = System.IO.File.ReadAllBytes(strPath + "form.pdf");

        oTK.InputByteArray = bytes;



        // Open the template PDF
        intOpenInputFile = oTK.OpenInputFile("MEMORY");
        if (intOpenInputFile != 0)
        {
            ErrorHandler("OpenInputFile", intOpenInputFile);
        }


        // Here you can call any Toolkit functions that will manipulate
        // the input file such as text and image stamping, form filling, etc.


        short formCount = oTK.CountFormFields();

        Console.WriteLine(TKversion + "Count form fields = " + formCount);

        Console.ReadKey();


        // Copy the template (with any changes) to the new file
        // Start page and end page, 0 = all pages
        intCopyForm = oTK.CopyForm(0, 0);
        if (intCopyForm != 1)
        {
            ErrorHandler("CopyForm", intCopyForm);
        }

        // Close the new file to complete PDF creation
        oTK.CloseOutputFile();

        // Set the in memory PDF to a variable
        // To retrieve the PDF as a byte array use oTK.BinaryImage
        memPDF = oTK.OutputByteStream;

        // Toolkit can take a PDF in memory and use it as an input file
        // Here we will use the PDF we just created in memory

        // Create the final PDF on disk
        intOpenOutputFile = oTK.OpenOutputFile(strPath + "final.pdf");
        if (intOpenOutputFile != 0)
        {
            ErrorHandler("OpenOutputFile", intOpenOutputFile);
        }

        // Prepare the in memory PDF to be used with Toolkit
        // For .NET Toolkit also has InputByteArray to accept Byte Arrays
        oTK.InputByteStream = memPDF;

        // Now we can use 'MEMORY' as the filename with OpenInputFile or MergeFile
        intMergeFile = oTK.MergeFile("MEMORY", 0, 0);
        if (intMergeFile != 1)
        {
            ErrorHandler("MergeFile", intMergeFile);
        }

        // Close the final file to complete PDF creation
        oTK.CloseOutputFile();

        // To save a PDF in memory to a file directly call SaveMemoryToDisk
        oTK.SaveMemoryToDisk(strPath + "SavedMemory.pdf");

        // Release Object
        oTK.Dispose();

        // Process Complete
        WriteResults("Done!");
    }
Example #3
0
        static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Starting with Toolkit version 10 native DLLs are no longer
            // copied to the system folder. The Toolkit constructor must
            // be called with the path to the native DLLs or place them
            // in your applications working directory. This example
            // assumes they are located in the default installation folder.
            // (Use x86 in the path for 32b applications)
            string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit\bin\x64";

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(CoreLibPath: toolkitPath))
            {
                // Here you can place any code that will alter the output file
                // Such as adding security, setting page dimensions, etc.

                // Create the new PDF file
                int result = toolkit.OpenOutputFile(FileName: $"{strPath}Toolkit.AddField.pdf");
                if (result == 0)
                {
                    // Open the template PDF
                    result = toolkit.OpenInputFile(InputFileName: $"{strPath}blank.pdf");
                    if (result == 0)
                    {
                        // Here you can call any Toolkit functions that will manipulate
                        // the input file such as text and image stamping, form filling, etc.

                        // Add a new button form to the first page that executes a simple
                        // JavaScript alert.
                        APToolkitNET.FieldInfo fieldInfo = toolkit.AddField(1, 3, "TEST_BUTTON", 72, 750, 85, 25, "Helvetica", 10);
                        fieldInfo.ButtonTextNormal = "TEST BUTTON";
                        fieldInfo.MouseDownScript  = "app.alert(\"Hello World\", 3);";

                        // Add a new button form to the first page that executes a menu
                        // item.
                        fieldInfo = toolkit.AddField(1, 3, "Print_BUTTON", 167, 750, 85, 25, "Helvetica", 10);
                        fieldInfo.ButtonTextNormal = "Print Me";
                        fieldInfo.MouseDownScript  = "app.execMenuItem('Print');";

                        // Add A DropDown with list items
                        fieldInfo = toolkit.AddField(1, 6, "TEST_DROPDOWN", 72, 700, 85, 25, "Helvetica", 10);
                        APToolkitNET.ListItems fieldListItems = fieldInfo.ListItems();
                        fieldListItems.AddNew("FirstItem", "FirstItemValue");
                        fieldListItems.AddNew("SecondItem", "SecondItemValue");
                        fieldListItems.AddNew("ThirdItem", "ThirdItemValue");

                        // Add a Checkbox and use SetFormFieldData to mark checked
                        fieldInfo = toolkit.AddField(1, 4, "TEST_CHECKBOX", 72, 650, 25, 25, "Helvetica", 10);
                        toolkit.SetFormFieldData("TEST_CHECKBOX", "On", 1);

                        // Add a Radio Button Group
                        fieldInfo                = toolkit.AddField(1, 5, "TEST_RADIOGROUP", 72, 600, 25, 25, "Helvetica", 10);
                        fieldInfo.ExportValue    = "One";
                        fieldInfo                = toolkit.AddField(1, 5, "TEST_RADIOGROUP", 72, 625, 25, 25, "Helvetica", 10);
                        fieldInfo.ExportValue    = "Two";
                        fieldInfo                = toolkit.AddField(1, 5, "TEST_RADIOGROUP", 72, 650, 25, 25, "Helvetica", 10);
                        fieldInfo.ExportValue    = "Three";
                        fieldInfo.RadiosInUnison = false;

                        // Add a text field and set it's default value.
                        fieldInfo = toolkit.AddField(1, 1, "TEST_TEXTFIELD", 72, 550, 140, 25, "Helvetica", 10);
                        fieldInfo.DefaultValue = "Made by ActivePDF Toolkit!";

                        // Add a list box
                        fieldInfo      = toolkit.AddField(1, 7, "TEST_LISTBOX", 72, 450, 85, 50, "Helvetica", 10);
                        fieldListItems = fieldInfo.ListItems();
                        fieldListItems.AddNew("FirstItem", "FirstItemValue");
                        fieldListItems.AddNew("SecondItem", "SecondItemValue");
                        fieldListItems.AddNew("ThirdItem", "ThirdItemValue");

                        // Copy the template (with any changes) to the new file
                        // Start page and end page, 0 = all pages
                        result = toolkit.CopyForm(FirstPage: 0, LastPage: 0);
                        if (result != 1)
                        {
                            WriteResult($"Error copying file: {result.ToString()}", toolkit);
                            return;
                        }

                        // Close the new file to complete PDF creation
                        toolkit.CloseOutputFile();
                    }
                    else
                    {
                        WriteResult($"Error opening input file: {result.ToString()}", toolkit);
                        return;
                    }
                }
                else
                {
                    WriteResult($"Error opening output file: {result.ToString()}", toolkit);
                    return;
                }
            }

            // Process Complete
            WriteResult("Success!");
        }