iTextSharp:阅读单选按钮,从非表格PDF复选框状态

时间:2011-11-29 16:35:26

标签: pdf checkbox radio-button itextsharp

我有一个pdf文档(由第三方使用RealObjects PDFreactor创建),不是表单。我正在尝试使用iTextSharp从该PDF中提取信息。我能够提取所有纯文本(使用SimpleTextExtractionStrategy),但有一些信息用单选按钮表示,在提取的纯文本中没有提到。我是iTextSharp的初学者,所以我可能会忽略一些非常简单的东西。 PdfReader.AcroForm返回null,PdfReader.AcroFields.Fields有0个键。如何在整个文档中找出单选按钮和复选框的状态?这些文件都有相同的结构,所以我真的不需要单选按钮&要标记的复选框;只需要一个项目列表,并知道它们是否被检查就足够了。

我已确认单选按钮不仅仅是使用this approach的图像。

我通过修改代码来提取图像,试图找到页面上的所有BTN对象,但我显然搞砸了,因为它不会在包含单选按钮的页面上返回任何内容:

private List<PdfObject> GetBTNFromPdfDict(PdfDictionary dict, PdfReader doc)
{
    List<PdfObject> objects = new List<PdfObject>();

    foreach (PdfName name in dict.Keys)
    {
        PdfObject obj = dict.Get(name);
        PdfDictionary tg = PdfReader.GetPdfObject(obj) as PdfDictionary;
        if (null != tg)
        {
            PdfName subtype = (PdfName)(PdfReader.GetPdfObject(tg.Get(PdfName.SUBTYPE)));

            if (obj.IsIndirect())
            {
                if (PdfName.BTN.Equals(subtype))
                {
                    int xrefIdx = ((PRIndirectReference)obj).Number;
                    PdfObject pdfObj = doc.GetPdfObject(xrefIdx);
                    objects.Add(pdfObj);
                }
                else if (PdfName.FORM.Equals(subtype) || PdfName.GROUP.Equals(subtype))
                {
                    objects.AddRange(GetBTNFromPdfDict(tg, doc));
                }
            }
            else objects.AddRange(GetBTNFromPdfDict(tg, doc));                    
        }
    }

    return objects;
}

我还使用PdfContentReaderTool查看了该页面的内容;输出不包括任何BTN,所以我不确定发生了什么。这是输出(我用[TEXT]替换了所有文本行)。只是看一下内容流部分,提取所有字符串(括号之间的所有字符串后跟Tj)似乎微不足道,但我似乎无法弄清楚单选按钮和复选框。 (我不得不缩减输出,问题太长了)

==============Page 2====================
- - - - - Dictionary - - - - - -
(/Type=/Page, /TrimBox=System.Collections.Generic.List`1[iTextSharp.text.pdf.PdfObject], /Contents=Stream, /Parent=Dictionary of type: /Pages, /Group=Dictionary of type: /Group, /BleedBox=System.Collections.Generic.List`1[iTextSharp.text.pdf.PdfObject], /Resources=Dictionary, /MediaBox=System.Collections.Generic.List`1[iTextSharp.text.pdf.PdfObject])
    Subdictionary /Parent = (/Count=10, /Type=/Pages, /Parent=Dictionary of type: /Pages, /Kids=System.Collections.Generic.List`1[iTextSharp.text.pdf.PdfObject])
        Subdictionary /Parent = (/Count=39, /Type=/Pages, /ITXT=2.1.6, /Kids=System.Collections.Generic.List`1[iTextSharp.text.pdf.PdfObject])
    Subdictionary /Group = (/Type=/Group, /S=/Transparency, /CS=/DeviceRGB)
    Subdictionary /Resources = (/ColorSpace=Dictionary, /ProcSet=System.Collections.Generic.List`1[iTextSharp.text.pdf.PdfObject], /Font=Dictionary)
        Subdictionary /ColorSpace = (/CS=/DeviceRGB)
        Subdictionary /Font = (/F1=Dictionary of type: /Font, /F3=Dictionary of type: /Font, /F2=Dictionary of type: /Font, /F4=Dictionary of type: /Font)
            Subdictionary /F1 = (/Type=/Font, /BaseFont=/Helvetica, /Subtype=/Type1, /Encoding=/WinAnsiEncoding)
            Subdictionary /F3 = (/Type=/Font, /BaseFont=/Times-Bold, /Subtype=/Type1, /Encoding=/WinAnsiEncoding)
            Subdictionary /F2 = (/Type=/Font, /BaseFont=/Times-Roman, /Subtype=/Type1, /Encoding=/WinAnsiEncoding)
            Subdictionary /F4 = (/Type=/Font, /BaseFont=/Times-Italic, /Subtype=/Type1, /Encoding=/WinAnsiEncoding)
