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.HeaderText.pdf"); if (result == 0) { // Open the template PDF result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.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. string fontName = "Helvetica"; // Add a 'Confidential' watermark by setting text transparency // Rotation and color of the text along with the fill mode are set toolkit.SetHeaderFont( FontName: fontName, FontSize: 90); toolkit.SetHeaderTextTransparency( PercentStroke: 0.6f, PercentFill: 0.6f); toolkit.SetHeaderRotation(RotationAngle: 45); toolkit.SetHeaderTextStrokeColor( AmountRed: 255, AmountGreen: 0, AmountBlue: 0, AmountGrey: 0); toolkit.SetHeaderTextFillMode(FillMode: 1); toolkit.SetHeaderText( X: 154, Y: 184, Text: "Confidential"); toolkit.ResetHeaderTextTransparency(); toolkit.SetHeaderTextFillMode(FillMode: 0); // Add a 'Top Secret' watermark by placing text in the foreground toolkit.SetHeaderFont( FontName: fontName, FontSize: 72); toolkit.SetHeaderTextBackground(UseBackground: 1); toolkit.SetHeaderTextColor( AmountRed: 200, AmountGreen: 200, AmountBlue: 200, AmountGrey: 0); toolkit.SetHeaderText( X: 154, Y: 300, Text: "Top Secret"); toolkit.ResetHeaderTextColor(); toolkit.SetHeaderRotation(RotationAngle: 0); // Add the document title to the bottom center of the page toolkit.SetHeaderFont( FontName: fontName, FontSize: 12); toolkit.SetHeaderTextBackground(UseBackground: 0); string title = "ActivePDF Toolkit"; float textWidth = toolkit.GetHeaderTextWidth(TextString: title); toolkit.SetHeaderText( X: (612 - textWidth) / 2, Y: 52, Text: title); // Add page numbers to the bottom left of the page toolkit.SetHeaderFont( FontName: fontName, FontSize: 12); toolkit.SetHeaderWPgNbr( X: 540, Y: 52, Text: "Page %p", FirstPageNbr: 1); // Add a mulitline print box for an 'approved' message in header toolkit.SetHeaderTextFillMode(FillMode: 2); toolkit.SetHeaderTextColorCMYK( AmountCyan: 0, AmountMagenta: 0, AmountYellow: 0, AmountBlack: 20); toolkit.SetHeaderTextStrokeColorCMYK( AmountCyan: 0, AmountMagenta: 0, AmountYellow: 0, AmountBlack: 80); toolkit.SetHeaderMultilineText( FontName: fontName, FontSize: 22, X: 144, Y: 766, Width: 190, Height: 86, Text: $"Approved on {DateTime.Now}", Alignment: 2); toolkit.ForceHeaderColorReset(); // 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!"); }
public static void Example() { string strPath; string asdf; int intOpenOutputFile; int intOpenInputFile; bool isDebug; string strTitle; float textWidth; int testVar; int intCopyForm; long longStartPrinting; int some_var; int intLinearizeFile; string grade; int count; int currentPage; strPath = System.AppDomain.CurrentDomain.BaseDirectory; // Instantiate Object APToolkitNET.Toolkit oTK = new APToolkitNET.Toolkit(); asdf = "asdf" + "1234" + strPath + "asdf.pdf"; oTK.AddEmail(); oTK.AddEmail(); // Create the new PDF file intOpenOutputFile = oTK.OpenOutputFile(strPath + "new.pdf"); if (intOpenOutputFile != 0) { ErrorHandler("OpenOutputFile", intOpenOutputFile); } // Open the template PDF intOpenInputFile = oTK.OpenInputFile(strPath + "PDF.pdf"); if (intOpenInputFile != 0) { ErrorHandler("OpenInputFile", intOpenInputFile); } // Add a 'Confidential' watermark by setting text transparency // Rotation and color of the text along with the fill mode are set oTK.SetHeaderFont("Helvetica", 90); oTK.SetHeaderTextTransparency(0.6f, 0.6f); oTK.SetHeaderRotation(45); oTK.SetHeaderTextStrokeColor(255, 0, 0, 0); oTK.SetHeaderTextFillMode(1); oTK.SetHeaderText(154, 184, "Confidential"); oTK.ResetHeaderTextTransparency(); oTK.SetHeaderTextFillMode(0); oTK.MyProperty = 1; oTK.Debug = "jkl;"; isDebug = oTK.Debug; // Add a 'Top Secret' watermark by placing text in the background oTK.SetHeaderFont("Helvetica", 72); oTK.SetHeaderTextBackground(0); oTK.SetHeaderTextColor(200, 200, 200, 0); oTK.SetHeaderText(154, 300, "Top Secret"); oTK.SetHeaderTextBackground(1); oTK.ResetHeaderTextColor(); oTK.SetHeaderRotation(0); // Add the document title to the bottom center of the page oTK.SetHeaderFont("Helvetica", 12); strTitle = "Lorem Ipsum"; textWidth = oTK.GetHeaderTextWidth(strTitle); oTK.SetHeaderText((612 - textWidth) / 2, 32, strTitle); // Add page numbers to the bottom left of the page oTK.SetHeaderFont("Helvetica", 12); oTK.SetHeaderWPgNbr(72, 32, "Page %p", 1); // Add a mulitline print box for an 'approved' message in header oTK.SetHeaderTextFillMode(2); oTK.SetHeaderTextColorCMYK(0, 0, 0, 20); oTK.SetHeaderTextStrokeColorCMYK(0, 0, 0, 80); oTK.SetHeaderMultilineText("Helvetica", 22, 344, 766, 190, 86, "Approved on January 17th, 2021", 2); // Add some lines to the footer and top right corner of the page oTK.SetHeaderGreyBar(72, 52, 468, 1, 0.8f); oTK.SetHeaderHLine(340, 544, 724, 1); oTK.SetHeaderVLine(724, 648, 544, 1); testVar = oTK.GetUniqueID + ".pdf"; // Use the Header Image properties to add some images to the footer // Net comment oTK.SetHeaderImage(strPath + "BMP.bmp", 375.0f, 13.0f, 0.0f, 0.0f, true); oTK.SetHeaderJPEG(strPath + "JPEG.jpg", 436.0f, 9.0f, 0.0f, 0.0f, true); oTK.SetHeaderTIFF(strPath + "TIFF.tif", 500.0f, 15.0f, 0.0f, 0.0f, true); // Copy the template (with the stamping changes) to the new file // Start page and end page, 0 = all pages intCopyForm = oTK.CopyForm(0, 0); if (intCopyForm != 1) { ErrorHandler("CopyForm", intCopyForm); } longStartPrinting = oTK.StartPrinting(strPath + "PDF.pdf"); if (longStartPrinting != 0) { ErrorHandler("StartPrinting", longStartPrinting); } longStartPrinting = oTK.StartPrinting("file.ps", "file.pdf"); if (longStartPrinting > 1) { ErrorHandler("StartPrinting", longStartPrinting); } longStartPrinting = oTK.StartPrinting("file.ps", "file.pdf"); if (longStartPrinting < 1) { ErrorHandler("StartPrinting", longStartPrinting); } if (some_var == 0) { intLinearizeFile = oTK.LinearizeFile(strPath + "PDF.pdf", strPath + "new.pdf", ""); if (intLinearizeFile > 0) { ErrorHandler("LinearizeFile", intLinearizeFile); } } if (some_var > 0) { intLinearizeFile = oTK.LinearizeFile(strPath + "PDF.pdf", strPath + "new.pdf", ""); if (intLinearizeFile > 0) { ErrorHandler("LinearizeFile", intLinearizeFile); } } if (some_var < 0) { oTK.conmment("This is true statement"); } else { // This is an else ErrorHandler("asdf", 234); } // Close the new file to complete PDF creation // Snippet with variables // Snippet comment from variable! oTK.SetSnippetPropertyToInt = 1; oTK.ArrayProperty = "Array of numbers and strings"; oTK.ArrayProperty = 1; oTK.ArrayProperty = 18.38f; // nil // Instantiate Object APServer.Server oSVR = new APServer.Server(); oTK.CloseOutputFile(); oSVR.CloseOutputFile(); oSVR.CloseOutputFile(); // Release Object oSVR = null; // Server cs line 2
static void Main(string[] args) { string strPath = System.AppDomain.CurrentDomain.BaseDirectory; // Instantiate Object using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit()) { // 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.HeaderText.pdf"); if (result != 0) { WriteResult($"Error opening output file: {result.ToString()}", toolkit); return; } // Open the template PDF result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf"); if (result != 0) { WriteResult($"Error opening input file: {result.ToString()}", toolkit); return; } string fontName = "Helvetica"; // Add a 'Confidential' watermark by setting text transparency // Rotation and color of the text along with the fill mode are set toolkit.SetHeaderFont(FontName: fontName, FontSize: 90); toolkit.SetHeaderTextTransparency(PercentStroke: 0.6f, PercentFill: 0.6f); toolkit.SetHeaderRotation(RotationAngle: 45); toolkit.SetHeaderTextStrokeColor(AmountRed: 255, AmountGreen: 0, AmountBlue: 0, AmountGrey: 0); toolkit.SetHeaderTextFillMode(FillMode: 1); toolkit.SetHeaderText(X: 154, Y: 184, Text: "Confidential"); toolkit.ResetHeaderTextTransparency(); toolkit.SetHeaderTextFillMode(FillMode: 0); // Add a 'Top Secret' watermark by placing text in the foreground toolkit.SetHeaderFont(FontName: fontName, FontSize: 72); toolkit.SetHeaderTextBackground(UseBackground: 1); toolkit.SetHeaderTextColor(AmountRed: 200, AmountGreen: 200, AmountBlue: 200, AmountGrey: 0); toolkit.SetHeaderText(X: 154, Y: 300, Text: "Top Secret"); toolkit.ResetHeaderTextColor(); toolkit.SetHeaderRotation(RotationAngle: 0); // Add the document title to the bottom center of the page toolkit.SetHeaderFont(FontName: fontName, FontSize: 12); toolkit.SetHeaderTextBackground(UseBackground: 0); string title = "ActivePDF Toolkit"; float textWidth = toolkit.GetHeaderTextWidth(title); toolkit.SetHeaderText((612 - textWidth) / 2, 52, title); // Add page numbers to the bottom left of the page toolkit.SetHeaderFont(FontName: fontName, FontSize: 12); toolkit.SetHeaderWPgNbr(X: 540, Y: 52, Text: "Page %p", FirstPageNbr: 1); // Add a mulitline print box for an 'approved' message in header toolkit.SetHeaderTextFillMode(FillMode: 2); toolkit.SetHeaderTextColorCMYK(AmountCyan: 0, AmountMagenta: 0, AmountYellow: 0, AmountBlack: 20); toolkit.SetHeaderTextStrokeColorCMYK(AmountCyan: 0, AmountMagenta: 0, AmountYellow: 0, AmountBlack: 80); toolkit.SetHeaderMultilineText(FontName: fontName, FontSize: 22, X: 144, Y: 766, Width: 190, Height: 86, Text: "Approved on January 17th, 2021", Alignment: 2); toolkit.ForceHeaderColorReset(); // 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(); } // Process Complete WriteResult("Success!"); }