コード例 #1
0
        public static void Example()
        {
            /*
             * Redacts the values in the document properties, as well as anything
             * that looks like an email address, from the document's metadata.
             */
            using (APRedactor.Redactor redact = new APRedactor.Redactor(
                       filename: @"..\..\..\Input\Redactor.Input.pdf"))
            {
                //You can redact specific values from the metadata like this.
                redact.MetadataLiteralText = new string[]
                {
                    "Digital", "ActivePDF"
                };

                //You can also redact values matching a pattern like this.
                //You can put any regex you want in place of our presets.
                redact.MetadataRegex = APRedactor.RegexPresets.EmailAddress;

                int redactionsPerformed = redact.Redact();
                Console.WriteLine($"{redactionsPerformed} performed on document.");
                redact.Save(@"..\..\..\Output\RedactMetadata.pdf");
                Console.WriteLine("Redacted page saved to RedactManyLiteralStrings.pdf");
            }
        }
コード例 #2
0
        /*
         * Redacts a number of secret terms from the input document, all at
         * once, by using IEnumerable<string>.
         */
        public static void Example()
        {
            using (APRedactor.Redactor redact = new APRedactor.Redactor(
                       filename: @"..\..\..\Input\Redactor.Input.pdf"))
            {
                // In this example, we use string[] for simplicity. However,
                // any IEnumerable<string> is allowed, including but not
                // limited to: List<string>, LinkedList<string>, Stack<string>,
                // Array<string>, HashSet<string>, etc.
                redact.PageLiteralText = new string[]
                {
                    "redactor", "redact", "Windows", "Microsoft",
                    "social security", "phone", "email", "date"
                };
                redact.TextMode =
                    APRedactor.Redactor.TextRedactionMode.LiteralText;

                // These are not limited to just content on pages. If you want
                // to remove these same terms from bookmarks, metadata, and
                // form fields, you can assign the same array to those
                // properties. You can just as easily redact different literals
                // from those sections of the document as well.
                redact.MetadataLiteralText = new string[]
                {
                    "Active", "PDF", "Redactor"
                };

                int redactionsPerformed = redact.Redact();
                Console.WriteLine($"{redactionsPerformed} performed on document.");
                redact.Save(filename: @"..\..\..\Output\RedactManyLiteralStrings.pdf");
                Console.WriteLine("Redacted page saved to RedactManyLiteralStrings.pdf");
            }
        }
コード例 #3
0
        public static void RedactByRegion_()
        {
            string strPath;

            strPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\";

            using (APRedactor.Redactor redact = new APRedactor.Redactor(strPath + "InputFiles\\5pageLoremIpsum.pdf", null))
            {
                redact.TextMode  = APRedactor.Redactor.TextRedactionMode.Region;
                redact.ImageMode = APRedactor.Redactor.ImageRedactionMode.Region;

                for (int pageNumber = 1; pageNumber <= redact.PageTotal; pageNumber++)
                {
                    redact.FirstPage = pageNumber;
                    redact.LastPage  = pageNumber;
                    float pageWidth, pageHeight;
                    redact.GetPageSize(pageNumber, out pageWidth, out pageHeight);
                    APRedactor.RedactRegion[] regions = new APRedactor.RedactRegion[]
                    {
                        new APRedactor.RedactRegion(pageNumber,
                                                    new APRedactor.Rectangle(pageWidth / 3, pageHeight / 3, pageWidth / 3, pageHeight / 3,
                                                                             APRedactor.Rectangle.CoordinateFrame.TopDown))
                    };
                    redact.TextRegions  = regions;
                    redact.ImageRegions = regions;
                    int redactionsPerformed = redact.Redact();
                }

                redact.Save(strPath + "OutPutFiles\\5pageLoremIpsumOutPutRedacted.pdf");
            }
        }
コード例 #4
0
 /*
  * Removes all text from all pages, and draws a black box on each page.
  */
 public static void Example()
 {
     using (APRedactor.Redactor redact = new APRedactor.Redactor(
                filename: @"..\..\..\Input\Redactor.Input.pdf"))
     {
         redact.TextMode =
             APRedactor.Redactor.TextRedactionMode.Unconditional;
         int redactionsPerformed = redact.Redact();
         redact.Save(@"..\..\..\Output\RedactEntirePage.pdf");
         Console.WriteLine("Redacted page saved to RedactEntirePage.pdf");
     }
 }
