This articles shows you how to create and edit Annotations in a PDF file using the JPedal Swing Viewer. If you are looking to do this directly in Java code, we recommend this article.
In the JPedal Java PDF Library, we have implemented features allowing you to create and edit annotations on your PDF files in the Viewer. Here is a quick summary of how it works:
Creating annotations
We have added a new tab to the sidebar, labelled “Annotations”. From here, you can select a variety of annotation types to add to your PDF. Most require a simple click and drag/move, but each button has a helpful tool-tip if you are unsure on what to do.
After selecting an annotation type, the cursor will change to a crosshair when you move your mouse over the page (or if using the highlight tool, an I-cursor when over un-highlighted text). You are now free to start drawing!
Editing annotations
To select an existing annotation, simply left-click anywhere over it. You will know if it is selected – there will now be a fancy border around it and tabs around the edges for resizing the annotation.
To move annotations, simply click and hold anywhere on one, then drag it wherever you please on the page. Additionally, resizing is just as easy – click and drag one of the tabs around the edge of the annotation.
For more in-depth customisation, right-clicking an annotation will open a context menu from which you can select “properties”. This will open the properties window, where you can edit the line width, line colour and fill colour (where these options are supported) to your heart’s content – just click on an option to change it.
Of course, we are not stopping here – we already have plans to add more annotation types and features in the near future.
Is there anything you would like to see in the next annotations update? Let us know in the comments below.
The JPedal PDF library allows you to solve these problems in Java
Viewer viewer = new Viewer();
viewer.setupViewer();
viewer.executeCommand(ViewerCommands.OPENFILE, "pdfFile.pdf");
//Convenience static method (see class for additional options)
ExtractClippedImages.writeAllClippedImagesToDir("inputFileOrDirectory", "outputDir", "outputImageFormat", new String[] {"imageHeightAsFloat", "subDirectoryForHeight"});
//Convenience static method (see class for additional options)
ExtractTextAsWordList.writeAllWordlistsToDir("inputFileOrDirectory", "outputDir", -1);
//Convenience static method (see class for additional options)
ArrayList resultsForPages = FindTextInRectangle.findTextOnAllPages("/path/to/file.pdf", "textToFind");
PrintPdfPages print = new PrintPdfPages("C:/pdfs/mypdf.pdf");
if (print.openPDFFile()) {
print.printAllPages("Printer Name");
}
//Convenience static method (see class for additional options)
ExtractClippedImages.writeAllClippedImagesToDir("inputFileOrDirectory", "outputDir", "outputImageFormat", new String[] {"imageHeightAsFloat", "subDirectoryForHeight"});
Why do developers choose JPedal over alternatives?
- Actively developed commercial library with full support and no third party dependencies.
- Simple licensing options and source code access for OEM users.
- Process PDF files up to 3x faster than alternative Java PDF libraries.