Adding a PDTextAnnotation

Help
y.terziev
2009-01-13
2013-05-28
  • y.terziev

    y.terziev - 2009-01-13

    Hello,

    i am trying to add a PDTextAnnotation to a page and then use the JPodRender to render it. I am doing following:

    public void addTextAnnotation(Point2D p){
            if(page==null)
                return;
           
            //Creates a new Annotation
            PDTextAnnotation annot = (PDTextAnnotation)PDTextAnnotation.META.createNew();
            //Sets an Appearance to the Annotation
           
           
            //Positioning
            Point2D inversePoint = p;
            try {
                inversePoint = imgTransform.inverseTransform(p, null);
            } catch (NoninvertibleTransformException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Float xObj = new Float(inversePoint.getX());
            Float yObj = new Float(inversePoint.getY());
           
            float llx = xObj.floatValue();
            float lly = yObj.floatValue();
            float urx = llx+annot.getDefaultWidth();
            float ury = lly+annot.getDefaultHeight();
            CDSRectangle rect = new CDSRectangle(llx,lly,urx,ury);
           
            annot.setRectangle(rect);
            //Adds the Annotation to the Page
            page.addAnnotation(annot);
            //Updates the model
            updateModel();
        }

    The Problem is, that i don't know how to assign the right Appearance for the PDTextAnnotation.
    Can somebody give any advice how to do this?

    Thanks a lot.

     
    • mtraut

      mtraut - 2009-01-13

      creating an annotation appearance should look something like this:

              // this will create lazy a new appearance but will not assign
              // in a viewer application it is not desirable to change the document upon rendering
              appearance = PDAnnotationTools.getAppearance(annotation);
              // assign the appearance statically
              annotation.setAppearance(appearance);
              PDForm normalForm = PDAppearanceTools.getNormalAppearance(appearance,
                      null);
              creator = CSCreator.createNew(normalForm);

              // ... draw whatever you want...

              creator.close();
              CDSRectangle bbox = annotation.getNormalizedRectangle();
              normalForm.setBoundingBox(bbox);
              CDSMatrix matrix = new CDSMatrix();
              matrix.translate(-bbox.getLowerLeftX(), -bbox.getLowerLeftY());
              normalForm.setMatrix(matrix);

      Drawing the forms content is up to you! The methods in CSCreator should be straightforward.

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks