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.AddComment.pdf"); if (result == 0) { // Open the template PDF result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf"); if (result == 0) { // Add a comment to first page of the input PDF toolkit.AddComment( Left: 72.0f, Top: 660.0f, Width: 144.0f, Height: 100.0f, Comment: "Adds a note comment with a signifying icon. The icon alerts the reader's attention to the noted area for the signified purpose.", Name: "AddComment", noteType: 0, Flags: 128, Color: "#BEBEBE", isOpened: true, PageNum: 0, UserName: "******", Subject: "Toolkit AddComment"); // 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; } // Extract the comments as XML Data to a variable. // Use the strXMLData variable to handle the XML data. string xmlCommentData = toolkit.ExportComments(PageNumber: 0); Console.WriteLine(xmlCommentData); // 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!"); }
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 Ultimate\bin\x64"; // Instantiate Object using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(toolkitPath)) { // Get the Extractor object from Toolkit APToolkitNET.Extractor extractor = toolkit.GetExtractor(); // Open the input PDF int result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf"); if (result == 0) { // Extract an image from the input PDF at the input // location and save it as a randomly named file. // Extractor supports BMP, JPEG, PNG, RGB, and TIFF var image = extractor.ExtractImageByArea( eImageType: APToolkitNET.APImageType.JPEG, Page: 1, Rect: new System.Drawing.RectangleF(300.0f, 0.0f, 300.0f, 100.0f)); string fileName = $"{System.IO.Path.GetRandomFileName()}.jpg"; try { if (image.Length != 0) { Console.WriteLine($"Extracting Image to: {fileName}"); System.IO.File.WriteAllBytes( $"{strPath}\\{fileName}", image); } else { Console.WriteLine("No image found at location."); } } catch (Exception e) { Console.WriteLine($"Exception caught creating image file ({fileName}): {e.Message}"); } // Close the new file to complete PDF creation toolkit.CloseInputFile(); } else { WriteResult($"Error opening input file: {result.ToString()}", toolkit); return; } } // Process Complete WriteResult("Success!"); }
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(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.SetPDFView.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; } // Get the reference to the InitialViewInfo object APToolkitNET.InitialViewInfo viewInfo = toolkit.GetInitialViewInfo(); // Options for viewer window viewInfo.CenterWindow = true; viewInfo.FullScreen = false; viewInfo.ResizeWindow = true; viewInfo.Show = APToolkitNET.IVShow.IVShow_DocumentTitle; // Show or hide UI elements of the viewer viewInfo.HideMenuBar = true; viewInfo.HideToolBars = true; viewInfo.HideWindowControls = true; viewInfo.NavigationTab = APToolkitNET.IVNavigationTab.IVNavigationTab_PageOnly; // Page settings viewInfo.Magnification = APToolkitNET.IVMagnification.IVMagnification_150; viewInfo.OpenToPage = 2; viewInfo.PageLayout = APToolkitNET.IVPageLayout.IVPageLayout_SinglePageContinuous; // 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!"); }
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.Watermark.pdf"); if (result == 0) { // Open the template PDF result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf"); if (result == 0) { // Add a watermark string stampText = "WATERMARK"; toolkit.SetFont(FontName: "Helvetica", FontSize: 72, PageNumber: -1); toolkit.SetTextColor(AmountRed: 168, AmountGreen: 0, AmountBlue: 0, AmountGrey: 0, PageNumber: -1); toolkit.PrintText( X: (612 - toolkit.GetTextWidth(stampText)) / 2, Y: (792 - toolkit.GetTextHeight(stampText)) / 2, Text: stampText, PageNumber: -1); toolkit.ResetTextColor(PageNumber: -1); // 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!"); }
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(toolkitPath)) { // Instantiate the Compressor object APToolkitNET.Compressor compressor = toolkit.GetCompressor(); // Change the resolution of images to 72 dpi. compressor.DownsampleImages = true; // Images of DPI greater or equal to the TriggerDPI will be // downsampled to the TargetDPI compressor.TargetDPI = 72.0f; compressor.TriggerDPI = 150.0f; // 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.DownsampleImages.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. // Copy the template (with any changes) to the new file // Start page and end page, 0 = all pages result = toolkit.CopyForm(0, 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!"); }
static void Main(string[] args) { string strPath = System.AppDomain.CurrentDomain.BaseDirectory; // Simulate the intput byte array by opening a file into memory. byte[] inputPDF = File.ReadAllBytes($"{strPath}Toolkit.Input.pdf"); // 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)) { // Create the new PDF file in memory int result = toolkit.OpenOutputFile("MEMORY"); if (result == 0) { // Set the input byte array toolkit.InputByteArray = inputPDF; // Open the input byte array result = toolkit.OpenInputFile("MEMORY"); if (result == 0) { // 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(); // Here is the output byte array. Byte[] outputPDF = toolkit.OutputByteArray; // Or save the output to disk result = toolkit.SaveMemoryToDisk(FileName: $"{strPath}Toolkit.AllInMemory.pdf"); if (result != 0) { WriteResult($"Error saving output file: {result.ToString()}", toolkit); return; } } 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; // 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.FillDBFields.pdf"); if (result == 0) { // Specify the template form to populate toolkit.SetDBInputTemplate(InputPDFPath: $"{strPath}Toolkit.DBTemplate.pdf"); // Set query command to a variable string strSQL = "Select * From Supplier"; // Set connection String to a variable string strConn = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={strPath}Toolkit.Input.mdb" + ";Persist Security Info=False"; // Set master query result = toolkit.SetMasterQuery( ConnectionString: strConn, UserID: "Admin", Password: "", Options: -1, QueryString: strSQL); if (result != 0) { WriteResult($"Failed to access the database file: {result}", toolkit); return; } // Set the row Separator toolkit.SetDBMultiRowSeparator(MultiRowSeparator: ""); // Related query separator is only needed if different from // default of '|' toolkit.RelatedQuerySeparator = "|"; // Add related query result = toolkit.AddRelatedQuery( ConnectionString: strConn, UserID: "Admin", Password: "", Options: -1, QueryString: strSQL, MultiRows: true); if (result != 0) { WriteResult($"Failed to implmenet the query: {result}", toolkit); return; } // If db column names are different then field names a map file // is needed. In this example only the zip/postal code is // different. result = toolkit.LoadDBMapFile(PathToMapFile: $"{strPath}Toolkit.DBFormmap.txt"); if (result != 0) { WriteResult($"Failed to load the map file: {result}", toolkit); return; } // Flatten fields that are populated with data toolkit.SetDefaultDBMergeFlag(DefaultMergeFlag: -997); // Flatten all other fields on the form toolkit.FlattenRemainingFormFields = 1; // Fill the template form result = toolkit.DBToForm(MultiPage: false); if (result != 0) { WriteResult($"DBToForm failed: {result}", toolkit); return; } // Clear and close used queries toolkit.ClearQueries(); // Close the new file to complete PDF creation toolkit.CloseOutputFile(); } else { WriteResult($"Error opening output file: {result.ToString()}", toolkit); return; } } // Process Complete WriteResult("Success!"); }
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.FillForms.pdf"); if (result != 0) { WriteResult($"Error opening output file: {result.ToString()}"); 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; } // Set how you want form field data formatting to be handled // By default the field will remain the same (1) // You can have the field formatting be ignored (0) toolkit.DoFormFormatting = 1; // As we will be using the same PDF form for multiple pages we // do not want the field names to conflict as different data // will be in same named fields Using FormNumbering will rename // the fields so they do not conflict field 'name' would become // 'name__1', 'name__2', etc. 0 = False, 1 = True toolkit.FormNumbering = 1; // Populate form fields for the first page with data // Refer to the documentation for possible flag options toolkit.SetFormFieldData("Text1", "This text field's content was updated using ActivePDF Toolkit.", 1); // 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; } // Use ResetFormFields to clear the form data we previously // used toolkit.ResetFormFields(); // Populate form fields for the second page with data toolkit.SetFormFieldData("Text1", "This second text field's content was updated using ActivePDF Toolkit.", 1); // Set whether to flatten all other fields not touched by // SetFormFieldData toolkit.FlattenRemainingFormFields = 1; // 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!"); }
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.HeaderLines.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. // Add some lines to the footer and top right corner of the page toolkit.SetHeaderGreyBar( X: 72, Y: 52, Width: 468, Height: 1, GreyLevel: 0.8f); toolkit.SetHeaderHLine( X1: 340, X2: 544, Y: 724, Width: 1); toolkit.SetHeaderVLine( Y1: 724, Y2: 648, X: 544, Width: 1); // 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!"); }
static void Main(string[] args) { string strPath = System.AppDomain.CurrentDomain.BaseDirectory; string inputFile = $"{strPath}Toolkit.Input.pdf"; // 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(toolkitPath)) { // Retrieves the number of pages for the specified PDF file. int numPages = toolkit.NumPages(inputFile); if (numPages == 0) { WriteResult($"Error getting input file page count: {numPages.ToString()}", toolkit); return; } // The number of pages from the input PDF to place per row. float pagesPerRow = Convert.ToSingle(Math.Ceiling(Math.Sqrt((double)numPages))); // Close the input file before creating a new document. toolkit.CloseInputFile(); // Create the new PDF file int result = toolkit.OpenOutputFile($"{strPath}Toolkit.StitchPDF.pdf"); if (result != 0) { WriteResult($"Error opening output file: {result.ToString()}", toolkit); return; } // Using the default PDF width and height of 612/792 float pageWidth = 612.0f, pageHeight = 792.0f; // The width and height of each page from the original PDF // added to the output file. float width = pageWidth / pagesPerRow, height = pageHeight / pagesPerRow; // The rows of images from the original PDF added to the new // document. int numRows = Convert.ToInt32(Math.Ceiling(pageHeight / height)); for (int i = 1; i < numRows; ++i) { for (int j = 0; j < pagesPerRow; ++j) { // Add the page from the original PDF to the output. toolkit.StitchPDF( FileName: inputFile, PageNumber: i + j, X: width * j, Y: pageHeight - (height * i), Width: width, Height: height, Rotation: 0); } } // Close the new file to complete PDF creation toolkit.CloseOutputFile(); } // Process Complete WriteResult("Success!"); }
public static void Example() { int intDoPrint; string strPath; int intOpenInputFile; string strFieldInfo; strPath = System.AppDomain.CurrentDomain.BaseDirectory; // Instantiate Object NameSpace.Class objVAR = new NameSpace.Class(); // Release Object objVAR = null; // Instantiate Object APDocConv.APDocConverter oDC = new APDocConv.APDocConverter(); // Release Object oDC = null; // Instantiate Object activePDF.API.DocConverterWBE.DocConverter oDCw = new activePDF.API.DocConverterWBE.DocConverter(); // Release Object oDCw = null; // Instantiate Object APMeridian.Meridian oMER = new APMeridian.Meridian(); // Release Object oMER = null; // Instantiate Object APServer.Server oSVR = new APServer.Server(); // Release Object oSVR = null; // Instantiate Object APToolkitNET.Toolkit oTK = new APToolkitNET.Toolkit(); // Release Object oTK = null; // Instantiate Object APWebGrbNET.APWebGrabber oWG = new APWebGrbNET.APWebGrabber(); // Release Object oWG = null; // Instantiate Object APXtractor.Xtractor oXT = new APXtractor.Xtractor(); // Release Object oXT = null;
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 Ultimate\bin\x64"; // Instantiate Object using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(toolkitPath)) { // Get the Redactor object from Toolkit APToolkitNET.Redactor redactor = toolkit.GetRedactor(); int result = toolkit.OpenOutputFile(FileName: $"{strPath}Toolkt.RedactReplace.pdf"); if (result == 0) { // Open the input PDF result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf"); if (result == 0) { // Redact an existing word and replace it with your // own. redactor.RedactReplace(word2redact: "Toolkit", text4replace: "**********", "Arial", 8); // Call the Redactor Apply method to execute the // redaction process. All Toolkit methods normally // called between OpenInputFile and CopyForm // (PrintText, PrintImage etc.) must be after // Redactor.Apply redactor.Apply(); result = toolkit.CopyForm(FirstPage: 0, LastPage: 0); if (result != 1) { WriteResult("CopyForm Failed", toolkit); } // Close the new file to complete PDF creation toolkit.CloseInputFile(); } else { WriteResult($"Error opening input file: {result.ToString()}", toolkit); return; } } else { WriteResult($"Error opening output file: {result.ToString()}", toolkit); return; } } // Process Complete WriteResult("Success!"); }
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(toolkitPath)) { // Instantiate the Compressor object APToolkitNET.Compressor compressor = toolkit.GetCompressor(); // Compresses images in the output PDF. compressor.CompressImages = true; // Compress images to a particular quality, used only with // lossy image compression. Ranges from 1 to 100 indicate // the result image quality. A lower value creates an image of // lower PPI and smaller file size, while a greater value // creates images of better quality but larger file size. The // default is 20. compressor.CompressionQuality = 75; // Create the new PDF file int result = toolkit.OpenOutputFile($"{strPath}Toolkit.CompressionQuality.pdf"); if (result != 0) { WriteResult($"Error opening output file: {result.ToString()}", toolkit); return; } // Open the template PDF result = toolkit.OpenInputFile($"{strPath}Toolkit.Input.pdf"); if (result != 0) { WriteResult($"Error opening input file: {result.ToString()}", toolkit); return; } // Copy the template (with any changes) to the new file // Start page and end page, 0 = all pages result = toolkit.CopyForm(0, 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!"); }
public async Task <IActionResult> Upload(IFormFile file) { try { if (file != null && file.Length > 0) { var name = Path.GetFileName(file.FileName); var extension = Path.GetExtension(file.FileName); if (!_validExtensions.Contains(extension.ToLowerInvariant())) { TempData["Message"] = "Not a valid file extension"; return(RedirectToAction("Index")); } string filePath = Path.Combine("Output", String.Format("{0}_{1}.{2}", Guid.NewGuid(), name, extension)); using (var fileStream = new FileStream(filePath, FileMode.Create)) { await file.CopyToAsync(fileStream); } APToolkitNET.Toolkit oTK = new APToolkitNET.Toolkit(); // Set the PDF page Height and Width to Letter (72 = 1") oTK.OutputPageHeight = 792.0f; oTK.OutputPageWidth = 612.0f; // Create the new PDF file string pdfFileName = "output.pdf"; var intOpenOutputFile = oTK.OpenOutputFile(String.Format("{0}/{1}", "output", pdfFileName)); if (intOpenOutputFile != 0) { //log and redirect to custom error page //for demo just throw throw new Exception("error in pdf creation"); } oTK.NewPage(); oTK.SetFont("Helvetica", 12); oTK.PrintText(50.0f, 20.0f, "Signature: Mher Sarkissian"); oTK.PrintImage(filePath, 0.0f, 200.0f, 612.0f, 792.0f, true, 0); oTK.CloseOutputFile(); oTK.Dispose(); } else { TempData["Message"] = "Invalid file upload"; return(RedirectToAction("Index")); } } catch (Exception e) { //log and redirect to custom error page //for demo just throw throw e; } return(View("ViewPDF")); }
static void Main(string[] args) { string appPath = System.AppDomain.CurrentDomain.BaseDirectory; string newPDF = "GeneratedPDF.pdf"; int result = -1; // Use Toolkit to create a new PDF using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit()) { toolkit.OutputPageHeight = 792.0f; toolkit.OutputPageWidth = 612.0f; Console.WriteLine($"Toolkit: Generating new PDF using NewPage"); // Open the output file in memory result = toolkit.OpenOutputFile("MEMORY"); if (result != 0) { WriteResult($"Toolkit: Failed to open output file in-memory, error code {result}"); return; } // Each time a new page is required call NewPage toolkit.NewPage(); // Text can be added onto the new page with // SetFont, PrintText and PrintMultilineText functions toolkit.SetFont("Helvetica", 24); toolkit.PrintText(36.0f, 720.0f, $"Toolkit Version: {toolkit.ToolkitVersion}"); // Images can be added onto the new page with // PrintImage, PrintJPEG and PrintTIFF toolkit.PrintJPEG($"{appPath}IMG.jpg", 36.0f, 36.0f, 540.0f, 684.0f, true); // Close the new file to complete PDF creation toolkit.CloseOutputFile(); // Save the new PDF to the application path result = toolkit.SaveMemoryToDisk($"{appPath}{newPDF}"); if (result != 0) { WriteResult($"Toolkit: SaveMemoryToDisk failed, error code {result}"); return; } Console.WriteLine($"Toolkit: New pdf created {appPath}{newPDF}"); // Use Toolkit Compressor to compress images Console.WriteLine("Toolkit.Compressor: Compressing generated PDF"); toolkit.OpenOutputFile("MEMORY"); if (result != 0) { WriteResult($"Toolkit Compressor: Failed to open output file in-memory, error code {result}"); return; } // Retrieves the entire PDF as a string variable after you call // CloseOutputFile and set the output file name to MEMORY. toolkit.InputByteStream = toolkit.OutputByteStream; // Open the input file toolkit.OpenInputFile("MEMORY"); if (result != 0) { WriteResult($"Toolkit Compressor: Failed to open input file in-memory, error code {result}"); return; } // Instantiate the compressor object APToolkitNET.Compressor compressor = toolkit.GetCompressor(); // Compresses images in the output PDF with the default settings. compressor.CompressImages = true; result = toolkit.CopyForm(0, 0); if (result != 1) { WriteResult($"Toolkit Compressor: CopyForm failed, error code {result}"); return; } toolkit.CloseOutputFile(); // Save the compressed PDF to disk result = toolkit.SaveMemoryToDisk($"{appPath}Toolkit.Compressed.pdf"); if (result != 0) { WriteResult($"Toolkit Compressor: SaveMemoryToDisk failed, error code {result}"); return; } Console.WriteLine($"Toolkit Compressor: Compressed pdf created {appPath}Toolkit.Compressed.pdf"); } // Use Rasterizer to convert generated PDF to an image Console.WriteLine("\nRasterizer: Converting generated PDF to image format"); using (APRasterizerNET.Rasterizer rasterizer = new APRasterizerNET.Rasterizer()) { // Open PDF rasterizer.OpenFile($"{appPath}{newPDF}"); // Get page count of open file int pageCount = rasterizer.NumPages(); for (int currentPage = 1; currentPage <= pageCount; currentPage++) { // Image Format rasterizer.ImageFormat = APRasterizerNET.ImageType.ImgJPEG; // Output Type rasterizer.OutputFormat = APRasterizerNET.OutputFormatType.OutFile; // Other settings rasterizer.OutputFileName = $"{appPath}Rasterizer.ConvertPDFToJPEG.Page.{currentPage}.jpg"; // Render the current page rasterizer.RenderPage(currentPage); // Check for errors if (rasterizer.LastError != 0) { WriteResult($"Error rendering page {currentPage}: {rasterizer.LastErrorMessage}"); } Console.WriteLine($"Rasterizer: JPG image created at {appPath}Rasterizer.ConvertPDFToJPEG.Page.{currentPage}.jpg"); } } // Use Xtractor to extract text and images Console.WriteLine("\nXtractor: Extracting images and text from the generated PDF"); using (Xtractor.Xtractor xtractor = new Xtractor.Xtractor(filename: $"{appPath}{newPDF}")) { // Saves all images in the entire document to JPG files. string[] jpgFileNames = xtractor.ExtractImagesToFile(filenameOrMask: $"{appPath}Xtractor.#PAGE#_#NUM#.jpg"); Console.WriteLine($"Xtractor: Files extracted from \"{newPDF}\""); foreach (string file in jpgFileNames) { Console.WriteLine($"\tExtracted File: {file}"); } // This method extracts the text from the whole document at once. // The string[] is sorted by page number, where index 'n' is page 'n + 1'. string[] allTextArray = xtractor.ExtractText(); Console.WriteLine($"Xtractor: Text extracted from {newPDF}"); foreach (string text in allTextArray) { Console.WriteLine($"\tExtracted Text: {text}"); } } // Use Redactor to redact images and text from generated PDF Console.WriteLine("\nRedactor: Redacting images and text from the generated PDF"); using (APRedactor.Redactor redactor = new APRedactor.Redactor( filename: $"{appPath}{newPDF}")) { redactor.PageLiteralText = new string[] { "Version" }; redactor.TextMode = APRedactor.Redactor.TextRedactionMode.LiteralText; redactor.ImageMode = APRedactor.Redactor.ImageRedactionMode.Unconditional; int redactionsPerformed = redactor.Redact(); redactor.Save($"{appPath}RedactImagesAndText.pdf"); Console.WriteLine($"Redactor: Redacted PDF created {appPath}RedactedImagesAndText.pdf"); } WriteResult("\nSuccess!"); }
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(toolkitPath)) { // Instantiate the Compressor object APToolkitNET.Compressor compressor = toolkit.GetCompressor(); // Compresses images in the output PDF. compressor.CompressImages = true; // Compresses eligible objects in the output PDF, which include // page objects and fonts. Streams (including content, text, // images, and data) are not affected. compressor.CompressObjects = true; // Compress images to a particular quality, used only with // lossy image compression. Ranges from 1 to 100 indicate // the result image quality. A lower value creates an image of // lower PPI and smaller file size, while a greater value // creates images of better quality but larger file size. The // default is 20. compressor.CompressionQuality = 20; // Remove all embedded files. compressor.DiscardAttachments = true; // Remove comments from the output PDF. compressor.DiscardComments = true; // Remove form fields from the output PDF. compressor.DiscardFormFields = true; // Remove metadata from the output PDF. compressor.DiscardMetadata = true; // Remove markup and reflow data from the resulting PDF. compressor.DiscardDocumentTags = true; // Change the resolution of images to 72 dpi. compressor.DownsampleImages = true; // Compress uncompressed PDF streams. compressor.EncodeStreams = true; // Subset fonts. compressor.SubsetFonts = true; // Images of DPI greater or equal to the TriggerDPI will be // downsampled to the TargetDPI compressor.TargetDPI = 150.0f; compressor.TriggerDPI = 300.0f; // Create the new PDF file int result = toolkit.OpenOutputFile($"{strPath}Toolkit.HighCompression.pdf"); if (result != 0) { WriteResult($"Error opening output file: {result.ToString()}", toolkit); return; } // Open the template PDF result = toolkit.OpenInputFile($"{strPath}Toolkit.Input.pdf"); if (result != 0) { WriteResult($"Error opening input file: {result.ToString()}", toolkit); return; } // Copy the template (with any changes) to the new file // Start page and end page, 0 = all pages result = toolkit.CopyForm(0, 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!"); }
public ActionResult <Response> CreateSampleBookmarks([FromBody] Request request) { try { using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit()) { //Set page dimensions toolkit.OutputPageHeight = 792.0f; toolkit.OutputPageWidth = 612.0f; //Create new file int result = toolkit.OpenOutputFile(FileName: $"{serverDirectory}SampleBookmarks.pdf"); if (result != 0) { throw new Exception($"Could not create destination file: SampleBookmarks.pdf"); } // Open Source File result = toolkit.OpenInputFile($"{ serverDirectory}{request.filename}.pdf"); if (result != 0) { throw new Exception($"Could not Open file: {request.filename}"); } // Add new page to output toolkit.NewPage(); toolkit.SetFont(FontName: "Arial", FontSize: 20); toolkit.PrintText(X: 72.0f, Y: 720.0f, Text: "Table of Contents"); toolkit.AddInternalLink(1, 72, 720, 72, 720, 5, 72, 720, 4); //toolkit.AddInternalLinkBookmark("Section 1", 2, 0, 0); APToolkitNET.BookmarkManager bookmarkManager = toolkit.GetBookmarkManager(); bookmarkManager.CopyBookmarks = true; APToolkitNET.Bookmark root = bookmarkManager.MakeRoot("Table of Contents", "red", APToolkitNET.FontStyle.Bold); var section1 = bookmarkManager.AddChild(root, "Section 1"); section1.SetInternalLink(1, 0, 0); var section11 = bookmarkManager.AddChild(section1, "Section 1.1"); section11.SetInternalLink(2, 0, 0); var section111 = bookmarkManager.AddChild(section1, "Section 1.1.1"); section11.SetInternalLink(3, 0, 0); var section2 = bookmarkManager.AddChild(root, "Section 2"); section2.SetInternalLink(4, 0, 0); var section21 = bookmarkManager.AddChild(section2, "Section 2.1"); section21.SetInternalLink(5, 0, 0); var section211 = bookmarkManager.AddChild(section2, "Section 2.1.1"); section211.SetInternalLink(6, 0, 0); // Close the new file to complete PDF creation toolkit.CopyForm(0, 0); toolkit.CloseInputFile(); toolkit.CloseOutputFile(); return(new Response() { FileContent = string.Empty, FileName = "SampleBookmarks.pdf", Message = "File SampleBookmarks.pdf created successfully", Success = true }); } } catch (Exception ex) { return(new Response() { FileContent = string.Empty, FileName = "", Message = "Could not Create Sample Bookmarks " + ex.Message, Success = false }); } }
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.SignPDF.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; } // Find certificate, if it doesn't exist it will be created // If you have an existing signature you can find it with // FindCertificate and remove the portion of code that creates // the certificate int certificateID = toolkit.FindCertificate( CertName: "John Doe", Store: "My", LMStore: 0); if (certificateID < 1) { Console.WriteLine("Certificate not found, creating."); // Certificate not found, create a certificate with Toolkit int createCertResult = toolkit.CreateCertificate( CommonName: "John Doe", OrgUnit: "Management", Org: "Doe Enterprises", Local: "Mission Viejo", State: "CA", Country: "US", EMail: "*****@*****.**", UseLocalMachine: 0, CertStoreName: "My", DaysCertIsValid: 365, IssuerUseLocalMachine: 0, IssuerName: "", IssuerStoreName: ""); if (createCertResult == 1) { // New certificate created, find it for use certificateID = toolkit.FindCertificate( CertName: "John Doe", Store: "My", LMStore: 0); if (certificateID < 1) { WriteResult($"Failed to find new certificate after creation: {certificateID}"); } } else { WriteResult($"Failed to create new certificate: {createCertResult}"); } } // Invisibly sign the output file after any creation, merge or append operation. toolkit.SignOutputFile( SigNumber: certificateID, Location: "Mission Viejo", Reason: "Testing Toolkit PDF Signing.", ContactInfo: "http://www.activepdf.com", Encoding: 0); // 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!"); }
public ActionResult <Response> CreateFile([FromBody] Request request) { try { using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit()) { //Set page dimensions toolkit.OutputPageHeight = 792.0f; toolkit.OutputPageWidth = 612.0f; //Create new file int result = toolkit.OpenOutputFile(FileName: $"{ serverDirectory}{request.filename}.pdf"); if (result != 0) { throw new Exception($"Could not create file: {request.filename}"); } // Each time a new page is required call NewPage toolkit.NewPage(); toolkit.PrintLogo(); // Get the current version of Toolkit and save it to print on // the PDF string toolkitVersion = toolkit.ToolkitVersion; toolkit.SetFont(FontName: "Arial", FontSize: 24); toolkit.PrintText(X: 72.0f, Y: 720.0f, Text: toolkitVersion); toolkit.PrintText(X: 72.0f, Y: 500.0f, Text: request.filetext); // Images can be added onto the new page with PrintImage, // PrintJPEG and PrintTIFF toolkit.PrintJPEG( FileName: serverDirectory + "logoSpartanDevTeam.jpg", X: 72.0f, Y: 400.0f, Width: 150.0f, Height: 150.0f, PersistRatio: true, PageNumber: 0); // 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 != 0) { throw new Exception($"Could not Copy Template to new file: {request.filename}"); } // Close the new file to complete PDF creation toolkit.CloseOutputFile(); return(new Response() { FileContent = string.Empty, FileName = string.IsNullOrEmpty(request.filename) ? Guid.NewGuid().ToString() + ".pdf" : request.filename + ".pdf", Message = "File created successfully", Success = true }); } } catch (Exception ex) { return(new Response() { FileContent = string.Empty, FileName = "", Message = "Could not create file. " + ex.Message, Success = false }); } }
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(toolkitPath)) { // Get the Toolkit Bookmark Manager APToolkitNET.BookmarkManager bookmarkManager = toolkit.GetBookmarkManager(); // Set CopyBookmarks to true to create bookmarks in the output PDF. bookmarkManager.CopyBookmarks = true; // Create the new PDF file int result = toolkit.OpenOutputFile($"{strPath}Toolkit.LaunchBookmark.pdf"); if (result == 0) { // Open the template PDF result = toolkit.OpenInputFile($"{strPath}Toolkit.Input.pdf"); if (result == 0) { // Create a new bookmark for the page. APToolkitNET.Bookmark newBookmark = bookmarkManager.NewBookmark( Title: "Open your application."); // Set the page number and location to link newBookmark.SetLaunch(CommandName: "your.exe"); // Set the bookmark color - orange newBookmark.Color = "#FFA500"; // Set the bookmark font style newBookmark.FontStyle = APToolkitNET.FontStyle.ItalicBold; // Copy the template (with any changes) to the new file // Start page and end page, 0 = all pages result = toolkit.CopyForm(0, 0); if (result != 1) { WriteResult($"Error copying file: {result.ToString()}", toolkit); return; } } else { WriteResult($"Error opening input file: {result.ToString()}", toolkit); return; } // Close the new file to complete PDF creation toolkit.CloseOutputFile(); } else { WriteResult($"Error opening output file: {result.ToString()}", toolkit); return; } } // Process Complete WriteResult("Success!"); }
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 Ultimate\bin\x64"; // Instantiate Object using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(toolkitPath)) { // Get the Extractor object from Toolkit APToolkitNET.Extractor extractor = toolkit.GetExtractor(); // Open the input PDF int result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf"); if (result == 0) { // Extract the text from the whole document at once. string extractedText = extractor.ExtractText(); string fileName = $"{System.IO.Path.GetRandomFileName()}.txt"; try { if (extractedText.Length != 0) { Console.WriteLine($"Writing full document text to: {fileName}"); System.IO.File.WriteAllText( $"{System.IO.Directory.GetCurrentDirectory()}\\{fileName}", extractedText); // Get the number of pages in the input PDF int numPages = toolkit.NumPages(""); // Extract Text by Page for (int i = 1; i <= numPages; i++) { fileName = $"{System.IO.Path.GetRandomFileName()}_Page{i}.txt"; extractedText = extractor.ExtractText(i); System.IO.File.WriteAllText( $"{strPath}\\{fileName}", extractedText); } } else { Console.WriteLine("No text found in document."); } } catch (Exception e) { Console.WriteLine($"Exception caught creating image file ({fileName}): {e.Message}"); } // Close the new file to complete PDF creation toolkit.CloseInputFile(); } else { WriteResult($"Error opening input file: {result.ToString()}", toolkit); return; } } // Process Complete WriteResult("Success!"); }
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. // Add AES 256 bit encryption to the output PDF. Toolkit also // supports RC4 40 bit, RC4 128 bit and AES 128 bit. // 'DEMO' is appended to the start of the password with the evaluation version // Setting CanPrint to false will disable printing. toolkit.SetPDFSecurity(nEncrLevel: 5, UserPassword: "******", OwnerPassword: "******", CanPrint: false, CanEdit: true, CanCopy: true, CanModify: true, CanFillInFormFields: true, CanMakeAccessible: true, CanAssemble: true, CanReproduce: true); // Create the new PDF file int result = toolkit.OpenOutputFile(FileName: $"{strPath}Toolkit.DisablePrint.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. // 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!"); }
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!"); }
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 Ultimate\bin\x64"; // Instantiate Object using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(toolkitPath)) { // Get the Redactor object from Toolkit APToolkitNET.Redactor redactor = toolkit.GetRedactor(); int result = toolkit.OpenOutputFile(FileName: $"{strPath}Toolkit.RedactRegExs.pdf"); if (result == 0) { // Open the input PDF result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf"); if (result == 0) { string[] patterns = new string[] { // Pattern for all words starting with an 's' or // 'S' @"\b[s|S](\S+)\s?", // Pattern for all words starting with an 'a' or // 'A' @"\b[a|A](\S+)\s?" }; // Redact the expression pattern from the input PDF. // You may also redact individual pages setting the // page function argument, the default is all pages. redactor.RedactRegexs(regexs: patterns); // Call the Redactor Apply method to execute the // redaction process. All Toolkit methods normally // called between OpenInputFile and CopyForm // (PrintText, PrintImage etc.) must be after // Redactor.Apply redactor.Apply(); result = toolkit.CopyForm(FirstPage: 0, LastPage: 0); if (result != 1) { WriteResult("CopyForm Failed", toolkit); } // Close the new file to complete PDF creation toolkit.CloseInputFile(); } else { WriteResult($"Error opening input file: {result.ToString()}", toolkit); return; } } else { WriteResult($"Error opening output file: {result.ToString()}", toolkit); return; } } // Process Complete WriteResult("Success!"); }
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)) { // Get the Toolkit Bookmark Manager APToolkitNET.BookmarkManager bookmarkManager = toolkit.GetBookmarkManager(); // Set CopyBookmarks to true to create bookmarks in the output PDF. bookmarkManager.CopyBookmarks = true; // Create the new PDF file int result = toolkit.OpenOutputFile(FileName: $"{strPath}Toolkit.MakeRootAll.pdf"); if (result == 0) { // Open the template PDF result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf"); if (result == 0) { // Get the number of pages from the input PDF int numPages = toolkit.NumPages(FileName: ""); // Create a new root bookmark for all bookmarks to be // placed under. APToolkitNET.Bookmark root = bookmarkManager.MakeRoot( Title: "New Root", Color: "#FFA500", FontStyle: APToolkitNET.FontStyle.ItalicBold); // Add a book mark for each page for (int i = 0; i < numPages; ++i) { // Create a new bookmark for the page. APToolkitNET.Bookmark newBookmark = bookmarkManager.AddChild( Parent: root, Title: $"Page {i + 1}", Color: "#FFA500", FontStyle: APToolkitNET.FontStyle.Bold); // Set the page number and location to link newBookmark.SetInternalLink( DestPage: i + 1, LLX: 0, LLY: 0); } // 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; } } else { WriteResult($"Error opening input file: {result.ToString()}", toolkit); return; } // Close the new file to complete PDF creation toolkit.CloseOutputFile(); } else { WriteResult($"Error opening output file: {result.ToString()}", toolkit); return; } } // Process Complete WriteResult("Success!"); }
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.SetInfo.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. // Set the PDF metadata for the output PDF toolkit.SetInfo( Title: "Test PDF", Subject: "Testing", Author: "John Doe", Keywords: "test, pdf, sample"); // 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() { 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!"); }
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.SignPDF.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. // Find certificate, if it doesn't exist it will be created // If you have an existing signature you can find it with // FindCertificate and remove the portion of code that creates // the certificate int certificateID = toolkit.FindCertificate( CertName: "John Doe", Store: "My", LMStore: 0); if (certificateID < 1) { Console.WriteLine("Certificate not found, creating."); // Certificate not found, create a certificate with Toolkit int createCertResult = toolkit.CreateCertificate( CommonName: "John Doe", OrgUnit: "Management", Org: "Doe Enterprises", Local: "Mission Viejo", State: "CA", Country: "US", EMail: "*****@*****.**", UseLocalMachine: 0, CertStoreName: "My", DaysCertIsValid: 365, IssuerUseLocalMachine: 0, IssuerName: "", IssuerStoreName: ""); if (createCertResult == 1) { // New certificate created, find it for use certificateID = toolkit.FindCertificate( CertName: "John Doe", Store: "My", LMStore: 0); if (certificateID < 1) { WriteResult($"Failed to find new certificate after creation: {certificateID}"); } } else { WriteResult($"Failed to create new certificate: {createCertResult}"); } } // Invisibly sign the output file after any creation, merge or append operation. toolkit.SignOutputFile( SigNumber: certificateID, Location: "Mission Viejo", Reason: "Testing Toolkit PDF Signing.", ContactInfo: "http://www.activepdf.com", Encoding: 0); // 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!"); }
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.FillDBFields.pdf"); if (result != 0) { WriteResult($"Error opening output file: {result.ToString()}", toolkit); return; } // Specify the template form to populate toolkit.SetDBInputTemplate($"{strPath}Toolkit.DBTemplate.pdf"); // Set query command to a variable string strSQL = "Select * From Supplier"; // Set connection String to a variable string strConn = $"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={strPath}Toolkit.Input.mdb" + ";Persist Security Info=False"; // Set master query toolkit.SetMasterQuery( ConnectionString: strConn, UserID: "Admin", Password: "", Options: -1, QueryString: strSQL); // Set the row Separator toolkit.SetDBMultiRowSeparator(MultiRowSeparator: ""); // Related query separator is only needed if different from // default of '|' toolkit.RelatedQuerySeparator = "|"; // Add related query toolkit.AddRelatedQuery( ConnectionString: strConn, UserID: "Admin", Password: "", Options: -1, QueryString: strSQL, MultiRows: true); // If db column names are different then field names a map file // is needed. In this example only the zip/postal code is // different. result = toolkit.LoadDBMapFile(PathToMapFile: $"{strPath}Toolkit.DBFormmap.txt"); if (result != 0) { WriteResult($"Failed to load the map file: {result}", toolkit); return; } // Flatten fields that are populated with data toolkit.SetDefaultDBMergeFlag(DefaultMergeFlag: -997); // Flatten all other fields on the form toolkit.FlattenRemainingFormFields = 1; // Fill the template form result = toolkit.DBToForm(MultiPage: false); if (result != 0) { WriteResult($"DBToForm failed: {result}", toolkit); return; } // Clear and close used queries toolkit.ClearQueries(); // Close the new file to complete PDF creation toolkit.CloseOutputFile(); } // Process Complete WriteResult("Success!"); }