Ejemplo n.º 1
0
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List <PdfObject> operands)
            {
                var proc      = (PdfContentStreamEditor)processor;
                var isXObject = "Do" == oper.ToString();

                if (isXObject)
                {
                    if (proc.XObjectLevel == 0)
                    {
                        proc.IsWatermark = false;
                    }
                    proc.XObjectLevel++;
                }
                if (!isXObject && operands.Count == 2 && proc.XObjectLevel > 0 && proc.RemoveXObjects)
                {
                    var op = operands[1].ToString();
                    if ((op == "Tj" || op == "TJ") && proc.Watermark.IsMatch(operands[0].ToString()))
                    {
                        proc.IsWatermark = true;
                        proc.WatermarkCount++;
                    }
                }

                OriginalOperator?.Invoke(processor, oper, operands);

                if (isXObject)
                {
                    proc.XObjectLevel--;
                }
                if (isXObject && proc.IsWatermark && proc.RemoveXObjects)
                {
                    return;
                }
                if (proc.XObjectLevel == 0)
                {
                    ((PdfContentStreamEditor)processor).Write(processor, oper, operands);
                }
            }
        protected override void Write(PdfContentStreamProcessor processor, PdfLiteral oper, List <PdfObject> operands)
        {
            var operatorString = oper.ToString();

            if ("Tj".Equals(operatorString) || "TJ".Equals(operatorString))
            {
                for (var i = 0; i < operands.Count; i++)
                {
                    if (!operands[i].IsString())
                    {
                        continue;
                    }

                    var text = operands[i].ToString();
                    if (Regex.IsMatch(text, _matchPattern))
                    {
                        operands[i] = new PdfString(Regex.Replace(text, _matchPattern, _replacePattern));
                    }
                }
            }

            base.Write(processor, oper, operands);
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        private void RunBtn_Click(object sender, EventArgs e) //Paso uno, resibe PDF => StringBuilder
        {
            if (TxtUrl.Text == "")                            //En caso que no se ha seleccionado nada
            {
                MessageBox.Show("Please upload a PDF file first !!");
            }
            else
            {
                progressBar1.Visible = true;
                this.timer1.Start();


                PdfReader     reader  = new PdfReader(TxtUrl.Text.ToString()); //Lee la ubicacion del archivo
                StringBuilder builder = new StringBuilder();                   //El documento se guarada como string builder

                for (int x = 1; x <= reader.NumberOfPages; x++)
                {
                    //PdfDictionary page = reader.GetPageN(x);
                    IRenderListener           listener     = new SBTextRenderer(builder);
                    PdfContentStreamProcessor processor    = new PdfContentStreamProcessor(listener);
                    PdfDictionary             pageDic      = reader.GetPageN(x);
                    PdfDictionary             resourcesDic = pageDic.GetAsDict(PdfName.RESOURCES);
                    processor.ProcessContent(ContentByteUtils.GetContentBytesForPage(reader, x), resourcesDic);

                    if (listPages.Count != 0)
                    {
                        listPages.Add(builder.ToString().Replace(listPages[x - 2].ToString(), ""));
                    }
                    else
                    {
                        listPages.Add(builder.ToString());
                    }


                    if (x == reader.NumberOfPages)
                    {
                        foreach (string pagina in listPages)
                        {
                            for (int p = 0; p < pagina.Length; p++)
                            {
                                if (pagina[p].ToString() == "e" && pagina[p + 1].ToString() == "s" && pagina[p + 2].ToString() == " " && pagina[p + 3].ToString() == "D" && pagina[p + 4].ToString() == "a")
                                {
                                    int index = p + 7;

                                    listHeaders.Add(pagina.Substring(0, index));
                                    break;
                                }
                            }
                        }
                    }
                }//Find de for de conversion de PDF a string

                StringBuilder comenzar = new StringBuilder();
                int           Inicio   = 0;//Guardara la ubicacion dentro del PDF donde se puede comenzar a copiar caracteres
                int           final    = 0;

                for (int i = 0; i < builder.ToString().Length; i++)
                {
                    //ATP es la palabra donde comenzara a guardar caracteres
                    char uno  = 'A';
                    char dos  = 'T';
                    char tres = 'P';

                    encabezado = encabezado + builder.ToString()[i];//Esta variable guarda el encabezado para eliminarlo en las proximas paginas



                    if (builder.ToString()[i] == uno && builder.ToString()[i + 1] == dos && builder.ToString()[i + 2] == tres && banderaInicio == false || builder.ToString()[i] == 'B' && builder.ToString()[i + 1] == 'a' && builder.ToString()[i + 2] == 's' && builder.ToString()[i + 3] == 'e' && builder.ToString()[i + 4] == ':' && banderaInicio == false)
                    {
                        Inicio = i + 2; //Detecta donde inicia a guardar, le suma dos porque son los caracteres de TP de ATP
                                        //  break;//Como se ha encontrado donde comenzar a copiar , se rompe el ciclo
                        banderaInicio = true;
                        //Aqui detecta el nombre del aeropuerto
                        for (int r = i; r < builder.ToString().Length; r++)
                        {
                            string testErase = builder.ToString()[r].ToString();

                            if (builder.ToString()[r] == ':')
                            {
                                inicioAirport = r + 1;
                            }
                            else if (Regex.IsMatch(builder.ToString()[r].ToString(), @"^\d+$"))
                            {
                                finalAirport = r;
                            }
                            if (inicioAirport != 0 && finalAirport != 0 && airport == "")
                            {
                                airport = builder.ToString().Substring(inicioAirport, (finalAirport - inicioAirport));
                                break;
                            }
                        }
                    }


                    if (i == 2900)
                    {
                        int y = 0;
                    }

                    else if (builder.ToString()[i] == 'U' && builder.ToString()[i + 1] == 'C' && builder.ToString()[i + 2] == 'T' && builder.ToString()[i + 3] == ' ' && builder.ToString()[i + 4] == '2' && builder.ToString()[i + 5] == '2' && builder.ToString()[i + 6] == '1')
                    {
                        final = i;
                        break;
                    }
                    else if (builder.ToString()[i] == 'T' && builder.ToString()[i + 1] == 'T' && builder.ToString()[i + 2] == 'O' && builder.ToString()[i + 3] == ' ' && builder.ToString()[i + 4] == '2' && builder.ToString()[i + 5] == '2' && builder.ToString()[i + 6] == '1')
                    {
                        final = i;
                        break;
                    }
                }//Find de for de deteccion de inicio para copiar

                bool bandera = false;
                // for (int i = Inicio; i < builder.ToString().Length; i++)
                for (int i = Inicio; i < final; i++)
                {
                    if (bandera == false)                                   //Verifica si comienza con cero y con ello lograr comenzar a guardar
                    {
                        string auxiliar = builder.ToString()[i].ToString(); //Se puede borrar, solo se usa de prueba
                        if (builder.ToString()[i].ToString() == "0" || Regex.IsMatch(builder.ToString()[i].ToString(), @"^\d+$"))
                        {
                            bandera = true;
                        }
                    }

                    if (bandera == true)//Como se verifico que si comienza en cero comienza a guardarse
                    {
                        char a = 'T';
                        char b = 'O';
                        char c = 'T';
                        char d = 'A';

                        string auxiliar2 = builder.ToString()[i].ToString();//Solo de prueba, se puede eliminar

                        if (builder.ToString()[i] == a && builder.ToString()[i + 1] == b && builder.ToString()[i + 2] == c && builder.ToString()[i + 3] == d)
                        {
                            int aux = i + 18;//Detecta donde inicia a guardar, le suma dos porque son los caracteres de TP de ATP

                            for (int y = aux; y < builder.ToString().Length; y++)
                            {
                                string auxiliar3 = builder.ToString()[y].ToString();//Se puede borrar, es solo de prueba

                                if (builder.ToString()[y] == 'U' && builder.ToString()[y + 1] == 'S' && builder.ToString()[y + 2] == 'G')
                                {
                                    i = y + 2;
                                    break;
                                }
                            }
                        }
                        else if (builder.ToString()[i] == 'A' && builder.ToString()[i + 1] == 'i' && builder.ToString()[i + 2] == 'r' && builder.ToString()[i + 3] == 'p' && builder.ToString()[i + 4] == 'o' && builder.ToString()[i + 5] == 'r' && builder.ToString()[i + 6] == 't')
                        {
                            break;
                        }
                        else
                        {
                            string cadena = builder.ToString()[i].ToString();
                            comenzar.Append(cadena);
                        }
                    }
                }
                encabezado = encabezado.Replace("DateA", "Date");
                //textBox1.Text = encabezado;
                //textBox2.Text = comenzar.ToString().Replace(encabezado, "");
                string nuevo = comenzar.ToString().Replace(encabezado, "");
                LlenarGrid(nuevo.ToString());
            }
        }
Ejemplo n.º 5
0
        //static const Regex.Replace(s, @"\t|\n|\r", "");
        static void Main(string[] args)
        {
            string fileName = @"D:\mobi.pdf";

            //Open PDF document
            using (PdfReader reader = new PdfReader(fileName))
            {
                var sb = new TextRenderEx();
                //var parser = new PdfReaderContentParser(reader);
                for (int page = 1; page <= reader.NumberOfPages; page++)
                {
                    var size = reader.GetCropBox(page);
                    Console.WriteLine(size.Width);
                    Console.WriteLine(size.Height);

                    PdfDictionary             pdfDictionary = reader.GetPageN(page);
                    IRenderListener           listener      = new SBTextRenderer(sb);
                    PdfContentStreamProcessor processor     = new PdfContentStreamProcessor(listener);
                    PdfDictionary             pageDic       = reader.GetPageN(page);
                    PdfDictionary             resourcesDic  = pageDic.GetAsDict(PdfName.RESOURCES);
                    processor.ProcessContent(ContentByteUtils.GetContentBytesForPage(reader, page), resourcesDic);

                    //Create an instance of our strategy
                    //var t2 = new MyLocationTextExtractionStrategy(searchText, System.Globalization.CompareOptions.IgnoreCase);
                    //var ex = PdfTextExtractor.GetTextFromPage(reader, page, t2);
                    ////Loop through each chunk found
                    //foreach (var p in t2.myPoints)
                    //{
                    //    Console.WriteLine(string.Format("Found text {0} at {1}x{2}", p.Text, p.Rect.Left, p.Rect.Bottom));
                    //}
                    //var strategy = parser.ProcessContent(i, new LocationTextExtractionStrategyEx());

                    //var res = strategy.GetLocations();
                    var    its    = new LocationTextExtractionStrategyEx2();
                    String s      = PdfTextExtractor.GetTextFromPage(reader, page, its);
                    var    result = new StringBuilder();

                    foreach (var t in its.Columbs.Values)
                    {
                        string rs = t.ToString();
                        Console.WriteLine(rs);
                    }

                    string str = result.ToString();
                    //Console.Write(str);
                    //if (!string.IsNullOrWhiteSpace(str) && (str.IndexOf(SearchText) != -1)||searchText.IndexOf(str) != -1) {
                    //    Console.Write(str);
                    //}

                    //Console.WriteLine(pageResult.ToString());

                    // System.Diagnostics.Debug.WriteLine(s);
                    //var its2 = new LocationTextExtractionStrategyEx(searchText, page);
                    //String ss = PdfTextExtractor.GetTextFromPage(reader, page, its2);
                    //for (int i1 = 0; i1 < its2.m_SearchResultsList.Count; i1++)
                    //{
                    //    SearchResult t = its2.m_SearchResultsList[i1];
                    //    Console.WriteLine(string.Format("text:{2}; x:{0},y:{1}", t.iPosX, t.iPosY, t.Text));
                    //    Console.WriteLine(string.Format("topleft: x:{0},y:{1}", t.TopLeft[Vector.I1], t.TopLeft[Vector.I2]));
                    //}
                    var bbb  = sb.sb.ToString();
                    var asdf = "";
                }
            }
        }
Ejemplo n.º 6
0
 public void HandleXObject(PdfContentStreamProcessor processor, PdfStream xobjectStream, PdfIndirectReference refi) {
     // ignore XObject subtype
 }
Ejemplo n.º 7
0
            public void HandleXObject(PdfContentStreamProcessor processor, PdfStream stream, PdfIndirectReference refi) {
                
                PdfDictionary resources = stream.GetAsDict(PdfName.RESOURCES);

                // we read the content bytes up here so if it fails we don't leave the graphics state stack corrupted
                // this is probably not necessary (if we fail on this, probably the entire content stream processing
                // operation should be rejected
                byte[] contentBytes;
                contentBytes = ContentByteUtils.GetContentBytesFromContentObject(stream);
                PdfArray matrix = stream.GetAsArray(PdfName.MATRIX);

                new PushGraphicsState().Invoke(processor, null, null);

                if (matrix != null){
                    float a = matrix.GetAsNumber(0).FloatValue;
                    float b = matrix.GetAsNumber(1).FloatValue;
                    float c = matrix.GetAsNumber(2).FloatValue;
                    float d = matrix.GetAsNumber(3).FloatValue;
                    float e = matrix.GetAsNumber(4).FloatValue;
                    float f = matrix.GetAsNumber(5).FloatValue;
                    Matrix formMatrix = new Matrix(a, b, c, d, e, f);

                    processor.Gs().ctm = formMatrix.Multiply(processor.Gs().ctm);
                }

                processor.ProcessContent(contentBytes, resources);

                new PopGraphicsState().Invoke(processor, null, null);
                
            }
Ejemplo n.º 8
0
 public void Invoke(PdfContentStreamProcessor processor,
         PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
         {
     processor.EndMarkedContent();
 }
Ejemplo n.º 9
0
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
            {
                PdfArray array = (PdfArray)operands[0];
                float tj = 0;
                foreach (iTextSharp.text.pdf.PdfObject entryObj in array.ArrayList)
                {
                    if (entryObj is PdfString){
                        processor.DisplayPdfString((PdfString)entryObj);
                        tj = 0;
                    } else {
                        tj = ((PdfNumber)entryObj).FloatValue;
                        processor.ApplyTextAdjust(tj);
                    }
                }

            }
Ejemplo n.º 10
0
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
            {
                float tx = ((PdfNumber)operands[0]).FloatValue;
                float ty = ((PdfNumber)operands[1]).FloatValue;

                Matrix translationMatrix = new Matrix(tx, ty);
                processor.textMatrix =  translationMatrix.Multiply(processor.textLineMatrix);
                processor.textLineMatrix = processor.textMatrix;
            }
Ejemplo n.º 11
0
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
            {
                float ty = ((PdfNumber)operands[1]).FloatValue;

                List<iTextSharp.text.pdf.PdfObject> tlOperands = new List<iTextSharp.text.pdf.PdfObject>(1);
                tlOperands.Insert(0, new PdfNumber(-ty));
                setTextLeading.Invoke(processor, null, tlOperands);
                moveStartNextLine.Invoke(processor, null, operands);
            }
Ejemplo n.º 12
0
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
            {
                float a = ((PdfNumber)operands[0]).FloatValue;
                float b = ((PdfNumber)operands[1]).FloatValue;
                float c = ((PdfNumber)operands[2]).FloatValue;
                float d = ((PdfNumber)operands[3]).FloatValue;
                float e = ((PdfNumber)operands[4]).FloatValue;
                float f = ((PdfNumber)operands[5]).FloatValue;

                processor.textLineMatrix = new Matrix(a, b, c, d, e, f);
                processor.textMatrix = processor.textLineMatrix;
            }
Ejemplo n.º 13
0
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
 {
     List<iTextSharp.text.pdf.PdfObject> tdoperands = new List<iTextSharp.text.pdf.PdfObject>(2);
     tdoperands.Insert(0, new PdfNumber(0));
     tdoperands.Insert(1, new PdfNumber(-processor.Gs().leading));
     moveStartNextLine.Invoke(processor, null, tdoperands);
 }
Ejemplo n.º 14
0
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
            {
                PdfString str = (PdfString)operands[0];

                processor.DisplayPdfString(str);
            }
Ejemplo n.º 15
0
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
 {
     textMoveNextLine.Invoke(processor, null, new List<iTextSharp.text.pdf.PdfObject>(0));
     showText.Invoke(processor, null, operands);
 }
Ejemplo n.º 16
0
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
            {
                PdfNumber aw = (PdfNumber)operands[0];
                PdfNumber ac = (PdfNumber)operands[1];
                PdfString str = (PdfString)operands[2];

                List<iTextSharp.text.pdf.PdfObject> twOperands = new List<iTextSharp.text.pdf.PdfObject>(1);
                twOperands.Insert(0, aw);
                setTextWordSpacing.Invoke(processor, null, twOperands);

                List<iTextSharp.text.pdf.PdfObject> tcOperands = new List<iTextSharp.text.pdf.PdfObject>(1);
                tcOperands.Insert(0, ac);
                setTextCharacterSpacing.Invoke(processor, null, tcOperands);

                List<iTextSharp.text.pdf.PdfObject> tickOperands = new List<iTextSharp.text.pdf.PdfObject>(1);
                tickOperands.Insert(0, str);
                moveNextLineAndShowText.Invoke(processor, null, tickOperands);
            }
Ejemplo n.º 17
0
 public void HandleXObject(PdfContentStreamProcessor processor, PdfStream stream, PdfIndirectReference refi)
 {
     OriginalHandler.HandleXObject(processor, stream, refi);
 }
Ejemplo n.º 18
0
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
            {
                PdfName fontResourceName = (PdfName)operands[0];
                float size = ((PdfNumber)operands[1]).FloatValue;

                PdfDictionary fontsDictionary = processor.resources.GetAsDict(PdfName.FONT);
                CMapAwareDocumentFont font;
                iTextSharp.text.pdf.PdfObject fontObject = fontsDictionary.Get(fontResourceName);
                if (fontObject is PdfDictionary)
                    font = processor.GetFont((PdfDictionary)fontObject);
                else
                    font = processor.GetFont((PRIndirectReference)fontObject);

                processor.Gs().font = font;
                processor.Gs().fontSize = size;

            }
Ejemplo n.º 19
0
            public void Invoke(PdfContentStreamProcessor processor,
                    PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
                    {

                        iTextSharp.text.pdf.PdfObject properties = operands[1];
                
                processor.BeginMarkedContent((PdfName)operands[0], GetPropertiesDictionary(properties, processor.resources));
            }
Ejemplo n.º 20
0
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
 {
     PdfNumber render = (PdfNumber)operands[0];
     processor.Gs().renderMode = render.IntValue;
 }
Ejemplo n.º 21
0
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
 {
     PdfName xobjectName = (PdfName)operands[0];
     processor.DisplayXObject(xobjectName);
 }
Ejemplo n.º 22
0
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
 {
     PdfNumber scale = (PdfNumber)operands[0];
     processor.Gs().horizontalScaling = scale.FloatValue/100f;
 }
Ejemplo n.º 23
0
 public void HandleXObject(PdfContentStreamProcessor processor, PdfStream xobjectStream, PdfIndirectReference refi) {
     PdfDictionary colorSpaceDic = processor.resources.GetAsDict(PdfName.COLORSPACE);
     ImageRenderInfo renderInfo = ImageRenderInfo.CreateForXObject(processor.Gs().ctm, refi, colorSpaceDic);
     processor.renderListener.RenderImage(renderInfo);
 }
Ejemplo n.º 24
0
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
 {
     PdfNumber wordSpace = (PdfNumber)operands[0];
     processor.Gs().wordSpacing = wordSpace.FloatValue;
 }
Ejemplo n.º 25
0
 protected override void Write(PdfContentStreamProcessor processor, PdfLiteral oper, List <PdfObject> operands)
 {
     base.Write(processor, oper, operands);
 }
Ejemplo n.º 26
0
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
            {

                PdfName dictionaryName = (PdfName)operands[0];
                PdfDictionary extGState = processor.resources.GetAsDict(PdfName.EXTGSTATE);
                if (extGState == null)
                    throw new ArgumentException(MessageLocalization.GetComposedMessage("resources.do.not.contain.extgstate.entry.unable.to.process.oper.1", oper));
                PdfDictionary gsDic = extGState.GetAsDict(dictionaryName);
                if (gsDic == null)
                    throw new ArgumentException(MessageLocalization.GetComposedMessage("1.is.an.unknown.graphics.state.dictionary", dictionaryName));

                // at this point, all we care about is the FONT entry in the GS dictionary
                PdfArray fontParameter = gsDic.GetAsArray(PdfName.FONT);
                if (fontParameter != null){
                    CMapAwareDocumentFont font = processor.GetFont((PRIndirectReference)fontParameter[0]);
                    float size = fontParameter.GetAsNumber(1).FloatValue;

                    processor.Gs().font = font;
                    processor.Gs().fontSize = size;
                }
            }
Ejemplo n.º 27
0
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List <PdfObject> operands)
 {
 }
Ejemplo n.º 28
0
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
 {
     GraphicsState gs = processor.gsStack.Peek();
     GraphicsState copy = new GraphicsState(gs);
     processor.gsStack.Push(copy);
 }
Ejemplo n.º 29
0
        public void Invoke(PdfContentStreamProcessor pdfContentStreamProcessor, PdfLiteral @operator, List <PdfObject> operands)
        {
            String         operatorStr = @operator.ToString();
            PdfContentByte canvas      = cleanUpStrategy.Context.Canvas;
            PRStream       xFormStream = null;

            // key - number of a string in the TJ operator, value - number following the string; the first number without string (if it's presented) is stored under 0.
            // BE AWARE: zero-length strings are ignored!!!
            IDictionary <int, float> structuredTJoperands = null;

            if ("Do" == operatorStr)
            {
                if (operands.Count == 2 && operands[0].IsName())
                {
                    PdfDictionary xObjResources = cleanUpStrategy.Context.Resources.GetAsDict(PdfName.XOBJECT);

                    if (xObjResources != null)
                    {
                        PdfStream xObj = xObjResources.GetAsStream((PdfName)operands[0]);

                        if (xObj is PRStream && xObj.GetAsName(PdfName.SUBTYPE) != null &&
                            xObj.GetAsName(PdfName.SUBTYPE).CompareTo(PdfName.FORM) == 0)
                        {
                            xFormStream = (PRStream)xObj;
                            cleanUpStrategy.RegisterNewContext(xObj.GetAsDict(PdfName.RESOURCES), null);
                        }
                    }
                }
            }

            originalContentOperator.Invoke(pdfContentStreamProcessor, @operator, operands);
            IList <PdfCleanUpContentChunk> chunks = cleanUpStrategy.Chunks;
            bool disableOutput = false;

            if (xFormStream != null)
            {
                xFormStream.SetData(cleanUpStrategy.Context.Canvas.ToPdf(cleanUpStrategy.Context.Canvas.PdfWriter));
                cleanUpStrategy.PopContext();
                canvas = cleanUpStrategy.Context.Canvas;
            }

            if ("Do" == operatorStr)
            {
                if (chunks.Count > 0 && chunks[0].IsImage())
                {
                    PdfCleanUpContentChunk chunk = chunks[0];

                    if (chunk.IsVisible())
                    {
                        PdfDictionary xObjResources = cleanUpStrategy.Context.Resources.GetAsDict(PdfName.XOBJECT);
                        PRStream      imageStream   = (PRStream)xObjResources.GetAsStream((PdfName)operands[0]);
                        UpdateImage(imageStream, chunk.NewImageData);
                    }
                    else
                    {
                        disableOutput = true;
                    }
                }
            }
            else if ("q" == operatorStr)
            {
                cleanUpStrategy.Context.SaveGraphicsState();
            }
            else if ("Q" == operatorStr)
            {
                cleanUpStrategy.Context.RestoreGraphicsState();
            }
            else if ("Tf" == operatorStr)
            {
                cleanUpStrategy.Context.FontSize = ((PdfNumber)operands[1]).FloatValue;
            }
            else if ("Tc" == operatorStr)
            {
                cleanUpStrategy.Context.CharacterSpacing = ((PdfNumber)operands[0]).FloatValue;
            }
            else if ("Tw" == operatorStr)
            {
                cleanUpStrategy.Context.WordSpacing = ((PdfNumber)operands[0]).FloatValue;
            }
            else if ("Tz" == operatorStr)
            {
                cleanUpStrategy.Context.HorizontalScaling = ((PdfNumber)operands[0]).FloatValue;
            }
            else if (textShowingOperators.Contains(operatorStr) && !AllChunksAreVisible(cleanUpStrategy.Chunks))
            {
                disableOutput = true;

                if ("'" == operatorStr)
                {
                    canvas.InternalBuffer.Append(TStar);
                }
                else if ("\"" == operatorStr)
                {
                    operands[0].ToPdf(canvas.PdfWriter, canvas.InternalBuffer);
                    canvas.InternalBuffer.Append(Tw);

                    operands[1].ToPdf(canvas.PdfWriter, canvas.InternalBuffer);
                    canvas.InternalBuffer.Append(TcTStar);

                    cleanUpStrategy.Context.CharacterSpacing = ((PdfNumber)operands[1]).FloatValue;
                }
                else if ("TJ" == operatorStr)
                {
                    structuredTJoperands = StructureTJarray((PdfArray)operands[0]);
                }

                RenderChunks(structuredTJoperands, chunks, canvas);
            }
            else if ("\"" == operatorStr)
            {
                cleanUpStrategy.Context.CharacterSpacing = ((PdfNumber)operands[1]).FloatValue;
            }

            if (!disableOutput)
            {
                int index = 0;

                foreach (PdfObject o in operands)
                {
                    ToPdf(o, canvas.PdfWriter, canvas.InternalBuffer);
                    canvas.InternalBuffer.Append(operands.Count > ++index ? (byte)' ' : (byte)'\n');
                }
            }

            cleanUpStrategy.ClearChunks();
        }
Ejemplo n.º 30
0
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
 {
     float a = ((PdfNumber)operands[0]).FloatValue;
     float b = ((PdfNumber)operands[1]).FloatValue;
     float c = ((PdfNumber)operands[2]).FloatValue;
     float d = ((PdfNumber)operands[3]).FloatValue;
     float e = ((PdfNumber)operands[4]).FloatValue;
     float f = ((PdfNumber)operands[5]).FloatValue;
     Matrix matrix = new Matrix(a, b, c, d, e, f);
     GraphicsState gs = processor.gsStack.Peek();
     gs.ctm = matrix.Multiply(gs.ctm);
 }
Ejemplo n.º 31
0
        public virtual void Invoke(PdfContentStreamProcessor pdfContentStreamProcessor, PdfLiteral oper, List <PdfObject> operands)
        {
            String         operatorStr   = oper.ToString();
            PdfContentByte canvas        = cleanUpStrategy.Context.Canvas;
            PRStream       xFormStream   = null;
            bool           disableOutput = pathConstructionOperators.Contains(operatorStr) || pathPaintingOperators.Contains(operatorStr) || clippingPathOperators.Contains(operatorStr);
            GraphicsState  gs            = pdfContentStreamProcessor.Gs();

            // key - number of a string in the TJ operator, value - number following the string; the first number without string (if it's presented) is stored under 0.
            // BE AWARE: zero-length strings are ignored!!!
            IDictionary <int, float> structuredTJoperands = null;

            if ("Do" == operatorStr)
            {
                if (operands.Count == 2 && operands[0].IsName())
                {
                    PdfDictionary xObjResources = cleanUpStrategy.Context.Resources.GetAsDict(PdfName.XOBJECT);

                    if (xObjResources != null)
                    {
                        PdfStream xObj = xObjResources.GetAsStream((PdfName)operands[0]);

                        if (xObj is PRStream && xObj.GetAsName(PdfName.SUBTYPE) != null &&
                            xObj.GetAsName(PdfName.SUBTYPE).CompareTo(PdfName.FORM) == 0)
                        {
                            xFormStream = (PRStream)xObj;
                            cleanUpStrategy.RegisterNewContext(xObj.GetAsDict(PdfName.RESOURCES), null);
                        }
                    }
                }
            }

            originalContentOperator.Invoke(pdfContentStreamProcessor, oper, operands);
            IList <PdfCleanUpContentChunk> chunks = cleanUpStrategy.Chunks;

            if (xFormStream != null)
            {
                xFormStream.SetData(cleanUpStrategy.Context.Canvas.ToPdf(cleanUpStrategy.Context.Canvas.PdfWriter));
                cleanUpStrategy.PopContext();
                canvas = cleanUpStrategy.Context.Canvas;
            }

            if ("Do" == operatorStr)
            {
                if (chunks.Count > 0 && chunks[0] is PdfCleanUpContentChunk.Image)
                {
                    PdfCleanUpContentChunk.Image chunk = (PdfCleanUpContentChunk.Image)chunks[0];

                    if (chunk.Visible)
                    {
                        PdfDictionary xObjResources = cleanUpStrategy.Context.Resources.GetAsDict(PdfName.XOBJECT);
                        PRStream      imageStream   = (PRStream)xObjResources.GetAsStream((PdfName)operands[0]);
                        UpdateImageStream(imageStream, chunk.NewImageData);
                    }
                    else
                    {
                        disableOutput = true;
                    }
                }
            }
            else if (lineStyleOperators.Contains(operatorStr))
            {
                disableOutput = true;
            }
            else if (textShowingOperators.Contains(operatorStr) && !AllChunksAreVisible(cleanUpStrategy.Chunks))
            {
                disableOutput = true;

                if ("'" == operatorStr)
                {
                    canvas.InternalBuffer.Append(TStar);
                }
                else if ("\"" == operatorStr)
                {
                    operands[0].ToPdf(canvas.PdfWriter, canvas.InternalBuffer);
                    canvas.InternalBuffer.Append(Tw);

                    operands[1].ToPdf(canvas.PdfWriter, canvas.InternalBuffer);
                    canvas.InternalBuffer.Append(TcTStar);
                }
                else if ("TJ" == operatorStr)
                {
                    structuredTJoperands = StructureTJarray((PdfArray)operands[0]);
                }

                WriteTextChunks(structuredTJoperands, chunks, canvas, gs.CharacterSpacing, gs.WordSpacing,
                                gs.FontSize, gs.HorizontalScaling);
            }
            else if (pathPaintingOperators.Contains(operatorStr))
            {
                WritePath(operatorStr, canvas, gs.ColorSpaceStroke);
            }
            else if (strokeColorOperators.Contains(operatorStr))
            {
                // Replace current color with the new one.
                cleanUpStrategy.Context.PopStrokeColor();
                cleanUpStrategy.Context.PushStrokeColor(operands);
            }
            else if ("q" == operatorStr)
            {
                cleanUpStrategy.Context.PushStrokeColor(cleanUpStrategy.Context.PeekStrokeColor());
            }
            else if ("Q" == operatorStr)
            {
                cleanUpStrategy.Context.PopStrokeColor();
            }

            if (!disableOutput)
            {
                WriteOperands(canvas, operands);
            }

            cleanUpStrategy.ClearChunks();
        }
Ejemplo n.º 32
0
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
 {
     processor.gsStack.Pop();
 }
Ejemplo n.º 33
0
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
 {
     processor.textMatrix = null;
     processor.textLineMatrix = null;
     processor.EndText();
 }
Ejemplo n.º 34
0
 public void Invoke(PdfContentStreamProcessor processor,
         PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
         {
     processor.BeginMarkedContent((PdfName)operands[0], new PdfDictionary());
 }
Ejemplo n.º 35
0
 public void HandleXObject(PdfContentStreamProcessor processor, PdfStream stream, PdfIndirectReference refi, ICollection markedContentInfoStack)
 {
     OriginalHandler.HandleXObject(processor, stream, refi, markedContentInfoStack);
 }
Ejemplo n.º 36
0
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<iTextSharp.text.pdf.PdfObject> operands)
 {
     // ignore the oper
 }