コード例 #5
0
 /*
  * Removes all text and images from pages.
  */
 public static void Example()
 {
     using (APRedactor.Redactor redact = new APRedactor.Redactor(
                filename: @"..\..\..\Input\Redactor.Input.pdf"))
     {
         redact.TextMode  = APRedactor.Redactor.TextRedactionMode.Unconditional;
         redact.ImageMode = APRedactor.Redactor.ImageRedactionMode.Unconditional;
         int redactionsPerformed = redact.Redact();
         Console.WriteLine($"{redactionsPerformed} text and image redactions performed on document.");
         redact.Save(filename: @"..\..\..\Output\RedactTextAndImages.pdf");
         Console.WriteLine("Redacted page saved to RedactTextAndImages.pdf");
     }
 }
コード例 #6
0
        public static void RedactEntirePage_()
        {
            string strPath;

            strPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\";

            using (APRedactor.Redactor redact = new APRedactor.Redactor(strPath + "InputFiles\\1page.pdf", null))
            {
                redact.TextMode = APRedactor.Redactor.TextRedactionMode.Unconditional;
                int redactionsPerformed = redact.Redact();
                redact.Save(strPath + "OutPutFiles\\RedactedEntirePageOutput.pdf");
            }
        }
コード例 #7
0
        public static void RedactText_()
        {
            string strPath;

            strPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\";

            using (APRedactor.Redactor redact = new APRedactor.Redactor(strPath + "InputFiles\\5pageLoremIpsum.pdf", null))
            {
                redact.LiteralText = "Lorem";
                redact.TextMode    = APRedactor.Redactor.TextRedactionMode.LiteralText;
                int redactionsPerformed = redact.Redact();
                redact.Save(strPath + "OutPutFiles\\RedactTextOutPut.pdf");
            }
        }
コード例 #8
0
        public static void RegexExclusion_()
        {
            string strPath;

            strPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\";

            using (APRedactor.Redactor redact = new APRedactor.Redactor(strPath + "InputFiles//PhoneNumberPDF.pdf", null))
            {
                redact.TextMode           = APRedactor.Redactor.TextRedactionMode.Regex;
                redact.RegularExpression  = APRedactor.RegexPresets.PhoneNumber;
                redact.RegexExclusionList = new string[] { "(555) 555-5555" };
                int redactionsPerformed = redact.Redact();
                redact.Save(strPath + "OutPutFiles\\RegexExclusionOutput.pdf");
            }
        }
コード例 #9
0
        public static void RedactMoney_()
        {
            string strPath;

            strPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\";


            using (APRedactor.Redactor redact = new APRedactor.Redactor(strPath + "InputFiles\\fw4.pdf", null))
            {
                redact.TextMode          = APRedactor.Redactor.TextRedactionMode.Regex;
                redact.RegularExpression = APRedactor.RegexPresets.USD;
                int redactionsPerformed = redact.Redact();
                redact.Save(strPath + "OutPutFiles\\RedactMoneyOutput.pdf");
            }
        }
コード例 #10
0
        public static void ChangeColor_()
        {
            string strPath;

            strPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\";

            using (APRedactor.Redactor redact = new APRedactor.Redactor(strPath + "InputFiles\\LoremIpsumSample.pdf", null))
            {
                redact.ReplacementColor = new APRedactor.Color(255, 0, 0);
                redact.LiteralText      = "Lorem";
                redact.TextMode         = APRedactor.Redactor.TextRedactionMode.LiteralText;
                int redactionsPerformed = redact.Redact();
                redact.Save("OutPutFiles\\OutLoremIpsumOutPutRedacted.pdf");
            }
        }
コード例 #11
0
 /*
  * Redacts the text "Hello, world!" (not case sensitive) from pages 5-10 only.
  */
 public static void Example()
 {
     using (APRedactor.Redactor redact = new APRedactor.Redactor(
                filename: @"..\..\..\Input\Redactor.Input.pdf"))
     {
         redact.PageLiteralText = new string[] { "the" };
         redact.TextMode        = APRedactor.Redactor.TextRedactionMode.LiteralText;
         redact.FirstPage       = 1;
         redact.LastPage        = 2;
         int redactionsPerformed = redact.Redact();
         redact.Save(@"..\..\..\Output\RedactRangeOfPages.pdf");
         Console.WriteLine($"{redactionsPerformed} redactions performed.");
         redact.Save(@"..\..\..\Output\RedactRangeOfPages.pdf");
         Console.WriteLine("Redacted page saved to RedactRangeOfPages.pdf");
     }
 }
