当前位置: 首页>>代码示例>>C#>>正文


C# pdf.PRTokeniser类代码示例

本文整理汇总了C#中iTextSharp.text.pdf.PRTokeniser的典型用法代码示例。如果您正苦于以下问题:C# PRTokeniser类的具体用法?C# PRTokeniser怎么用?C# PRTokeniser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PRTokeniser类属于iTextSharp.text.pdf命名空间,在下文中一共展示了PRTokeniser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseDAParam

        IDictionary<string, IList<object>> ParseDAParam(PdfString DA) {
            IDictionary<string, IList<object>> commandArguments = new Dictionary<string, IList<object>>();

            PRTokeniser tokeniser = new PRTokeniser(new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateSource(DA.GetBytes())));
            IList<object> currentArguments = new List<object>();

            while (tokeniser.NextToken()) {
                if (tokeniser.TokenType == PRTokeniser.TokType.OTHER) {
                    String key = tokeniser.StringValue;

                    if (key == "RG" || key == "G" || key == "K") {
                        key = STROKE_COLOR;
                    } else if (key == "rg" || key == "g" || key == "k") {
                        key = FILL_COLOR;
                    }

                    if (commandArguments.ContainsKey(key)) {
                        commandArguments[key] = currentArguments;
                    } else {
                        commandArguments.Add(key, currentArguments);
                    }

                    currentArguments = new List<object>();
                } else {
                    switch (tokeniser.TokenType) {
                        case PRTokeniser.TokType.NUMBER:
                            currentArguments.Add(new PdfNumber(tokeniser.StringValue));
                            break;

                        case PRTokeniser.TokType.NAME:
                            currentArguments.Add(new PdfName(tokeniser.StringValue));
                            break;

                        default:
                            currentArguments.Add(tokeniser.StringValue);
                            break;
                    }
                }
            }

            return commandArguments;
        }
开发者ID:yu0410aries,项目名称:itextsharp,代码行数:42,代码来源:PdfCleanUpProcessor.cs

示例2: CheckNumberValue

        private void CheckNumberValue(String data, String expectedValue) {
            PRTokeniser tok = new PRTokeniser(new RandomAccessFileOrArray(GetBytes(data)));

            tok.NextValidToken();
            Assert.AreEqual(PRTokeniser.TokType.NUMBER, tok.TokenType, "Wrong type");
            Assert.AreEqual(expectedValue, tok.StringValue, "Wrong multiple minus signs number handling");
        }
开发者ID:newlysoft,项目名称:itextsharp,代码行数:7,代码来源:PRTokeniserTest.cs

示例3: CustomPdfReader

 /// <summary>
 /// CustomPdfReader to be able to work with streams.
 /// </summary>
 public CustomPdfReader(Stream isp, X509Certificate certificate, ICipherParameters certificateKey)
 {
     this.certificate = certificate;
     this.certificateKey = certificateKey;
     tokens = new PRTokeniser(new RandomAccessFileOrArray(isp));
     ReadPdf();
 }
开发者ID:VahidN,项目名称:PdfReport,代码行数:10,代码来源:SignatureWriter.cs

示例4: CheckTokenTypes

        private void CheckTokenTypes(String data, params PRTokeniser.TokType[] expectedTypes)
        {
            PRTokeniser tok = new PRTokeniser(new RandomAccessFileOrArray(GetBytes(data)));

            for (int i = 0; i < expectedTypes.Length; i++)
            {
                tok.NextValidToken();
                //System.out.println(tok.getTokenType() + " -> " + tok.getStringValue());
                Assert.AreEqual(expectedTypes[i], tok.TokenType, "Position " + i);
            }
        }
开发者ID:,项目名称:,代码行数:11,代码来源:

示例5: PdfReader

 /** Reads and parses a PDF document.
 * @param url the Uri of the document
 * @param ownerPassword the password to read the document
 * @throws IOException on error
 */
 public PdfReader(Uri url, byte[] ownerPassword) {
     password = ownerPassword;
     tokens = new PRTokeniser(new RandomAccessFileOrArray(url));
     ReadPdf();
 }
开发者ID:,项目名称:,代码行数:10,代码来源:

