Reading PDF Annotations with iText

前端 未结 2 419
Happy的楠姐
Happy的楠姐 2021-02-06 03:56

I trying to get the contents of a PDF annotation to string so I can store that information in a database for searching purposes.

Does anyone know how to accomplish this

2条回答
  •  渐次进展
    2021-02-06 04:26

    Yes, but the specifics really depend on what kind[s] of annotations you're talking about.

    In general:

    PdfDictionary pageDict = myPdfReader.getPageN(firstPageIsOne);
    
    PdfArray annotArray = pageDict.getAsArray(PdfName.ANNOTS);
    
    for (int i = 0; i < annotArray.size(); ++i) {
      PdfDictionary curAnnot = annotArray.getAsDict(i);
    
      int someType = myCodeToGetAnAnnotsType(curAnnot);
      if (someType == THIS_TYPE) {
        writeThisType(curAnnot);
      } else if (someType == THAT_TYPE) {
        writeThatType(curAnnot);
      }
    }
    

    For details, you'll need to examine the PDF Specification, in particular the annotation descriptions: "Chapter 12.5.6 Annotation Types".

    If you can tell us what types you care about, I can be of more help.

提交回复
热议问题