提取物iTextSharp的路径和形状 [英] Extract paths and shapes with iTextSharp
问题描述
iTextSharp的支持与 PdfContentByte创建形状和路径
类,也可以设置颜色和油漆的曲线和基本要素...有哪些做的其他方式的机制?我可以通过调用 PdfReader.GetPageContent(...)
来获取内容,但我没有找到一个解析器阅读这些操作,并将其应用到图形上下文和
iTextSharp supports creation of shapes and paths with PdfContentByte
class, there you can set colors and paint curves and basic elements ... is there a mechanism which does the other way? I am able to get content by calling PdfReader.GetPageContent(...)
but I didn't find a "parser" to read those operations, apply them to graphics context and for example paint it on a panel.
Example:
例1 RG
1 1 1 RG
0.12 0 0 0.12 1631厘米
Q
480421米
4318421升
4318 5459升
4805459升
480421升W N
0.074509806931 0.074509806931 0.074509806931 RG
0.074509806931 0.074509806931 0.074509806931 RG / OC /过流BDC
....
感谢您的回复!
推荐答案
下面是提取网页的不同命令的起点:
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<PdfObject> operands = new List<PdfObject>();
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!
}
}
这篇关于提取物iTextSharp的路径和形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!