Example #1
0
 /// <summary>
 /// Creates a
 /// <see cref="PdfCleanUpTool"/>
 /// object. If
 /// <paramref name="cleanRedactAnnotations"/>
 /// is true,
 /// regions to be erased are extracted from the redact annotations contained inside the given document.
 /// Those redact annotations will be removed from the resultant document. If
 /// <paramref name="cleanRedactAnnotations"/>
 /// is false,
 /// then no regions for erasing are specified. In that case use
 /// <see cref="AddCleanupLocation(PdfCleanUpLocation)"/>
 /// method to set regions to be erased from the document.
 /// </summary>
 /// <param name="pdfDocument">
 /// A
 /// <see cref="iText.Kernel.Pdf.PdfDocument"/>
 /// object representing the document
 /// to which redaction applies.
 /// </param>
 /// <param name="cleanRedactAnnotations">
 /// if true - regions to be erased are extracted from the redact annotations contained
 /// inside the given document.
 /// </param>
 public PdfCleanUpTool(PdfDocument pdfDocument, bool cleanRedactAnnotations)
 {
     try
     {
         String licenseKeyClassName        = "iText.License.LicenseKey, itext.licensekey";
         String licenseKeyProductClassName = "iText.License.LicenseKeyProduct, itext.licensekey";
         String licenseKeyFeatureClassName = "iText.License.LicenseKeyProductFeature, itext.licensekey";
         String checkLicenseKeyMethodName  = "ScheduledCheck";
         Type   licenseKeyClass            = GetClass(licenseKeyClassName);
         if (licenseKeyClass != null)
         {
             Type     licenseKeyProductClass        = GetClass(licenseKeyProductClassName);
             Type     licenseKeyProductFeatureClass = GetClass(licenseKeyFeatureClassName);
             Array    array   = Array.CreateInstance(licenseKeyProductFeatureClass, 0);
             object[] objects = new object[]
             {
                 PdfCleanupProductInfo.PRODUCT_NAME,
                 PdfCleanupProductInfo.MAJOR_VERSION,
                 PdfCleanupProductInfo.MINOR_VERSION,
                 array
             };
             Object     productObject = System.Activator.CreateInstance(licenseKeyProductClass, objects);
             MethodInfo m             = licenseKeyClass.GetMethod(checkLicenseKeyMethodName);
             m.Invoke(System.Activator.CreateInstance(licenseKeyClass), new object[] { productObject });
         }
     }
     catch (Exception e)
     {
         if (!Kernel.Version.IsAGPLVersion())
         {
             throw;
         }
     }
     if (pdfDocument.GetReader() == null || pdfDocument.GetWriter() == null)
     {
         throw new PdfException(PdfException.PdfDocumentMustBeOpenedInStampingMode);
     }
     this.pdfDocument         = pdfDocument;
     this.pdfCleanUpLocations = new Dictionary <int, IList <PdfCleanUpLocation> >();
     this.filteredImagesCache = new FilteredImagesCache();
     if (cleanRedactAnnotations)
     {
         AddCleanUpLocationsBasedOnRedactAnnotations();
     }
     processAnnotations = true;
 }
 internal virtual FilteredImagesCache.FilteredImageKey CreateFilteredImageKey(ImageRenderInfo image, PdfDocument
                                                                              document)
 {
     return(FilteredImagesCache.CreateFilteredImageKey(image, GetImageAreasToBeCleaned(image), document));
 }