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; // Create the new PDF file int result = toolkit.OpenOutputFile($"{strPath}Toolkit.DownsampleImages.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!"); }
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 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; // Create the new PDF file int result = toolkit.OpenOutputFile($"{strPath}Toolkit.CompressObjects.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!"); }
static void Main(string[] args) { string strPath = System.AppDomain.CurrentDomain.BaseDirectory; // Instantiate Object using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit()) { // 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!"); }
static void Main(string[] args) { string strPath = System.AppDomain.CurrentDomain.BaseDirectory; // Instantiate Object using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit()) { // 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; // Create the new PDF file int result = toolkit.OpenOutputFile($"{strPath}Toolkit.DownsampleImages.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!"); }
static void Main(string[] args) { string strPath = System.AppDomain.CurrentDomain.BaseDirectory; // Instantiate Object using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit()) { // Instantiate the Compressor object APToolkitNET.Compressor compressor = toolkit.GetCompressor(); // 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; // Create the new PDF file int result = toolkit.OpenOutputFile($"{strPath}Toolkit.CompressObjects.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!"); }
static void Main(string[] args) { string strPath = System.AppDomain.CurrentDomain.BaseDirectory; // Instantiate Object using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit()) { // Instantiate the Compressor object APToolkitNET.Compressor compressor = toolkit.GetCompressor(); // Remove comments from the output PDF. compressor.DiscardComments = true; // Create the new PDF file int result = toolkit.OpenOutputFile($"{strPath}Toolkit.DiscardComments.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!"); }
static void Main(string[] args) { string strPath = System.AppDomain.CurrentDomain.BaseDirectory; // Instantiate Object using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit()) { // 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!"); }
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(); // Flatten form fields. compressor.FlattenFormFields = true; // 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.FlattenFormFields.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; // 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 = 50; // Change the resolution of images to 72 dpi. compressor.DownsampleImages = true; // Compress uncompressed PDF streams. compressor.EncodeStreams = true; // Flatten form fields. compressor.FlattenFormFields = 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; // 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.MediumCompression.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 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; // 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!"); }