- - - - - XObject Summary - - - - - -
No XObjects
- - - - - Content Stream - - - - - -
q
BT
36 805.89 Td
ET
Q
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
1 w
2 J
0 j
10 M
[]0 d
q
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.03 w
2 J
0 j
10 M
[]0 d
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0 841.89 m
595.29 841.89 l
595.29 0 l
0 0 l
0 841.89 l
h
W
n
0 0 0 rg
BT
/F1 233.33 Tf
0.03 0 0 0.03 540.69 4.71 Tm
12.63 Tc
(TEXT)Tj
0 Tc
ET
BT
/F1 233.33 Tf
0.03 0 0 0.03 129.18 4.71 Tm
11.37 Tc
(TEXT)Tj
0 Tc
ET
0.8 0.8 0.8 rg
15 826.89 m
580.29 826.89 l
580.29 494.79 l
15 494.79 l
15 826.89 l
h
f
0 0 0 rg
20.1 826.89 m
575.16 826.89 l
574.41 826.14 l
20.85 826.14 l
h
f
20.85 495.54 m
574.41 495.54 l
575.16 494.79 l
20.1 494.79 l
h
f
20.1 826.89 m
20.85 826.14 l
20.85 495.54 l
20.1 494.79 l
h
f
574.41 826.14 m
575.16 826.89 l
575.16 494.79 l
574.41 495.54 l
h
f
1 1 1 rg
20.85 826.14 m
574.41 826.14 l
574.41 495.54 l
20.85 495.54 l
20.85 826.14 l
h
f
0 0 0 rg
28.35 818.64 m
566.91 818.64 l
566.91 799.14 l
28.35 799.14 l
28.35 818.64 l
h
f
1 1 1 rg
BT
/F3 350 Tf
0.03 0 0 0.03 31.35 804.69 Tm
6.52 Tc
(I. )Tj
0 Tc
ET
BT
/F3 350 Tf
0.03 0 0 0.03 41.07 804.69 Tm
27.57 Tc
(TEXT)Tj
0 Tc
ET
0 0 0 rg
BT
/F2 300 Tf
0.03 0 0 0.03 28.35 789.54 Tm
( )Tj
ET
28.35 787.14 m
566.91 787.14 l
566.16 786.39 l
29.1 786.39 l
h
f
29.1 728.64 m
566.16 728.64 l
566.91 727.89 l
28.35 727.89 l
h
f
28.35 787.14 m
29.1 786.39 l
29.1 728.64 l
28.35 727.89 l
h
f
566.16 786.39 m
566.91 787.14 l
566.91 727.89 l
566.16 728.64 l
h
f
29.1 729.39 m
296.88 729.39 l
297.63 728.64 l
29.1 728.64 l
h
f
296.88 786.39 m
297.63 786.39 l
297.63 728.64 l
296.88 729.39 l
h
f
BT
/F2 250 Tf
0.03 0 0 0.03 32.1 775.14 Tm
19.36 Tc
(TEXT)Tj
0 Tc
ET
0.37647 0.37647 0.37647 rg
32.1 772.89 m
293.88 772.89 l
292.38 771.39 l
33.6 771.39 l
h
f
0.87843 0.87843 0.87843 rg
292.38 771.39 m
293.88 772.89 l
293.88 744.39 l
292.38 745.14 l
h
f
0.37647 0.37647 0.37647 rg
32.1 772.89 m
33.6 771.39 l
33.6 745.14 l
32.1 744.39 l
h
f
0 0 0 rg
33.6 745.14 m
292.38 745.14 l
293.88 744.39 l
32.1 744.39 l
h
f
1 1 1 rg
33.6 771.39 m
292.38 771.39 l
292.38 745.14 l
33.6 745.14 l
33.6 771.39 l
h
f
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.03 w
2 J
0 j
10 M
[]0 d
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
33.72 766.14 m
287.13 766.14 l
287.13 750.39 l
33.72 750.39 l
33.72 766.14 l
h
W
n
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.74987 w
2 J
0 j
10 M
[]0 d
q
33.72 766.14 m
33.72 750.39 l
287.13 750.39 l
287.13 766.14 l
h
W
n
1 1 1 rg
33.72 766.14 m
287.13 766.14 l
287.13 750.39 l
33.72 750.39 l
33.72 766.14 l
h
f
33.72 766.14 m
287.13 766.14 l
287.13 750.39 l
33.72 750.39 l
33.72 766.14 l
h
W
n
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.74987 w
2 J
0 j
10 M
[]0 d
q
33.72 766.14 m
33.72 750.39 l
287.13 750.39 l
287.13 766.14 l
h
W
n
0 0 0 rg
BT
/F2 18 Tf
0.74973 0 0 0.75 33.72 753.31 Tm
2.02 Tc
(TEXT)Tj
0 Tc
ET
BT
/F2 18 Tf
0.74973 0 0 0.75 76.53 753.31 Tm
( )Tj
ET
BT
/F2 18 Tf
0.74973 0 0 0.75 80.63 753.31 Tm
1.85 Tc
(TEXT)Tj
0 Tc
ET
Q
Q
Q
Q
Q
Q
0 0 0 rg
297.63 729.39 m
566.16 729.39 l
566.16 728.64 l
297.63 728.64 l
h
f
BT
/F2 250 Tf
0.03 0 0 0.03 300.63 775.14 Tm
18.42 Tc
(TEXT)Tj
0 Tc
ET
0.37647 0.37647 0.37647 rg
300.63 772.89 m
563.16 772.89 l
561.66 771.39 l
302.13 771.39 l
h
f
0.87843 0.87843 0.87843 rg
561.66 771.39 m
563.16 772.89 l
563.16 744.39 l
561.66 745.14 l
h
f
0.37647 0.37647 0.37647 rg
300.63 772.89 m
302.13 771.39 l
302.13 745.14 l
300.63 744.39 l
h
f
0 0 0 rg
302.13 745.14 m
561.66 745.14 l
563.16 744.39 l
300.63 744.39 l
h
f
1 1 1 rg
302.13 771.39 m
561.66 771.39 l
561.66 745.14 l
302.13 745.14 l
302.13 771.39 l
h
f
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.03 w
2 J
0 j
10 M
[]0 d
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
302.25 766.14 m
556.41 766.14 l
556.41 750.39 l
302.25 750.39 l
302.25 766.14 l
h
W
n
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.74987 w
2 J
0 j
10 M
[]0 d
q
302.25 766.14 m
302.25 750.39 l
556.41 750.39 l
556.41 766.14 l
h
W
n
1 1 1 rg
302.25 766.14 m
556.41 766.14 l
556.41 750.39 l
302.25 750.39 l
302.25 766.14 l
h
f
302.25 766.14 m
556.41 766.14 l
556.41 750.39 l
302.25 750.39 l
302.25 766.14 l
h
W
n
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.74987 w
2 J
0 j
10 M
[]0 d
q
302.25 766.14 m
302.25 750.39 l
556.41 750.39 l
556.41 766.14 l
h
W
n
0 0 0 rg
BT
/F2 18 Tf
0.74973 0 0 0.75 302.25 753.31 Tm
1.42 Tc
(TEXT)Tj
0 Tc
ET
BT
/F2 18 Tf
0.74973 0 0 0.75 344.3 753.31 Tm
( )Tj
ET
BT
/F2 18 Tf
0.74973 0 0 0.75 348.4 753.31 Tm
1.8 Tc
(TEXT)Tj
0 Tc
ET
BT
/F2 18 Tf
0.74973 0 0 0.75 431.64 753.31 Tm
( )Tj
ET
BT
/F2 18 Tf
0.74973 0 0 0.75 435.75 753.31 Tm
1.23 Tc
(TEXT)Tj
0 Tc
ET
Q
Q
Q
Q
Q
Q
0 0 0 rg
28.35 727.89 m
566.91 727.89 l
566.16 727.14 l
29.1 727.14 l
h
f
29.1 503.79 m
566.16 503.79 l
566.91 503.04 l
28.35 503.04 l
h
f
28.35 727.89 m
29.1 727.14 l
29.1 503.79 l
28.35 503.04 l
h
f
566.16 727.14 m
566.91 727.89 l
566.91 503.04 l
566.16 503.79 l
h
f
29.1 670.14 m
296.88 670.14 l
297.63 669.39 l
29.1 669.39 l
h
f
296.88 727.14 m
297.63 727.14 l
297.63 669.39 l
296.88 670.14 l
h
f
BT
/F2 250 Tf
0.03 0 0 0.03 32.1 715.89 Tm
19.68 Tc
(TEXT )Tj
0 Tc
ET
0.37647 0.37647 0.37647 rg
32.1 713.64 m
293.88 713.64 l
292.38 712.14 l
33.6 712.14 l
h
f
0.87843 0.87843 0.87843 rg
292.38 712.14 m
293.88 713.64 l
293.88 685.14 l
292.38 685.89 l
h
f
0.37647 0.37647 0.37647 rg
32.1 713.64 m
33.6 712.14 l
33.6 685.89 l
32.1 685.14 l
h
f
0 0 0 rg
33.6 685.89 m
292.38 685.89 l
293.88 685.14 l
32.1 685.14 l
h
f
1 1 1 rg
33.6 712.14 m
292.38 712.14 l
292.38 685.89 l
33.6 685.89 l
33.6 712.14 l
h
f
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.03 w
2 J
0 j
10 M
[]0 d
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
33.72 706.89 m
287.13 706.89 l
287.13 691.14 l
33.72 691.14 l
33.72 706.89 l
h
W
n
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.74987 w
2 J
0 j
10 M
[]0 d
q
33.72 706.89 m
33.72 691.14 l
287.13 691.14 l
287.13 706.89 l
h
W
n
1 1 1 rg
33.72 706.89 m
287.13 706.89 l
287.13 691.14 l
33.72 691.14 l
33.72 706.89 l
h
f
33.72 706.89 m
287.13 706.89 l
287.13 691.14 l
33.72 691.14 l
33.72 706.89 l
h
W
n
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.74987 w
2 J
0 j
10 M
[]0 d
q
33.72 706.89 m
33.72 691.14 l
287.13 691.14 l
287.13 706.89 l
h
W
n
0 0 0 rg
BT
/F2 18 Tf
0.74973 0 0 0.75 33.72 694.06 Tm
1.8 Tc
(TEXT)Tj
0 Tc
ET
BT
/F2 18 Tf
0.74973 0 0 0.75 77.19 694.06 Tm
( )Tj
ET
BT
/F2 18 Tf
0.74973 0 0 0.75 81.3 694.06 Tm
1.89 Tc
(TEXT)Tj
0 Tc
ET
Q
Q
Q
Q
Q
Q
0 0 0 rg
297.63 670.14 m
566.16 670.14 l
566.16 669.39 l
297.63 669.39 l
h
f
BT
/F2 250 Tf
0.03 0 0 0.03 300.63 715.89 Tm
22.9 Tc
(TEXT )Tj
0 Tc
ET
0.37647 0.37647 0.37647 rg
300.63 713.64 m
563.16 713.64 l
561.66 712.14 l
302.13 712.14 l
h
f
0.87843 0.87843 0.87843 rg
561.66 712.14 m
563.16 713.64 l
563.16 685.14 l
561.66 685.89 l
h
f
0.37647 0.37647 0.37647 rg
300.63 713.64 m
302.13 712.14 l
302.13 685.89 l
300.63 685.14 l
h
f
0 0 0 rg
302.13 685.89 m
561.66 685.89 l
563.16 685.14 l
300.63 685.14 l
h
f
1 1 1 rg
302.13 712.14 m
561.66 712.14 l
561.66 685.89 l
302.13 685.89 l
302.13 712.14 l
h
f
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.03 w
2 J
0 j
10 M
[]0 d
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
302.25 706.89 m
556.41 706.89 l
556.41 691.14 l
302.25 691.14 l
302.25 706.89 l
h
W
n
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.74987 w
2 J
0 j
10 M
[]0 d
q
302.25 706.89 m
302.25 691.14 l
556.41 691.14 l
556.41 706.89 l
h
W
n
1 1 1 rg
302.25 706.89 m
556.41 706.89 l
556.41 691.14 l
302.25 691.14 l
302.25 706.89 l
h
f
302.25 706.89 m
556.41 706.89 l
556.41 691.14 l
302.25 691.14 l
302.25 706.89 l
h
W
n
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.74987 w
2 J
0 j
10 M
[]0 d
q
302.25 706.89 m
302.25 691.14 l
556.41 691.14 l
556.41 706.89 l
h
W
n
Q
Q
Q
Q
Q
Q
0 0 0 rg
29.1 504.54 m
566.16 504.54 l
566.16 503.79 l
29.1 503.79 l
h
f
0.86667 0.86667 0.86667 rg
29.1 669.39 m
566.16 669.39 l
566.16 504.54 l
29.1 504.54 l
29.1 669.39 l
h
f
0 0 0 rg
BT
/F2 250 Tf
0.03 0 0 0.03 32.1 658.14 Tm
19.96 Tc
(TEXT)Tj
0 Tc
ET
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.03 w
2 J
0 j
10 M
[]0 d
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
54.6 647.46 m
61.35 647.46 l
61.35 640.71 l
54.6 640.71 l
54.6 647.46 l
h
W
n
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.75 w
2 J
0 j
10 M
[]0 d
q
54.6 647.46 m
54.6 640.71 l
61.35 640.71 l
61.35 647.46 l
h
W
n
Q
Q
Q
q
47.85 654.21 m
68.1 654.21 l
68.1 633.96 l
47.85 633.96 l
47.85 654.21 l
h
W
n
1 1 1 rg
61.35 644.08 m
61.35 642.22 59.84 640.71 57.97 640.71 c
56.11 640.71 54.6 642.22 54.6 644.08 c
54.6 645.95 56.11 647.46 57.97 647.46 c
59.84 647.46 61.35 645.95 61.35 644.08 c
h
f
Q
q
47.85 654.21 m
68.1 654.21 l
68.1 633.96 l
47.85 633.96 l
47.85 654.21 l
h
W
n
0 0 0 rg
57.97 646.71 m
59.42 646.71 60.6 645.53 60.6 644.08 c
60.6 642.64 59.42 641.46 57.97 641.46 c
56.53 641.46 55.35 642.64 55.35 644.08 c
55.35 645.53 56.53 646.71 57.97 646.71 c
h
57.97 647.46 m
56.11 647.46 54.6 645.95 54.6 644.08 c
54.6 642.22 56.11 640.71 57.97 640.71 c
59.84 640.71 61.35 642.22 61.35 644.08 c
61.35 645.95 59.84 647.46 57.97 647.46 c
h
f
Q
Q
BT
/F2 250 Tf
0.03 0 0 0.03 64.35 642.39 Tm
21.62 Tc
(TEXT)Tj
0 Tc
ET
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.03 w
2 J
0 j
10 M
[]0 d
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
54.6 630.39 m
61.35 630.39 l
61.35 623.64 l
54.6 623.64 l
54.6 630.39 l
h
W
n
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.75 w
2 J
0 j
10 M
[]0 d
q
54.6 630.39 m
54.6 623.64 l
61.35 623.64 l
61.35 630.39 l
h
W
n
Q
Q
Q
q
47.85 637.14 m
68.1 637.14 l
68.1 616.89 l
47.85 616.89 l
47.85 637.14 l
h
W
n
1 1 1 rg
61.35 627.01 m
61.35 625.15 59.84 623.64 57.97 623.64 c
56.11 623.64 54.6 625.15 54.6 627.01 c
54.6 628.88 56.11 630.39 57.97 630.39 c
59.84 630.39 61.35 628.88 61.35 627.01 c
h
f
Q
q
47.85 637.14 m
68.1 637.14 l
68.1 616.89 l
47.85 616.89 l
47.85 637.14 l
h
W
n
0 0 0 rg
57.97 629.64 m
59.42 629.64 60.6 628.46 60.6 627.01 c
60.6 625.57 59.42 624.39 57.97 624.39 c
56.53 624.39 55.35 625.57 55.35 627.01 c
55.35 628.46 56.53 629.64 57.97 629.64 c
h
57.97 630.39 m
56.11 630.39 54.6 628.88 54.6 627.01 c
54.6 625.15 56.11 623.64 57.97 623.64 c
59.84 623.64 61.35 625.15 61.35 627.01 c
61.35 628.88 59.84 630.39 57.97 630.39 c
h
f
59.66 627.01 m
59.66 626.08 58.91 625.33 57.97 625.33 c
57.04 625.33 56.29 626.08 56.29 627.01 c
56.29 627.95 57.04 628.7 57.97 628.7 c
58.91 628.7 59.66 627.95 59.66 627.01 c
h
f
Q
Q
BT
/F2 250 Tf
0.03 0 0 0.03 64.35 625.32 Tm
18.25 Tc
(TEXT)Tj
0 Tc
ET
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.03 w
2 J
0 j
10 M
[]0 d
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
65.1 610.32 m
71.85 610.32 l
71.85 603.57 l
65.1 603.57 l
65.1 610.32 l
h
W
n
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.75 w
2 J
0 j
10 M
[]0 d
q
65.1 610.32 m
65.1 603.57 l
71.85 603.57 l
71.85 610.32 l
h
W
n
Q
Q
Q
q
58.35 617.07 m
78.6 617.07 l
78.6 596.82 l
58.35 596.82 l
58.35 617.07 l
h
W
n
1 1 1 rg
71.85 606.94 m
71.85 605.08 70.34 603.57 68.47 603.57 c
66.61 603.57 65.1 605.08 65.1 606.94 c
65.1 608.81 66.61 610.32 68.47 610.32 c
70.34 610.32 71.85 608.81 71.85 606.94 c
h
f
Q
q
58.35 617.07 m
78.6 617.07 l
78.6 596.82 l
58.35 596.82 l
58.35 617.07 l
h
W
n
0 0 0 rg
68.47 609.57 m
69.92 609.57 71.1 608.39 71.1 606.94 c
71.1 605.5 69.92 604.32 68.47 604.32 c
67.03 604.32 65.85 605.5 65.85 606.94 c
65.85 608.39 67.03 609.57 68.47 609.57 c
h
68.47 610.32 m
66.61 610.32 65.1 608.81 65.1 606.94 c
65.1 605.08 66.61 603.57 68.47 603.57 c
70.34 603.57 71.85 605.08 71.85 606.94 c
71.85 608.81 70.34 610.32 68.47 610.32 c
h
f
70.16 606.94 m
70.16 606.01 69.41 605.26 68.47 605.26 c
67.54 605.26 66.79 606.01 66.79 606.94 c
66.79 607.88 67.54 608.63 68.47 608.63 c
69.41 608.63 70.16 607.88 70.16 606.94 c
h
f
Q
Q
BT
/F2 250 Tf
0.03 0 0 0.03 74.85 605.25 Tm
21.69 Tc
( TEXT)Tj
0 Tc
ET
BT
/F2 250 Tf
0.03 0 0 0.03 399.88 605.25 Tm
( )Tj
ET
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.03 w
2 J
0 j
10 M
[]0 d
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
65.1 593.25 m
71.85 593.25 l
71.85 586.5 l
65.1 586.5 l
65.1 593.25 l
h
W
n
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.75 w
2 J
0 j
10 M
[]0 d
q
65.1 593.25 m
65.1 586.5 l
71.85 586.5 l
71.85 593.25 l
h
W
n
Q
Q
Q
q
58.35 600 m
78.6 600 l
78.6 579.75 l
58.35 579.75 l
58.35 600 l
h
W
n
1 1 1 rg
71.85 589.87 m
71.85 588.01 70.34 586.5 68.47 586.5 c
66.61 586.5 65.1 588.01 65.1 589.87 c
65.1 591.74 66.61 593.25 68.47 593.25 c
70.34 593.25 71.85 591.74 71.85 589.87 c
h
f
Q
q
58.35 600 m
78.6 600 l
78.6 579.75 l
58.35 579.75 l
58.35 600 l
h
W
n
0 0 0 rg
68.47 592.5 m
69.92 592.5 71.1 591.32 71.1 589.87 c
71.1 588.43 69.92 587.25 68.47 587.25 c
67.03 587.25 65.85 588.43 65.85 589.87 c
65.85 591.32 67.03 592.5 68.47 592.5 c
h
68.47 593.25 m
66.61 593.25 65.1 591.74 65.1 589.87 c
65.1 588.01 66.61 586.5 68.47 586.5 c
70.34 586.5 71.85 588.01 71.85 589.87 c
71.85 591.74 70.34 593.25 68.47 593.25 c
h
f
Q
Q
BT
/F2 250 Tf
0.03 0 0 0.03 74.85 588.18 Tm
23.16 Tc
( TEXT)Tj
0 Tc
ET
BT
/F2 250 Tf
0.03 0 0 0.03 407.97 588.18 Tm
( )Tj
ET
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.03 w
2 J
0 j
10 M
[]0 d
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
65.1 576.18 m
71.85 576.18 l
71.85 569.43 l
65.1 569.43 l
65.1 576.18 l
h
W
n
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.75 w
2 J
0 j
10 M
[]0 d
q
65.1 576.18 m
65.1 569.43 l
71.85 569.43 l
71.85 576.18 l
h
W
n
Q
Q
Q
q
58.35 582.93 m
78.6 582.93 l
78.6 562.68 l
58.35 562.68 l
58.35 582.93 l
h
W
n
1 1 1 rg
71.85 572.8 m
71.85 570.94 70.34 569.43 68.47 569.43 c
66.61 569.43 65.1 570.94 65.1 572.8 c
65.1 574.67 66.61 576.18 68.47 576.18 c
70.34 576.18 71.85 574.67 71.85 572.8 c
h
f
Q
q
58.35 582.93 m
78.6 582.93 l
78.6 562.68 l
58.35 562.68 l
58.35 582.93 l
h
W
n
0 0 0 rg
68.47 575.43 m
69.92 575.43 71.1 574.25 71.1 572.8 c
71.1 571.36 69.92 570.18 68.47 570.18 c
67.03 570.18 65.85 571.36 65.85 572.8 c
65.85 574.25 67.03 575.43 68.47 575.43 c
h
68.47 576.18 m
66.61 576.18 65.1 574.67 65.1 572.8 c
65.1 570.94 66.61 569.43 68.47 569.43 c
70.34 569.43 71.85 570.94 71.85 572.8 c
71.85 574.67 70.34 576.18 68.47 576.18 c
h
f
Q
Q
BT
/F2 250 Tf
0.03 0 0 0.03 74.85 571.11 Tm
23.08 Tc
( TEXT )Tj
0 Tc
ET
BT
/F2 250 Tf
0.03 0 0 0.03 78 560.04 Tm
23.94 Tc
(TEXT )Tj
0 Tc
ET
BT
/F4 250 Tf
0.03 0 0 0.03 168.51 560.04 Tm
26.34 Tc
(TEXT)Tj
0 Tc
ET
BT
/F2 250 Tf
0.03 0 0 0.03 183.81 560.04 Tm
22.63 Tc
(TEXT)Tj
0 Tc
ET
BT
/F2 250 Tf
0.03 0 0 0.03 78 539.97 Tm
20.99 Tc
(TEXT)Tj
0 Tc
ET
0.37647 0.37647 0.37647 rg
111.57 558.54 m
179.94 558.54 l
178.44 557.04 l
113.07 557.04 l
h
f
0.87843 0.87843 0.87843 rg
178.44 557.04 m
179.94 558.54 l
179.94 530.04 l
178.44 530.79 l
h
f
0.37647 0.37647 0.37647 rg
111.57 558.54 m
113.07 557.04 l
113.07 530.79 l
111.57 530.04 l
h
f
0 0 0 rg
113.07 530.79 m
178.44 530.79 l
179.94 530.04 l
111.57 530.04 l
h
f
1 1 1 rg
113.07 557.04 m
178.44 557.04 l
178.44 530.79 l
113.07 530.79 l
113.07 557.04 l
h
f
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.03 w
2 J
0 j
10 M
[]0 d
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
113.19 551.79 m
173.19 551.79 l
173.19 536.04 l
113.19 536.04 l
113.19 551.79 l
h
W
n
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.75 w
2 J
0 j
10 M
[]0 d
q
113.19 551.79 m
113.19 536.04 l
173.19 536.04 l
173.19 551.79 l
h
W
n
1 1 1 rg
113.19 551.79 m
173.19 551.79 l
173.19 536.04 l
113.19 536.04 l
113.19 551.79 l
h
f
113.19 551.79 m
173.19 551.79 l
173.19 536.04 l
113.19 536.04 l
113.19 551.79 l
h
W
n
q
0 841.89 m
0 0 l
595.29 0 l
595.29 841.89 l
h
W
n
0.75 w
2 J
0 j
10 M
[]0 d
q
113.19 551.79 m
113.19 536.04 l
173.19 536.04 l
173.19 551.79 l
h
W
n
Q
Q
Q
Q
Q
Q
0 0 0 rg
BT
/F2 250 Tf
0.03 0 0 0.03 179.94 539.97 Tm
(TEXT)Tj
ET
BT
/F2 250 Tf
0.03 0 0 0.03 197.04 539.97 Tm
20.99 Tc
(TEXT)Tj
0 Tc
ET
0.37647 0.37647 0.37647 rg
230.61 558.54 m
298.98 558.54 l
297.48 557.04 l
232.11 557.04 l
h
f
0.87843 0.87843 0.87843 rg
297.48 557.04 m
298.98 558.54 l
298.98 530.04 l
297.48 530.79 l
h
f
0.37647 0.37647 0.37647 rg
230.61 558.54 m
232.11 557.04 l
232.11 530.79 l
230.61 530.04 l
h
f
0 0 0 rg
232.11 530.79 m
297.48 530.79 l
298.98 530.04 l
230.61 530.04 l
h
f
<snip!>

