我需要解析pdf的帮助,它有4层,每一层都有一个图形路径对象我不会做的是获取所有4个图形路径并将它们绘制在另一个具有相同宽度的pdf文件中像这个pdf一样高,我想把它们画在相同的位置。这是我开始编写的代码:
public static List<PDFMask> GetMasksFromPage(PdfPage page)
{
List<PDFMask> masks = new List<PDFMask>();
PdfDictionary contents = page.Elements.GetDictionary("/Contents");
PdfDictionary.PdfStream contentsStream = contents.Stream;
PdfDictionary resources = page.Elements.GetDictionary("/Resources");
PdfDictionary properties = resources.Elements.GetDictionary("/Properties");
PdfName[] keys = properties.Elements.KeyNames;
int dataStartPointer = 0;
int dataEndPointer = Utils.Bytes.IndexOf(contentsStream.UnfilteredValue, Encoding.ASCII.GetBytes("EMC "), dataStartPointer);
int dataCount = dataEndPointer+4;
for (int i = 0; i < keys.Length; i++)
{
PdfDictionary mc = properties.Elements.GetDictionary(keys[i].Value);
PDFMask mask = new PDFMask();
mask.name = mc.Elements.GetString("/Title");
mask.key = keys[i].Value;
byte[] data = new byte[dataCount];
Array.Copy(contentsStream.UnfilteredValue, dataStartPointer, mask.data, 0, dataCount);
mask.parseData(data);
dataStartPointer += dataCount+1;
dataEndPointer = Utils.Bytes.IndexOf(contentsStream.UnfilteredValue, Encoding.ASCII.GetBytes("EMC "), dataStartPointer);
dataCount = dataEndPointer + 4 - dataStartPointer;
masks.Add(mask);
}
return masks;
}
现在上面的代码用于获取所有图层数据并将它们分成 4 个对象
PdfDictionary.PdfStream contentsStream = contents.Stream;
这条线给了我 4 层图形二进制数据现在这是代表 1 层的 PDFMask 类
public class PDFMask
{
public string name;
public string key;
public byte[] data;
public void parseData(byte[] data)
{
this.data = data; //how i parsing this data to some XGrapic Object?
}
}
现在这是数据源的样子:
/Layer /MC0 BDC
0.75 0.68 0.67 0.902 k
/GS0 gs
q 1 0 0 1 396.4473 1835.6143 cm
0 0 m
76.497 -132.515 l
-17.184 -159.051 l
76.496 -185.607 l
-0.003 -318.119 l
-72.563 -252.047 l
-50.486 -349.178 l
-202.179 -349.182 l
-180.097 -252.046 l
-252.658 -318.116 l
-329.154 -185.603 l
-235.473 -159.048 l
-329.154 -132.511 l
-252.654 0.002 l
-180.094 -66.07 l
-202.175 31.087 l
-50.482 31.081 l
-72.563 -66.072 l
h
f
Q
EMC
我正在寻找一些解析器(我更喜欢 pdfsharp 解析器),它可以将这些数据解析为一些图形对象,我可以在另一个 pdf 文档上使用它