Exemple #1
0
 /// <seealso cref= "PdfOperator.Process(OCGParser, PdfLiteral, List{T})"> </seealso>
 virtual public void Process(OCGParser parser, PdfLiteral @operator, IList <PdfObject> operands)
 {
     if (parser.IsVisible(operands))
     {
         parser.Process(@operator, operands, true);
     }
 }
Exemple #2
0
        /// <summary>
        /// Uses the OCGParser on a page </summary>
        /// <param name="parser">	the OCGParser </param>
        /// <param name="page">		the page dictionary of the page that needs to be parsed. </param>
        /// <exception cref="IOException"> </exception>
        private void Parse(OCGParser parser, PdfDictionary page)
        {
            PRStream      stream    = (PRStream)page.GetAsStream(PdfName.CONTENTS);
            PdfDictionary resources = page.GetAsDict(PdfName.RESOURCES);

            parser.Parse(stream, resources);
        }
Exemple #3
0
 /// <summary>
 /// Removes layers from a PDF document </summary>
 /// <param name="reader">	a PdfReader containing a PDF document </param>
 /// <param name="layers">	a sequence of names of OCG layers </param>
 /// <exception cref="IOException"> </exception>
 public virtual void RemoveLayers(PdfReader reader, params string[] layers)
 {
     int n = reader.NumberOfPages;
     ICollection<string> ocgs = new HashSet2<string>();
     for (int i = 0; i < layers.Length; i++)
     {
         ocgs.Add(layers[i]);
     }
     OCGParser parser = new OCGParser(ocgs);
     for (int i = 1; i <= n; i++)
     {
         PdfDictionary page = reader.GetPageN(i);
         Parse(parser, page);
         page.Remove(new PdfName("PieceInfo"));
         RemoveAnnots(page, ocgs);
         RemoveProperties(page, ocgs);
     }
     PdfDictionary root = reader.Catalog;
     PdfDictionary ocproperties = root.GetAsDict(PdfName.OCPROPERTIES);
     RemoveOCGsFromArray(ocproperties, PdfName.OCGS, ocgs);
     PdfDictionary d = ocproperties.GetAsDict(PdfName.D);
     if (d != null)
     {
         RemoveOCGsFromArray(d, PdfName.ON, ocgs);
         RemoveOCGsFromArray(d, PdfName.OFF, ocgs);
         RemoveOCGsFromArray(d, PdfName.LOCKED, ocgs);
         RemoveOCGsFromArray(d, PdfName.RBGROUPS, ocgs);
         RemoveOCGsFromArray(d, PdfName.ORDER, ocgs);
         RemoveOCGsFromArray(d, PdfName.AS, ocgs);
     }
     reader.RemoveUnusedObjects();
 }
Exemple #4
0
        /// <summary>
        /// Processes an operator. </summary>
        /// <param name="parser">	the parser that needs to process the operator </param>
        /// <param name="operator">	the operator </param>
        /// <param name="operands">	its operands </param>
        /// <exception cref="Exception"> </exception>
        protected internal static void ProcessOperator(OCGParser parser, PdfLiteral @operator, IList <PdfObject> operands)
        {
            PdfOperator op;

            if (!operators.TryGetValue(@operator.ToString(), out op) || op == null)
            {
                op = operators[DEFAULTOPERATOR];
            }
            op.Process(parser, @operator, operands);
        }