1 个答案:

答案 0 :(得分:0)

我想到了这一点,至少对于我正在处理的文件。这不是适用于各种pdf文档的通用解决方案。就我而言,我正在处理一个软件生成的pdf,它总是为复选框和单选按钮生成相同的“图形路径”。因此,我能够在每个页面的内容上使用一些正则表达式:

        private string GetPageContent(PdfReader pdfReader, int page)
        {
            StringBuilder sb = new StringBuilder();

            // from http://www.java2s.com/Open-Source/CSharp/PDF/iTextSharp/iTextSharp/text/pdf/parser/PdfContentReaderTool.cs.htm          
            RandomAccessFileOrArray f = pdfReader.SafeFile;
            byte[] contentBytes = pdfReader.GetPageContent(page, f);
            f.Close();
            foreach (byte b in contentBytes)
                sb.Append((char)b);

            return sb.ToString();
        }

例如,未经检查的单选按钮总是如下所示:

1 1 1 rg
61.35 644.08 m
61.35 642.22 59.84 640.71 57.97 640.71 c
56.11 640.71 54.6 642.22 54.6 644.08 c
54.6 645.95 56.11 647.46 57.97 647.46 c
59.84 647.46 61.35 645.95 61.35 644.08 c
h
f
Q
q
47.85 654.21 m
68.1 654.21 l
68.1 633.96 l
47.85 633.96 l
47.85 654.21 l
h
W
n
0 0 0 rg
57.97 646.71 m
59.42 646.71 60.6 645.53 60.6 644.08 c
60.6 642.64 59.42 641.46 57.97 641.46 c
56.53 641.46 55.35 642.64 55.35 644.08 c
55.35 645.53 56.53 646.71 57.97 646.71 c
h
57.97 647.46 m
56.11 647.46 54.6 645.95 54.6 644.08 c
54.6 642.22 56.11 640.71 57.97 640.71 c
59.84 640.71 61.35 642.22 61.35 644.08 c
61.35 645.95 59.84 647.46 57.97 647.46 c
h
f

3个同心圆,而选中的单选按钮总是有4个同心圆。注释始终遵循同心圆。同样适用于复选框。