コード例 #12
0
        static void RedactorEvent(object sender, APRedactor.RedactEventArgs args)
        {
            APRedactor.Redactor redact = sender as APRedactor.Redactor;
            Debug.Assert(redact != null);
            string eventType = "";

            if (args.EventType == APRedactor.RedactEventArgs.PageEventType.Start)
            {
                eventType = "Started";
            }
            else if (args.EventType == APRedactor.RedactEventArgs.PageEventType.End)
            {
                eventType = "Completed";
            }
            Console.WriteLine("{0} processing page {1} of {2}.", eventType, args.PageNumber, redact.Filename);
        }
コード例 #13
0
        public static void RedactionEvent_()
        {
            string strPath;

            strPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\";

            using (APRedactor.Redactor redact = new APRedactor.Redactor(strPath + "InputFiles\\1page.pdf", null))
            {
                redact.TextMode      = APRedactor.Redactor.TextRedactionMode.LiteralText;
                redact.LiteralText   = "Lorem";
                redact.PageBegin    += RedactorEvent;
                redact.PageComplete += RedactorEvent;
                int redactionsPerformed = redact.Redact();
                redact.Save(strPath + "OutPutFiles\\RedactionEventsOutput.pdf");
            }
        }
コード例 #14
0
        /*
         * Use a regular expression to find and redact content on pages,
         * metadata, bookmarks, and form fields.
         */
        public static void Example()
        {
            using (APRedactor.Redactor redact = new APRedactor.Redactor(
                       filename: @"..\..\..\Input\Redactor.Input.pdf"))
            {
                // You can also find some common use cases in
                // APRedactor.RegexPresets
                redact.TextMode = APRedactor.Redactor.TextRedactionMode.Regex;

                // Redact the word "Family" from bookmark titles
                redact.BookmarkRegex = new Regex(pattern: @"Family");

                // Redact "field" from the text fields
                redact.FormFieldRegex = new Regex(pattern: @"(?-i)field");

                // Redact instances of "PDF" from the metadata
                redact.MetadataRegex = new Regex(pattern: @"(?-i)PDF");

                // Redact all words that begin with 'v' or 'V'
                redact.PageRegex = new Regex(pattern: @"\b[v|V](\S+)\s?");

                int redactionsPerformed = redact.Redact();
                Console.WriteLine($"{redactionsPerformed} redactions performed.");

                // You can view what literals were found in the document after the
                // redaction is done.
                foreach (Tuple <int, string> match in redact.PageRegexMatches)
                {
                    Console.WriteLine($"Redacted {match.Item2} on page {match.Item1}.");
                }
                foreach (string match in redact.BookmarkRegexMatches)
                {
                    Console.WriteLine($"Redacted {match} from bookmarks.");
                }
                foreach (string match in redact.FormFieldRegexMatches)
                {
                    Console.WriteLine($"Redacted {match} from form fields.");
                }
                foreach (string match in redact.MetadataRegexMatches)
                {
                    Console.WriteLine($"Redacted {match} from metadata.");
                }
                redact.Save(filename: @"..\..\..\Output\RedactByRegex.pdf");
                Console.WriteLine("Redacted page saved to RedactByRegex.pdf");
            }
        }
コード例 #15
0
        /*
         * Redacts the literal text "test" and "using" from any form
         * fields on pages. It also uses a regular expression to find and
         * remove anything that looks like an amount in US dollars.
         */
        public static void Example()
        {
            using (APRedactor.Redactor redact = new APRedactor.Redactor(@"..\..\..\Input\Redactor.Input.pdf"))
            {
                //You can find specific values to remove like this.
                redact.FormFieldLiteralText = new string[] { "test", "using" };

                //You can also remove content matching a pattern like this.
                //This one will catch both of the literals from the previous line as well.
                redact.FormFieldRegex = APRedactor.RegexPresets.USD;

                int redactionsPerformed = redact.Redact();
                Console.WriteLine($"{redactionsPerformed} redactions performed.");
                redact.Save(@"..\..\..\Output\RedactFormFields.pdf");
                Console.WriteLine("Redacted page saved to RedactFormFields.pdf");
            }
        }
