JPedal Support

The Ultimate Java PDF Library SDK

Download Trial Purchase

This topic contains 8 replies, has 2 voices, and was last updated by  Kieran France 4 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
  • #3569

    BK Santiago

    JPedal’s PDF Viewer currently supports adding of annotations then saving a copy via File -> Save As.

    Can we do this programmatically? Do you think we can use SaveFile.saveAsPdf(File file, final GUIFactory guiFactory, Values commonValues) function and just send an arbitrary value with annotations included on the GUIAnnotationPanel?

    I haven’t tried this yet, so I would like to ask your opinion on this if it might not be possible due to some dependencies etc.. If there’s already an existing function for this, let me know.



    Kieran France

    I would not suggest using code from SaveFile.saveAsPdf as it contains additional steps you would not need if you are just adding annotations to a document. Instead I recommend the following.

    Adding annotations can be done programmatically using the AnnotationWriter.writeAnnotations(File, File, WritableAnnotation[]).

    This static method accepts two File objects, the first is the input file and the second is the output.
    The final variable is an array of WritableAnnotation which represent the annotations you wish to add to the document.

    WritableAnnotation is a abstract lass that is extended by the classes in such as CircleAnnotation, SquareAnnotation and the other classes ending in Annotation.

    Each of these classes has two constructors depending on your needs.

    The first constructor allows you to pass in some basic details for the annotation and covers the basics for the annotation.

    The second constructor also accepts a FormObject as an input, the FormObject can contain much more detailed information about the annotation but requires much more in depth knowledge of the values used by annotations in the pdf spec.

    For instance, the following would add two annotations, a square to page one at coordinates 10, 10, 100, 100 and a circle to page two at coordinates 10, 10, 100, 100.

    WritableAnnotation[] annotations = new WritableAnnotation[2];
    annotations[0] = new SquareAnnotation(1, 10, 10, 100, 100);
    annotations[1] = new CircleAnnotation(2, 10, 10, 100, 100);
    AnnotationWriter.writeAnnotations(inputFile, outputFile, annotation);

    Kieran France

    The JavaDoc for AnnotationWriter can also be found here with an example that creates one of each of the support annotation types.


    BK Santiago

    Thank you all for your response.

    I’ll update once I encounter any problem with the suggested approach.


    BK Santiago

    How about encrypted PDFs? It might be better if AnnotationWriter accepts another param which contains PDF passwords rather than just file


    BK Santiago

    Hi Kieran,

    You above example doesn’t work. Null pointer in saveAnnotationObjects when calling getAPString.

    Looks like we really need to study PDF specs and use the 2nd param which accepts a FormObject for this to work.


    Kieran France

    Unfortunately we currently do not save annotations to encrypted files.

    The null pointer you mentioned has been fixed and will be in the monthly release later today.


    BK Santiago

    HI Kieran,

    I tried the monthly release build today but I still get nullpointer in other parts.

    Got the error from line 191 final AnnotOREF page = info.pageOffsets[pageNum], info can’t be null so I think the pageOffsets array is the null one.


    Kieran France

    I have not seen this issue when running the example code.

    Could you submit a bug report with the code you are using, an example file and any additional instructions / properties required to replicate the issue.

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.