2011-11-29 59 views
0

我有一個pdf文檔(由第三方使用RealObjects PDFreactor創建),它是而非表格。我試圖使用iTextSharp從該PDF中提取信息。我能夠提取所有純文本(使用SimpleTextExtractionStrategy),但是有一些信息用單選按鈕表示,這在提取的純文本中不會出現。我是iTextSharp的完全初學者,所以我可能會忽略一些非常簡單的東西。 PdfReader.AcroForm返回null,並且PdfReader.AcroFields.Fields有0個鍵。如何確定整個文檔中單選按鈕和複選框的狀態?這些文件都具有相同的結構,所以我並不需要單選按鈕&被標記;只是有一個項目清單,並知道他們是否被檢查是足夠的。iTextSharp:閱讀單選按鈕,從非形式的複選框狀態PDF

我已確認單選按鈕不僅僅是使用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!> 
+0

您應該鏈接到由第三方軟件創建的**簡單** PDF示例文件。或者在[郵件列表]上提問(https://lists.sourceforge.net/lists/listinfo/itext-questions) – kuujinbo

回答

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個同心圓。註釋總是遵循同心圓。類似的複選框。