コード例 #16
0
        /*
         * Shows an example of redacting individual pixels from an image
         * contained on a page. This is useful for a number of applications,
         * including: removing some copyrighted logo from an image, removing
         * some faces from a photo, removing text stored as an image because
         * the document was scanned, or anything else. The color that the
         * pixels are replaced with is set by the ReplacementColor property.
         */
        public static void Example()
        {
            using (APRedactor.Redactor redact = new APRedactor.Redactor(
                       filename: @"..\..\..\Input\Redactor.Input.pdf"))
            {
                // Getting the coordinates for what to redact is left to you,
                // as they vary from document to document. Remember that you
                // can call Redactor.GetPageSize() to get the size of each page
                // as a starting point. You can combine Redactor with tools
                // like ActivePDF Rasterizer to get images to display, allowing
                // the user to draw boxes that you can convert to coordinates.
                // Or you can use ActivePDF Extractor to find the coordinates
                // of specific content. Or, if you are redacting many documents
                // with the same layout, you can figure out the coordinates
                //once and apply them to all inputs.

                // This creates an array of regions that will find two
                // rectangles on page 1, one on page 2, and one on page 3.
                // Since the ImageMode is set to Subregion, it only applies to
                // individual pixels found in those rectangles. You can use the
                // same regions for Text by setting the TextMode to Region and
                // assigning to the TextRegions property, if you desire.
                APRedactor.RedactRegion[] regions = new APRedactor.RedactRegion[]
                {
                    new APRedactor.RedactRegion(
                        pageNumber: 1,
                        region: new APRedactor.Rectangle(x: 284.5125f,
                                                         y: 122.2324f,
                                                         w: 202.5f,
                                                         h: 118.4625f))
                };

                // Don't forget to update the file given to the Constructor and
                // the Save function! Be sure to set the text or image mode or
                // the test will do nothing! These apply only to images stored
                // within the PDF, and will not affect any text or graphics.
                redact.TextMode  = APRedactor.Redactor.TextRedactionMode.None;
                redact.ImageMode =
                    APRedactor.Redactor.ImageRedactionMode.Subregion;
                redact.ImageRegions = regions;

                int redactionsPerformed = redact.Redact();
                redact.Save(filename: @"..\..\..\Output\RedactIndividualPixels.pdf");
                Console.WriteLine("Redacted page saved to RedactIndividualPixels.pdf");
            }
        }
コード例 #17
0
        public static void RedactRangeOfPage_()
        {
            string strPath;

            strPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\";

            using (APRedactor.Redactor redact = new APRedactor.Redactor(strPath + "InputFiles\\LoremIpsumSample.pdf", null))
            {
                redact.LiteralText = "Lorem";
                redact.TextMode    = APRedactor.Redactor.TextRedactionMode.LiteralText;
                Debug.Assert(redact.PageTotal >= 10);
                redact.FirstPage = 5;
                redact.LastPage  = 10;
                int redactionsPerformed = redact.Redact();
                redact.Save(strPath + "OutPutFiles\\RangeOfPagesOutput.pdf");
            }
        }
コード例 #18
0
        /*
         * Redacts all phone number instances on pages using a Regular
         * Expression.
         */
        public static void Example()
        {
            using (APRedactor.Redactor redact = new APRedactor.Redactor(
                       filename: @"..\..\..\Input\Redactor.Input.pdf"))
            {
                // Redactor supports a wide range of preset regular expressions
                // from phone numbers, dates, email addresses and more.
                redact.PageRegex = APRedactor.RegexPresets.PhoneNumber;
                redact.TextMode  = APRedactor.Redactor.TextRedactionMode.Regex;

                redact.FormFieldRegex = APRedactor.RegexPresets.USD;

                int redactionsPerformed = redact.Redact();
                Console.WriteLine($"{redactionsPerformed} redaction performed on document.");
                redact.Save(@"..\..\..\Output\RedactPreset.pdf");
                Console.WriteLine("Redacted page saved to RedactPreset.pdf");
            }
        }
コード例 #19
0
        /*
         * Redacts bookmarks in the document, using both search-and-replace
         * literals and match-and-replace regex.
         */
        public static void Example()
        {
            using (APRedactor.Redactor redact = new APRedactor.Redactor(
                       filename: @"..\..\..\Input\Redactor.Input.pdf"))
            {
                // You can remove specific bookmarks like this which will
                // redact a bookmark with the title "ActivePDF"
                redact.BookmarkLiteralText = new string[] { "ActivePDF" };

                // You can also remove bookmarks matching a pattern like this.
                // This example will redact all bookmark titles beginning with\
                // 'd' or 'D'
                redact.BookmarkRegex = new Regex(pattern: @"\b[d|D](\S+)\s?");

                int redactionsPerformed = redact.Redact();
                Console.WriteLine($"{redactionsPerformed} redactions performed.");
                redact.Save(filename: @"..\..\..\Output\RedactBookmarks.pdf");
                Console.WriteLine("Redacted page saved to RedactImages.pdf");
            }
        }