Exemple #5
0
        /// <summary>
        /// Removes layers from a PDF document </summary>
        /// <param name="reader">	a PdfReader containing a PDF document </param>
        /// <param name="layers">	a sequence of names of OCG layers </param>
        /// <exception cref="IOException"> </exception>
        public virtual void RemoveLayers(PdfReader reader, params string[] layers)
        {
            int n = reader.NumberOfPages;

            for (int i = 1; i <= n; i++)
            {
                reader.SetPageContent(i, reader.GetPageContent(i));
            }
            ICollection <string> ocgs = new HashSet2 <string>();

            for (int i = 0; i < layers.Length; i++)
            {
                ocgs.Add(layers[i]);
            }
            OCGParser parser = new OCGParser(ocgs);

            for (int i = 1; i <= n; i++)
            {
                PdfDictionary page = reader.GetPageN(i);
                Parse(parser, page);
                page.Remove(PdfName.PIECEINFO);
                RemoveAnnots(page, ocgs);
                RemoveProperties(page, ocgs);
            }
            PdfDictionary root         = reader.Catalog;
            PdfDictionary ocproperties = root.GetAsDict(PdfName.OCPROPERTIES);

            if (ocproperties != null)
            {
                RemoveOCGsFromArray(ocproperties, PdfName.OCGS, ocgs);
                PdfDictionary d = ocproperties.GetAsDict(PdfName.D);
                if (d != null)
                {
                    RemoveOCGsFromArray(d, PdfName.ON, ocgs);
                    RemoveOCGsFromArray(d, PdfName.OFF, ocgs);
                    RemoveOCGsFromArray(d, PdfName.LOCKED, ocgs);
                    RemoveOCGsFromArray(d, PdfName.RBGROUPS, ocgs);
                    RemoveOCGsFromArray(d, PdfName.ORDER, ocgs);
                    RemoveOCGsFromArray(d, PdfName.AS, ocgs);
                }
                PdfArray ocgsArray = ocproperties.GetAsArray(PdfName.OCGS);
                if (ocgsArray != null && ocgsArray.IsEmpty())
                {
                    root.Remove(PdfName.OCPROPERTIES);
                    if (PdfName.USEOC.Equals(root.GetAsName(PdfName.PAGEMODE)))
                    {
                        root.Remove(PdfName.PAGEMODE);
                    }
                }
            }
            reader.RemoveUnusedObjects();
        }
Exemple #6
0
 /// <seealso cref= "PdfOperator.Process(OCGParser, PdfLiteral, List{T})"> </seealso>
 virtual public void Process(OCGParser parser, PdfLiteral @operator, IList <PdfObject> operands)
 {
     if ("BDC".Equals(@operator.ToString()) && operands.Count > 1 && PdfName.OC.Equals(operands[0]))
     {
         parser.CheckMarkedContentStart((PdfName)operands[1]);
     }
     else if ("BMC".Equals(@operator.ToString()))
     {
         parser.CheckMarkedContentStart(null);
     }
     parser.Process(@operator, operands, true);
     if ("EMC".Equals(@operator.ToString()))
     {
         parser.CheckMarkedContentEnd();
     }
 }
Exemple #7
0
 /// <summary>
 /// Removes layers from a PDF document </summary>
 /// <param name="reader">	a PdfReader containing a PDF document </param>
 /// <param name="layers">	a sequence of names of OCG layers </param>
 /// <exception cref="IOException"> </exception>
 public virtual void RemoveLayers(PdfReader reader, params string[] layers) {
     int n = reader.NumberOfPages;
     for (int i = 1; i <= n; i++)
         reader.SetPageContent(i, reader.GetPageContent(i));
     ICollection<string> ocgs = new HashSet2<string>();
     for (int i = 0; i < layers.Length; i++) {
         ocgs.Add(layers[i]);
     }
     OCGParser parser = new OCGParser(ocgs);
     for (int i = 1; i <= n; i++) {
         PdfDictionary page = reader.GetPageN(i);
         Parse(parser, page);
         page.Remove(PdfName.PIECEINFO);
         RemoveAnnots(page, ocgs);
         RemoveProperties(page, ocgs);
     }
     PdfDictionary root = reader.Catalog;
     PdfDictionary ocproperties = root.GetAsDict(PdfName.OCPROPERTIES);
     if (ocproperties != null) {
         RemoveOCGsFromArray(ocproperties, PdfName.OCGS, ocgs);
         PdfDictionary d = ocproperties.GetAsDict(PdfName.D);
         if (d != null) {
             RemoveOCGsFromArray(d, PdfName.ON, ocgs);
             RemoveOCGsFromArray(d, PdfName.OFF, ocgs);
             RemoveOCGsFromArray(d, PdfName.LOCKED, ocgs);
             RemoveOCGsFromArray(d, PdfName.RBGROUPS, ocgs);
             RemoveOCGsFromArray(d, PdfName.ORDER, ocgs);
             RemoveOCGsFromArray(d, PdfName.AS, ocgs);
         }
         PdfArray ocgsArray = ocproperties.GetAsArray(PdfName.OCGS);
         if (ocgsArray != null && ocgsArray.IsEmpty()) {
             root.Remove(PdfName.OCPROPERTIES);
             if (PdfName.USEOC.Equals(root.GetAsName(PdfName.PAGEMODE))) {
                 root.Remove(PdfName.PAGEMODE);
             }
         }
     }
     reader.RemoveUnusedObjects();
 }