示例6: ProcessContent

        /**
         * Processes PDF syntax.
         * <b>Note:</b> If you re-use a given {@link PdfContentStreamProcessor}, you must call {@link PdfContentStreamProcessor#reset()}
         * @param contentBytes  the bytes of a content stream
         * @param resources     the resources that come with the content stream
         */
        public void ProcessContent(byte[] contentBytes, PdfDictionary resources){
            this.resources.Push(resources);
            PRTokeniser tokeniser = new PRTokeniser(contentBytes);
            PdfContentParser ps = new PdfContentParser(tokeniser);
            List<iTextSharp.text.pdf.PdfObject> operands = new List<iTextSharp.text.pdf.PdfObject>();
            while (ps.Parse(operands).Count > 0){
                PdfLiteral oper = (PdfLiteral)operands[operands.Count-1];

                // w.GetOperatorInfo(oper)
                //w.wr.Print("operator info {0} type {1} string {2}", oper.GetType().ToString(), oper.Type, oper.ToString());

                if ("BI".Equals(oper.ToString())){
                    // we don't call invokeOperator for embedded images - this is one area of the PDF spec that is particularly nasty and inconsistent
                    PdfDictionary colorSpaceDic = resources != null ? resources.GetAsDict(PdfName.COLORSPACE) : null;
                    // 'iTextSharp.text.pdf.parser.ImageRenderInfo.CreateForEmbeddedImage(iTextSharp.text.pdf.parser.Matrix, iTextSharp.text.pdf.parser.InlineImageInfo, iTextSharp.text.pdf.PdfDictionary)' is inaccessible due to its protection level
                    ImageRenderInfo renderInfo = ImageRenderInfo.CreateForEmbeddedImage(Gs().ctm, InlineImageUtils.ParseInlineImage(ps, colorSpaceDic), colorSpaceDic);
                    renderListener.RenderImage(renderInfo);
                } else {
                    InvokeOperator(oper, operands);
                }
            }
            this.resources.Pop();
        }
开发者ID:labeuze,项目名称:source,代码行数:29,代码来源:PdfContentStreamProcessor.cs

示例7: PdfContentParser

 /**
 * Creates a new instance of PdfContentParser
 * @param tokeniser the tokeniser with the content
 */
 public PdfContentParser(PRTokeniser tokeniser)
 {
     this.tokeniser = tokeniser;
 }
开发者ID:jomamorales,项目名称:createPDF,代码行数:8,代码来源:PdfContentParser.cs

示例8: OpenPdf

        private void OpenPdf()
        {
            _pdfPages.Clear();
            try
            {
                var openFileDialog = new OpenFileDialog
                                         {
                                             DefaultExt = ".pdf",
                                             Filter = "Pdf documents (.pdf)|*.pdf"
                                         };

                bool? result = openFileDialog.ShowDialog();

                if (result == true)
                {
                    string filename = openFileDialog.FileName;
                    var pdfReader = new PdfReader(filename);
                    for (int i = 1; i <= pdfReader.NumberOfPages; i++)
                    {
                        byte[] pagesBytes = pdfReader.GetPageContent(i);
                        var token = new PRTokeniser(pagesBytes);
                        var pageContent = new StringBuilder();
                        while (token.NextToken())
                        {
                            if (token.TokenType == PRTokeniser.TokType.STRING)
                            {
                                pageContent.Append(token.StringValue);
                            }
                        }
                        _pdfPages.Add(pageContent.ToString());
                    }
                }
                RaisePropertyChanged("MaxIndex");
            }
            catch (Exception)
            {
                MessageBox.Show("Fail to load file");
            }
            CurrentIndex = 1;
        }
开发者ID:tikrimi,项目名称:Tools,代码行数:40,代码来源:MainViewModel.cs

示例9: ReadOneObjStm

		virtual protected internal PdfObject ReadOneObjStm (PRStream stream, int idx) {
            int first = stream.GetAsNumber(PdfName.FIRST).IntValue;
            byte[] b = GetStreamBytes(stream, tokens.File);
            PRTokeniser saveTokens = tokens;
            tokens = new PRTokeniser(new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateSource(b)));
            try {
				int address = 0;
                bool ok = true;
                ++idx;
                for (int k = 0; k < idx; ++k) {
                    ok = tokens.NextToken();
                    if (!ok)
                        break;
                    if (tokens.TokenType != PRTokeniser.TokType.NUMBER) {
                        ok = false;
                        break;
                    }
                    ok = tokens.NextToken();
                    if (!ok)
                        break;
                    if (tokens.TokenType != PRTokeniser.TokType.NUMBER) {
                        ok = false;
                        break;
                    }
                    address = tokens.IntValue + first;
                }
                if (!ok)
                    throw new InvalidPdfException(MessageLocalization.GetComposedMessage("error.reading.objstm"));
                tokens.Seek(address);
                tokens.NextToken();
                PdfObject obj;
                if (tokens.TokenType == PRTokeniser.TokType.NUMBER) {
                    obj = new PdfNumber(tokens.StringValue);
                }
                else {
                    tokens.Seek(address);
                    obj = ReadPRObject();
                }
                return obj;
            }
            finally {
                tokens = saveTokens;
            }
        }