コード例 #20
0
        public static void SaveOption_()
        {
            string strPath;

            strPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\";

            using (APRedactor.Redactor redact = new APRedactor.Redactor(strPath + "Inputfiles\\5pageLoremIpsum.pdf", null))
            {
                APRedactor.Redactor.SaveOptions options =
                    APRedactor.Redactor.SaveOptions.CleanContentStreams |
                    APRedactor.Redactor.SaveOptions.CompressFonts |
                    APRedactor.Redactor.SaveOptions.CompressImages |
                    APRedactor.Redactor.SaveOptions.CompressStreams |
                    APRedactor.Redactor.SaveOptions.GarbageCollectDeDuplicate |
                    APRedactor.Redactor.SaveOptions.Linearize |
                    APRedactor.Redactor.SaveOptions.SanitizeContentStreams;

                redact.LiteralText = "Lorem";
                redact.TextMode    = APRedactor.Redactor.TextRedactionMode.LiteralText;
                int redactionsPerformed = redact.Redact();
                redact.Save(strPath + "OutPutFiles\\SaveOptionsOutput.pdf", options);
            }
        }
コード例 #21
0
        /*
         * Uses a regular expression to find and redact phone numbers on pages,
         * but excludes the number "(555) 555-5555" whenever it is found,
         * leaving it unredacted.
         */
        public static void Example()
        {
            using (APRedactor.Redactor redact = new APRedactor.Redactor(
                       filename: @"..\..\..\Input\Redactor.Input.pdf"))
            {
                redact.TextMode  = APRedactor.Redactor.TextRedactionMode.Regex;
                redact.PageRegex = APRedactor.RegexPresets.PhoneNumber;

                // It is not used in this example, but the RegexExclusionList
                // also applies to the MetadataRegex, BookmarkRegex, and
                // FormFieldRegex properties in addition to the PageRegex
                // property.
                // Comment out the next line and the phone number at the bottom
                // of page two will be redacted.
                redact.RegexExclusionList = new string[] { "866-468-6733" };

                int redactionsPerformed = redact.Redact();
                redact.Save(@"..\..\..\Output\RegexExclusion.pdf");
                Console.WriteLine($"{redactionsPerformed} text and image redactions performed on document.");
                redact.Save(filename: @"..\..\..\Output\RegexExclusion.pdf");
                Console.WriteLine("Redacted page saved to RegexExclusion.pdf");
            }
        }
コード例 #22
0
 /*
  * Redacts both text and images that are contained the middle third of
  * each page. Because each page of a document can be a different size,
  * it is necessary to fetch the size of a page, and perform the
  * redaction operation, one page at a time.
  */
 public static void Example()
 {
     using (APRedactor.Redactor redact = new APRedactor.Redactor(
                filename: @"..\..\..\Input\Redactor.Input.pdf"))
     {
         redact.TextMode  = APRedactor.Redactor.TextRedactionMode.Region;
         redact.ImageMode =
             APRedactor.Redactor.ImageRedactionMode.Region;
         for (int pageNumber = 1;
              pageNumber <= redact.PageTotal;
              pageNumber++)
         {
             redact.FirstPage = redact.LastPage = pageNumber;
             float pageWidth, pageHeight;
             redact.GetPageSize(
                 pageNumber: pageNumber,
                 width: out pageWidth,
                 height: out pageHeight);
             APRedactor.RedactRegion[] regions =
                 new APRedactor.RedactRegion[]
             {
                 new APRedactor.RedactRegion(pageNumber: pageNumber,
                                             region: new APRedactor.Rectangle(
                                                 x: pageWidth / 3,
                                                 y: pageHeight / 3,
                                                 w: pageWidth / 3,
                                                 h: pageHeight / 3))
             };
             redact.TextRegions  = regions;
             redact.ImageRegions = regions;
             int redactionsPerformed = redact.Redact();
             Console.WriteLine($"{redactionsPerformed} on Page {pageNumber}");
         }
         redact.Save(@"..\..\..\Output\RedactByRegion.pdf");
         Console.WriteLine("Redacted page saved to RedactByRegion.pdf");
     }
 }
コード例 #23
0
        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!");
        }