Exemple #8
0
        /// <summary>
        /// Removes layers from a PDF document </summary>
        /// <param name="reader">	a PdfReader containing a PDF document </param>
        /// <param name="layers">	a sequence of names of OCG layers </param>
        /// <exception cref="IOException"> </exception>
        public virtual void RemoveLayers(PdfReader reader, params string[] layers)
        {
            int n = reader.NumberOfPages;
            ICollection <string> ocgs = new HashSet2 <string>();

            for (int i = 0; i < layers.Length; i++)
            {
                ocgs.Add(layers[i]);
            }
            OCGParser parser = new OCGParser(ocgs);

            for (int i = 1; i <= n; i++)
            {
                PdfDictionary page = reader.GetPageN(i);
                Parse(parser, page);
                page.Remove(new PdfName("PieceInfo"));
                RemoveAnnots(page, ocgs);
                RemoveProperties(page, ocgs);
            }
            PdfDictionary root         = reader.Catalog;
            PdfDictionary ocproperties = root.GetAsDict(PdfName.OCPROPERTIES);

            RemoveOCGsFromArray(ocproperties, PdfName.OCGS, ocgs);
            PdfDictionary d = ocproperties.GetAsDict(PdfName.D);

            if (d != null)
            {
                RemoveOCGsFromArray(d, PdfName.ON, ocgs);
                RemoveOCGsFromArray(d, PdfName.OFF, ocgs);
                RemoveOCGsFromArray(d, PdfName.LOCKED, ocgs);
                RemoveOCGsFromArray(d, PdfName.RBGROUPS, ocgs);
                RemoveOCGsFromArray(d, PdfName.ORDER, ocgs);
                RemoveOCGsFromArray(d, PdfName.AS, ocgs);
            }
            reader.RemoveUnusedObjects();
        }
Exemple #9
0
 /// <seealso cref= "PdfOperator.Process(OCGParser, PdfLiteral, List{T})"> </seealso>
 virtual public void Process(OCGParser parser, PdfLiteral @operator, IList <PdfObject> operands)
 {
     parser.Process(@operator, operands, false);
 }
Exemple #10
0
 /// <summary>
 /// Uses the OCGParser on a page </summary>
 /// <param name="parser">	the OCGParser </param>
 /// <param name="page">		the page dictionary of the page that needs to be parsed. </param>
 /// <exception cref="IOException"> </exception>
 private void Parse(OCGParser parser, PdfDictionary page) {
     PRStream stream = (PRStream) page.GetAsStream(PdfName.CONTENTS);
     PdfDictionary resources = page.GetAsDict(PdfName.RESOURCES);
     parser.Parse(stream, resources);
 }
Exemple #11
0
 /// <seealso cref= "PdfOperator.Process(OCGParser, PdfLiteral, List{T})"> </seealso>
 public void Process(OCGParser parser, PdfLiteral @operator, IList<PdfObject> operands) {
     if (parser.IsVisible(operands)) {
         parser.Process(@operator, operands, true);
     }
 }
Exemple #12
0
 /// <seealso cref= "PdfOperator.Process(OCGParser, PdfLiteral, List{T})"> </seealso>
 public void Process(OCGParser parser, PdfLiteral @operator, IList<PdfObject> operands) {
     if ("BDC".Equals(@operator.ToString()) && operands.Count > 1 && PdfName.OC.Equals(operands[0])) {
         parser.CheckMarkedContentStart((PdfName) operands[1]);
     }
     else if ("BMC".Equals(@operator.ToString())) {
         parser.CheckMarkedContentStart(null);
     }
     parser.Process(@operator, operands, true);
     if ("EMC".Equals(@operator.ToString())) {
         parser.CheckMarkedContentEnd();
     }
 }
Exemple #13
0
 /// <seealso cref= "PdfOperator.Process(OCGParser, PdfLiteral, List{T})"> </seealso>
 public void Process(OCGParser parser, PdfLiteral @operator, IList<PdfObject> operands) {
     parser.Process(@operator, operands, false);
 }
Exemple #14
0
 /// <summary>
 /// Processes an operator. </summary>
 /// <param name="parser">	the parser that needs to process the operator </param>
 /// <param name="operator">	the operator </param>
 /// <param name="operands">	its operands </param>
 /// <exception cref="Exception"> </exception>
 protected internal static void ProcessOperator(OCGParser parser, PdfLiteral @operator, IList<PdfObject> operands) {
     PdfOperator op = operators[@operator.ToString()];
     if (op == null) {
         op = operators[DEFAULTOPERATOR];
     }
     op.Process(parser, @operator, operands);
 }