public static void PopulateOperators(PdfContentStreamProcessor contentProcessor,
                              PdfCleanUpRenderListener pdfCleanUpRenderListener) {
     foreach (String oper in contentProcessor.RegisteredOperatorStrings) {
         PdfCleanUpContentOperator contentOperator = new PdfCleanUpContentOperator(pdfCleanUpRenderListener);
         contentOperator.originalContentOperator = contentProcessor.RegisterContentOperator(oper, contentOperator);
     }
 }
 public static void PopulateOperators(PdfContentStreamProcessor contentProcessor,
                                      PdfCleanUpRenderListener pdfCleanUpRenderListener)
 {
     foreach (String oper in contentProcessor.RegisteredOperatorStrings)
     {
         PdfCleanUpContentOperator contentOperator = new PdfCleanUpContentOperator(pdfCleanUpRenderListener);
         contentOperator.originalContentOperator = contentProcessor.RegisterContentOperator(oper, contentOperator);
     }
 }
        public static void PopulateOperators(PdfContentStreamProcessor contentProcessor,
                                             PdfCleanUpRenderListener pdfCleanUpRenderListener)
        {
            String[] operators = new String[] {
                PdfContentStreamProcessor.DEFAULTOPERATOR, "q", "Q", "g", "G", "rg", "RG", "k", "K",
                "cs", "CS", "sc", "SC", "scn", "SCN", "cm", "gs", "Tc", "Tw", "Tz", "TL", "Tf", "Tr",
                "Ts", "BT", "ET", "BMC", "BDC", "EMC", "Td", "TD", "Tm", "T*", "Tj", "'", "\"", "TJ", "Do"
            };

            foreach (String @operator in operators)
            {
                PdfCleanUpContentOperator contentOperator = new PdfCleanUpContentOperator(pdfCleanUpRenderListener);
                contentOperator.originalContentOperator = contentProcessor.RegisterContentOperator(@operator, contentOperator);
            }
        }
예제 #4
0
        private void CleanUpPage(int pageNum, IList <PdfCleanUpLocation> cleanUpLocations)
        {
            if (cleanUpLocations.Count == 0)
            {
                return;
            }

            PdfReader      pdfReader = pdfStamper.Reader;
            PdfDictionary  page      = pdfReader.GetPageN(pageNum);
            PdfContentByte canvas    = pdfStamper.GetUnderContent(pageNum);

            byte[] pageContentInput = ContentByteUtils.GetContentBytesForPage(pdfReader, pageNum);
            page.Remove(PdfName.CONTENTS);

            canvas.SaveState();

            PdfCleanUpRegionFilter   filter = CreateFilter(cleanUpLocations);
            PdfCleanUpRenderListener pdfCleanUpRenderListener = new PdfCleanUpRenderListener(pdfStamper, filter);

            pdfCleanUpRenderListener.RegisterNewContext(pdfReader.GetPageResources(page), canvas);

            PdfContentStreamProcessor contentProcessor = new PdfContentStreamProcessor(pdfCleanUpRenderListener);

            PdfCleanUpContentOperator.PopulateOperators(contentProcessor, pdfCleanUpRenderListener);
            contentProcessor.ProcessContent(pageContentInput, page.GetAsDict(PdfName.RESOURCES));
            pdfCleanUpRenderListener.PopContext();

            canvas.RestoreState();

            ColorCleanedLocations(canvas, cleanUpLocations);

            if (redactAnnotIndirRefs != null)   // if it isn't null, then we are in "extract locations from redact annots" mode
            {
                DeleteRedactAnnots(pageNum);
            }
        }
예제 #5
0
        private void CleanUpPage(int pageNum, IList<PdfCleanUpLocation> cleanUpLocations) {
            if (cleanUpLocations.Count == 0) {
                return;
            }

            PdfReader pdfReader = pdfStamper.Reader;
            PdfDictionary page = pdfReader.GetPageN(pageNum);
            PdfContentByte canvas = pdfStamper.GetUnderContent(pageNum);
            byte[] pageContentInput = ContentByteUtils.GetContentBytesForPage(pdfReader, pageNum);
            page.Remove(PdfName.CONTENTS);

            canvas.SaveState();

            PdfCleanUpRegionFilter filter = CreateFilter(cleanUpLocations);
            PdfCleanUpRenderListener pdfCleanUpRenderListener = new PdfCleanUpRenderListener(pdfStamper, filter);
            pdfCleanUpRenderListener.RegisterNewContext(pdfReader.GetPageResources(page), canvas);

            PdfContentStreamProcessor contentProcessor = new PdfContentStreamProcessor(pdfCleanUpRenderListener);
            PdfCleanUpContentOperator.PopulateOperators(contentProcessor, pdfCleanUpRenderListener);
            contentProcessor.ProcessContent(pageContentInput, page.GetAsDict(PdfName.RESOURCES));
            pdfCleanUpRenderListener.PopContext();

            canvas.RestoreState();

            ColorCleanedLocations(canvas, cleanUpLocations);

            if (redactAnnotIndirRefs != null) { // if it isn't null, then we are in "extract locations from redact annots" mode
                DeleteRedactAnnots(pageNum);
            }
        }
 public PdfCleanUpContentOperator(PdfCleanUpRenderListener cleanUpStrategy)
 {
     this.cleanUpStrategy = cleanUpStrategy;
 }
 public PdfCleanUpContentOperator(PdfCleanUpRenderListener cleanUpStrategy) {
     this.cleanUpStrategy = cleanUpStrategy;
 }