本文整理匯總了C#中iTextSharp.text.pdf.PRTokeniser.NextToken方法的典型用法代碼示例。如果您正苦於以下問題:C# PRTokeniser.NextToken方法的具體用法?C# PRTokeniser.NextToken怎麽用?C# PRTokeniser.NextToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PRTokeniser
的用法示例。
在下文中一共展示了PRTokeniser.NextToken方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
}
示例2: 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();
}
}
示例3: 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;
}
示例4: 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;
}
}
示例5: 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;
}
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
}
示例9: 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();
}
示例10: 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();
}
}
示例11: 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;
}
示例12: ReadObjStm
protected internal void ReadObjStm(PRStream stream, IntHashtable map) {
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(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.TK_NUMBER) {
ok = false;
break;
}
objNumber[k] = tokens.IntValue;
ok = tokens.NextToken();
if (!ok)
break;
if (tokens.TokenType != PRTokeniser.TK_NUMBER) {
ok = false;
break;
}
address[k] = tokens.IntValue + first;
}
if (!ok)
throw new InvalidPdfException("Error reading ObjStm");
for (int k = 0; k < n; ++k) {
if (map.ContainsKey(k)) {
tokens.Seek(address[k]);
PdfObject obj = ReadPRObject();
xrefObj[objNumber[k]] = obj;
}
}
}
finally {
tokens = saveTokens;
}
}