0

Hi I found this example of pdfbox using annotation:

https://svn.apache.org/repos/asf/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddAnnotations.java

When I try to run it in netbeans, nothing happens except to print in output:

Usage: add_annotation_exp1.Add_annotation_exp1$AddAnnotations

Not sure what I am doing wrong

mkl
  • 90,588
  • 15
  • 125
  • 265
gerry
  • 29
  • 4
  • Add program argument "test.pdf" as a program argument. If not sure how to set it up see https://stackoverflow.com/questions/9168759/netbeans-how-to-set-command-line-arguments-in-java – rgrebski Jul 02 '17 at 09:01
  • I now get: Target ""test.pdf"" does not exist in the project "{0} (run)". – gerry Jul 02 '17 at 09:43
  • OK. I understand a little more. The reason it will not run is down to this: if (args.length != 1) { System.err.println("Usage: " + AddAnnotations.class.getName() + " "); System.exit(1); } how and why do I make args.length = 1 ? – gerry Jul 02 '17 at 11:32
  • when I now pass it "test.pdf" as an argument it says: Target "test.pdf" does not exist in the project "{0} (run)" – gerry Jul 02 '17 at 14:03
  • You appear to pass "test.pdf" as an argument of the **build process**, not of the execution of the program itself. So this effectively is a question concerning how to use [tag:netbeans]. – mkl Jul 03 '17 at 04:15

1 Answers1

0

There are two possible solutions (based on Netbeans 8.2):

1) In the main method, add this at the beginning: args = new String[]{"c:/path/filename.pdf"}; and then build the subproject and then press SHIFT F6 to run, or right-click in the editor pane and choose "Run File". (If the subproject is open then you can skip the build step)

2) Go to the subproject properties (right-click on the left pane on "Apache PDFBox examples"), "Properties". A dialog box will appear. Choose "run" in the left pane. In the field "Main Class" enter org.apache.pdfbox.examples.pdmodel.AddAnnotations (or use the "Browse..." button), and in the field "Arguments" enter your file name with the path. Use quotes if there are spaces in the path. Then run by clicking the right mouse key on the subproject and choose "Run".

Tilman Hausherr
  • 17,731
  • 7
  • 58
  • 97