How to read width of line annotation appearance using iTextSharp?

This is due to the previous question that I asked about reading the stream of the appearance of the annotation and writing its text in the Contents . I would like to do a similar action with the Line annotation, reading its appearance width and setting the actual width to match the appearance.

I'm having trouble figuring out how to set my "set text contents using appearance" function to set the line width. This is the code I use to get the text:

//main function for setting inner content to appearance value
public void changeAnnotationContentToAppearance(PdfDictionary dict)
        {

                string surface = pdfTextParser.retrieveText(dict);
                if (surface != null)
                {
                   //update CONTENTS with appearance
                   //for changing line width, I would instead modify the /BS dictionary /W key value, i think
                   dict.Put(PdfName.CONTENTS, new PdfString(surface));
                }
        }

//get text from /AP dictionary
public string retrieveText(PdfDictionary annotDictionary)
    {

        PdfDictionary appearancesDictionary = annotDictionary.GetAsDict(PdfName.AP);
        foreach (PdfName key in appearancesDictionary.Keys)
        {
            PdfStream value = appearancesDictionary.GetAsStream(key);
            if (value != null)
            {
                String text = ExtractAnnotationText(value);
                return text;
            }
        }
        return null;

    }

//read the appearance stream and extract text contents
public String ExtractAnnotationText(PdfStream xObject)
{
    PdfDictionary resources = xObject.GetAsDict(PdfName.RESOURCES);
    ITextExtractionStrategy strategy = new LocationTextExtractionStrategy();

    PdfContentStreamProcessor processor = new PdfContentStreamProcessor(strategy);
    processor.ProcessContent(ContentByteUtils.GetContentBytesFromContentObject(xObject), resources);
    return strategy.GetResultantText();
}

ExtractAnnotationText()only seems able to read text, not line width, because it ITextExtractionStrategy()does not have methods to return line properties. Does iTextSharp offer a different mining strategy for use in line operations?

, , , , , , .

EDIT: , . , , , : , .

+4
2

PathRenderInfo . PathRenderInfo iText 7. , :

public static void main(String args[]) throws IOException {
    PdfDocument document = new PdfDocument(new PdfReader(SRC));
    PdfPage page = document.getPage(1);
    PdfCanvasProcessor processor = new PdfCanvasProcessor(new IEventListener() {
        public void eventOccurred(IEventData data, EventType type) {
            if (type == EventType.RENDER_PATH) {
                PathRenderInfo renderinfo = (PathRenderInfo) data;
                int i = renderinfo.getOperation();
                switch (i) {
                    case 1:
                        System.out.print("Stroke: ");
                        break;
                    case 2:
                        System.out.print("Fill: ");
                        break;
                    default:
                        System.out.print("No: ");
                }
                for (Subpath p : renderinfo.getPath().getSubpaths()) {
                    for (IShape shape : p.getSegments()) {
                        for (Point point : shape.getBasePoints()) {
                            System.out.println(String.format("x = %s; y = %s", point.getX(), point.getY()));
                        }
                    }
                }
            }
        }
        public Set<EventType> getSupportedEvents() {
            return null;
        }
    });
    processor.processPageContent(page);
}

PDF , () :

Stroke: x = -406.0; y = -240.0
x = 406.0; y = -240.0
x = -406.0; y = -200.0
x = 406.0; y = -200.0
x = -406.0; y = -160.0
x = 406.0; y = -160.0
x = -406.0; y = -120.0
x = 406.0; y = -120.0
x = -406.0; y = -80.0
x = 406.0; y = -80.0
x = -406.0; y = -40.0
x = 406.0; y = -40.0
x = -406.0; y = 0.0
x = 406.0; y = 0.0
x = -406.0; y = 40.0
x = 406.0; y = 40.0
x = -406.0; y = 80.0

iText 7, , , PathRenderInfo, Subpath IShape.

Update:

, , . :

enter image description here

PDF-, :

enter image description here

, :

  • /C: : = 0, = 0, = 1 (, )
  • /LE: ( : )
  • L: (x = 20, y = 790) (x = 575, y = 790)
  • ...

, ?

. /Rect. ([0 0 0 0]), , , /L.

+2

@Bruno

.

(, , ),... . PDF , Foxit Adobe.

, PDF . , ,

  • ,
  • ,
  • , ,
  • ,
  • ,
  • ...
  • ...

, - .

, , . . , , , , , , ,...


, , , , Foxit, , , , , .

, . , - .

, iTextSharp 5.5.x IExtRenderListener iTextSharp 7.0.x IEventListener.

+2

All Articles