Extract paths and shapes with iTextSharp

前端 未结 2 1419
我寻月下人不归
我寻月下人不归 2021-01-15 16:13

iTextSharp supports creation of shapes and paths with PdfContentByte class, there you can set colors and paint curves and basic elements ... is there a mechanis

2条回答
  •  抹茶落季
    2021-01-15 16:52

    Here is the starting point of extracting the different commands of a page:

        var file = "test.pdf";
        var reader = new PdfReader(file);
    
        var streamBytes = reader.GetPageContent(2);
        var tokenizer = new PRTokeniser(new RandomAccessFileOrArray(streamBytes));
        var ps = new PdfContentParser(tokenizer);
    
        List operands = new List();
        while (ps.Parse(operands).Count > 0)
        {
            PdfLiteral oper = (PdfLiteral)operands[operands.Count - 1];
            var cmd = oper.ToString();
    
            switch (cmd)
            {
                case "q":
                    Console.WriteLine("SaveGraphicsState(); //q");
                    break;
    
                case "Q":
                    Console.WriteLine("RestoreGraphicsState(); //Q");
                    break;
    
               // good luck with the rest!
    
            }
        }
    

提交回复
热议问题