本文整理汇总了C#中iTextSharp.text.pdf.PRTokeniser类的典型用法代码示例。如果您正苦于以下问题:C# PRTokeniser类的具体用法?C# PRTokeniser怎么用?C# PRTokeniser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PRTokeniser类属于iTextSharp.text.pdf命名空间,在下文中一共展示了PRTokeniser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: CheckObjectStart
public static long[] CheckObjectStart (byte[] line) {
try {
PRTokeniser tk = new PRTokeniser(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:,项目名称:,代码行数:21,代码来源:
示例17: GetOffsetTokeniser
/**
* Utility method that checks the provided byte source to see if it has junk bytes at the beginning. If junk bytes
* are found, construct a tokeniser that ignores the junk. Otherwise, construct a tokeniser for the byte source as it is
* @param byteSource the source to check
* @return a tokeniser that is guaranteed to start at the PDF header
* @throws IOException if there is a problem reading the byte source
*/
private static PRTokeniser GetOffsetTokeniser(IRandomAccessSource byteSource) {
PRTokeniser tok = new PRTokeniser(new RandomAccessFileOrArray(byteSource));
int offset = tok.GetHeaderOffset();
if (offset != 0){
IRandomAccessSource offsetSource = new WindowRandomAccessSource(byteSource, offset);
tok = new PRTokeniser(new RandomAccessFileOrArray(offsetSource));
}
return tok;
}
开发者ID:,项目名称:,代码行数:16,代码来源:
示例18: ReadObjStm
virtual protected internal void ReadObjStm(PRStream stream, IntHashtable map) {
if (stream == null) return;
int first = stream.GetAsNumber(PdfName.FIRST).IntValue;
int n = stream.GetAsNumber(PdfName.N).IntValue;
byte[] b = GetStreamBytes(stream, tokens.File);
PRTokeniser saveTokens = tokens;
tokens = new PRTokeniser(new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateSource(b)));
try {
int[] address = new int[n];
int[] objNumber = new int[n];
bool ok = true;
for (int k = 0; k < n; ++k) {
ok = tokens.NextToken();
if (!ok)
break;
if (tokens.TokenType != PRTokeniser.TokType.NUMBER) {
ok = false;
break;
}
objNumber[k] = tokens.IntValue;
ok = tokens.NextToken();
if (!ok)
break;
if (tokens.TokenType != PRTokeniser.TokType.NUMBER) {
ok = false;
break;
}
address[k] = tokens.IntValue + first;
}
if (!ok)
throw new InvalidPdfException(MessageLocalization.GetComposedMessage("error.reading.objstm"));
for (int k = 0; k < n; ++k) {
if (map.ContainsKey(k)) {
tokens.Seek(address[k]);
tokens.NextToken();
PdfObject obj;
if (tokens.TokenType == PRTokeniser.TokType.NUMBER) {
obj = new PdfNumber(tokens.StringValue);
}
else {
tokens.Seek(address[k]);
obj = ReadPRObject();
}
xrefObj[objNumber[k]] = obj;
}
}
}
finally {
tokens = saveTokens;
}
}
开发者ID:,项目名称:,代码行数:51,代码来源:
示例19: SplitDAelements
public static Object[] SplitDAelements(String da)
{
PRTokeniser tk = new PRTokeniser(PdfEncodings.ConvertToBytes(da, null));
ArrayList stack = new ArrayList();
Object[] ret = new Object[3];
while (tk.NextToken()) {
if (tk.TokenType == PRTokeniser.TK_COMMENT)
continue;
if (tk.TokenType == PRTokeniser.TK_OTHER) {
String oper = tk.StringValue;
if (oper.Equals("Tf")) {
if (stack.Count >= 2) {
ret[DA_FONT] = stack[stack.Count - 2];
ret[DA_SIZE] = float.Parse((String)stack[stack.Count - 1], System.Globalization.NumberFormatInfo.InvariantInfo);
}
}
else if (oper.Equals("g")) {
if (stack.Count >= 1) {
float gray = float.Parse((String)stack[stack.Count - 1], System.Globalization.NumberFormatInfo.InvariantInfo);
if (gray != 0)
ret[DA_COLOR] = new GrayColor(gray);
}
}
else if (oper.Equals("rg")) {
if (stack.Count >= 3) {
float red = float.Parse((String)stack[stack.Count - 3], System.Globalization.NumberFormatInfo.InvariantInfo);
float green = float.Parse((String)stack[stack.Count - 2], System.Globalization.NumberFormatInfo.InvariantInfo);
float blue = float.Parse((String)stack[stack.Count - 1], System.Globalization.NumberFormatInfo.InvariantInfo);
ret[DA_COLOR] = new Color(red, green, blue);
}
}
else if (oper.Equals("k")) {
if (stack.Count >= 4) {
float cyan = float.Parse((String)stack[stack.Count - 4], System.Globalization.NumberFormatInfo.InvariantInfo);
float magenta = float.Parse((String)stack[stack.Count - 3], System.Globalization.NumberFormatInfo.InvariantInfo);
float yellow = float.Parse((String)stack[stack.Count - 2], System.Globalization.NumberFormatInfo.InvariantInfo);
float black = float.Parse((String)stack[stack.Count - 1], System.Globalization.NumberFormatInfo.InvariantInfo);
ret[DA_COLOR] = new CMYKColor(cyan, magenta, yellow, black);
}
}
stack.Clear();
}
else
stack.Add(tk.StringValue);
}
return ret;
}
开发者ID:JamieMellway,项目名称:iTextSharpLGPL-Monotouch,代码行数:47,代码来源:AcroFields.cs
示例20: CompareInnerText
virtual public bool CompareInnerText(String path1, String path2) {
PdfReader reader1 = new PdfReader(path1);
byte[] streamBytes1 = reader1.GetPageContent(1);
PRTokeniser tokenizer1 =
new PRTokeniser(new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateSource(streamBytes1)));
PdfReader reader2 = new PdfReader(path2);
byte[] streamBytes2 = reader2.GetPageContent(1);
PRTokeniser tokenizer2 =
new PRTokeniser(new RandomAccessFileOrArray(new RandomAccessSourceFactory().CreateSource(streamBytes2)));
try {
while (tokenizer1.NextToken()) {
if (!tokenizer2.NextToken())
return false;
else {
if (tokenizer1.TokenType != tokenizer2.TokenType)
return false;
else {
if (tokenizer1.TokenType == tokenizer2.TokenType && tokenizer2.TokenType == PRTokeniser.TokType.NUMBER) {
if (Math.Abs(float.Parse(tokenizer1.StringValue, CultureInfo.InvariantCulture)
- float.Parse(tokenizer2.StringValue, CultureInfo.InvariantCulture)) > 0.001)
return false;
} else if (!tokenizer1.StringValue.Equals(tokenizer2.StringValue))
return false;
}
}
}
return true;
}
finally {
reader1.Close();
reader2.Close();
}
}
开发者ID:Niladri24dutta,项目名称:itextsharp,代码行数:38,代码来源:ChunkTest.cs
注:本文中的iTextSharp.text.pdf.PRTokeniser类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论