开发者ID:,项目名称:,代码行数:44,代码来源:

示例10: CheckObjectStart

		public static long[] CheckObjectStart (byte[] line) {
            try {
                PRTokeniser tk = new PRTokeniser(new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateSource(line)));
                int num = 0;
                int gen = 0;
                if (!tk.NextToken() || tk.TokenType != TokType.NUMBER)
                    return null;
                num = tk.IntValue;
                if (!tk.NextToken() || tk.TokenType != TokType.NUMBER)
                    return null;
                gen = tk.IntValue;
                if (!tk.NextToken())
                    return null;
                if (!tk.StringValue.Equals("obj"))
                    return null;
                return new long[]{num, gen};
            }
            catch {
            }
            return null;
        }
开发者ID:htlp,项目名称:itextsharp,代码行数:21,代码来源:PRTokeniser.cs

示例11: ProcessContent

 /**
  * Processes PDF syntax.
  * <b>Note:</b> If you re-use a given {@link PdfContentStreamProcessor}, you must call {@link PdfContentStreamProcessor#reset()}
  * @param contentBytes  the bytes of a content stream
  * @param resources     the resources that come with the content stream
  */
 public void ProcessContent(byte[] contentBytes, PdfDictionary resources){
     this.resources.Push(resources);
     PRTokeniser tokeniser = new PRTokeniser(new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateSource(contentBytes)));
     PdfContentParser ps = new PdfContentParser(tokeniser);
     List<PdfObject> operands = new List<PdfObject>();
     while (ps.Parse(operands).Count > 0){
         PdfLiteral oper = (PdfLiteral)operands[operands.Count-1];
         if ("BI".Equals(oper.ToString())){
             // we don't call invokeOperator for embedded images - this is one area of the PDF spec that is particularly nasty and inconsistent
             PdfDictionary colorSpaceDic = resources != null ? resources.GetAsDict(PdfName.COLORSPACE) : null;
             ImageRenderInfo renderInfo = ImageRenderInfo.CreateForEmbeddedImage(Gs().ctm, InlineImageUtils.ParseInlineImage(ps, colorSpaceDic), colorSpaceDic);
             renderListener.RenderImage(renderInfo);
         } else {
             InvokeOperator(oper, operands);
         }
     }
     this.resources.Pop();
 }
开发者ID:,项目名称:,代码行数:24,代码来源:

示例12: Parse

 /// <summary>
 /// Parses a stream object and removes OCGs. </summary>
 /// <param name="stream">	a stream object </param>
 /// <param name="resources">	the resources dictionary of that object (containing info about the OCGs) </param>
 public virtual void Parse(PRStream stream, PdfDictionary resources) {
     baos = new MemoryStream();
     properties = resources.GetAsDict(PdfName.PROPERTIES);
     xobj = new HashSet2<PdfName>();
     PdfDictionary xobjects = resources.GetAsDict(PdfName.XOBJECT);
     if (xobjects != null) {
         // remove XObject (form or image) that belong to an OCG that needs to be removed
         foreach (PdfName name in xobjects.Keys) {
             PRStream xobject = (PRStream) xobjects.GetAsStream(name);
             PdfDictionary oc = xobject.GetAsDict(PdfName.OC);
             if (oc != null) {
                 PdfString ocname = oc.GetAsString(PdfName.NAME);
                 if (ocname != null && ocgs.Contains(ocname.ToString())) {
                     xobj.Add(name);
                 }
             }
         }
         foreach (PdfName name in xobj) {
             xobjects.Remove(name);
         }
     }
     // parse the content stream
     byte[] contentBytes = PdfReader.GetStreamBytes(stream);
     PRTokeniser tokeniser = new PRTokeniser(new RandomAccessFileOrArray(contentBytes));
     PdfContentParser ps = new PdfContentParser(tokeniser);
     List<PdfObject> operands = new List<PdfObject>();
     while (ps.Parse(operands).Count > 0) {
         PdfLiteral @operator = (PdfLiteral) operands[operands.Count - 1];
         ProcessOperator(this, @operator, operands);
     }
     baos.Flush();
     baos.Close();
     stream.SetData(baos.GetBuffer());
 }
开发者ID:,项目名称:,代码行数:38,代码来源:

示例13: ReadOneObjStm

 protected internal PdfObject ReadOneObjStm(PRStream stream, int idx) {
     int first = stream.GetAsNumber(PdfName.FIRST).IntValue;
     byte[] b = GetStreamBytes(stream, tokens.File);
     PRTokeniser saveTokens = tokens;
     tokens = new PRTokeniser(b);
     try {
         int address = 0;
         bool ok = true;
         ++idx;
         for (int k = 0; k < idx; ++k) {
             ok = tokens.NextToken();
             if (!ok)
                 break;
             if (tokens.TokenType != PRTokeniser.TK_NUMBER) {
                 ok = false;
                 break;
             }
             ok = tokens.NextToken();
             if (!ok)
                 break;
             if (tokens.TokenType != PRTokeniser.TK_NUMBER) {
                 ok = false;
                 break;
             }
             address = tokens.IntValue + first;
         }
         if (!ok)
             throw new InvalidPdfException(MessageLocalization.GetComposedMessage("error.reading.objstm"));
         tokens.Seek(address);
         return ReadPRObject();
     }
     finally {
         tokens = saveTokens;
     }
 }
开发者ID:pusp,项目名称:o2platform,代码行数:35,代码来源:PdfReader.cs

示例14: ParsePdf

// ---------------------------------------------------------------------------    
    /**
     * Parses the PDF using PRTokeniser
     * @param src the ]original PDF file
]     */
    public string ParsePdf(byte[] src) {
      PdfReader reader = new PdfReader(src);
      // we can inspect the syntax of the imported page
      byte[] streamBytes = reader.GetPageContent(1);
      StringBuilder sb = new StringBuilder();
      PRTokeniser tokenizer = new PRTokeniser(streamBytes);
      while (tokenizer.NextToken()) {
        if (tokenizer.TokenType == PRTokeniser.TokType.STRING) {
          sb.AppendLine(tokenizer.StringValue);
        }
      }
      return sb.ToString();
    }
开发者ID:,项目名称:,代码行数:18,代码来源:

示例15: Process

        public void Process(Crawler crawler, PropertyBag propertyBag)
        {
            AspectF.Define.
                NotNull(crawler, "crawler").
                NotNull(propertyBag, "propertyBag");

            if (propertyBag.StatusCode != HttpStatusCode.OK)
            {
                return;
            }

            if (!IsPdfContent(propertyBag.ContentType))
            {
                return;
            }

            PdfReader pdfReader = new PdfReader(propertyBag.Response);
            try
            {
                object title = pdfReader.Info["Title"];
                if (!title.IsNull())
                {
                    string pdfTitle = Convert.ToString(title, CultureInfo.InvariantCulture).Trim();
                    if (!pdfTitle.IsNullOrEmpty())
                    {
                        propertyBag.Title = pdfTitle;
                    }
                }

                StringBuilder sb = new StringBuilder();
                // Following code from:
                // http://www.vbforums.com/showthread.php?t=475759
                for (int p = 1; p <= pdfReader.NumberOfPages; p++)
                {
                    byte[] pageBytes = pdfReader.GetPageContent(p);

                    if (pageBytes.IsNull())
                    {
                        continue;
                    }

                    PRTokeniser token = new PRTokeniser(pageBytes);
                    while (token.NextToken())
                    {
                        int tknType = token.TokenType;
                        string tknValue = token.StringValue;

                        if (tknType == PRTokeniser.TK_STRING)
                        {
                            sb.Append(token.StringValue);
                            sb.Append(" ");
                        }
                        else if (tknType == 1 && tknValue == "-600")
                        {
                            sb.Append(" ");
                        }
                        else if (tknType == 10 && tknValue == "TJ")
                        {
                            sb.Append(" ");
                        }
                    }
                }

                propertyBag.Text = sb.ToString();
            }
            finally
            {
                pdfReader.Close();
            }
        }
开发者ID:bormaxi,项目名称:NCrawler,代码行数:70,代码来源:iTextSharpPdfProcessor.cs


注:本文中的iTextSharp.text.pdf.PRTokeniser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。