Пример #1
0
 /**
  * Creates a PDF document.
  *
  * @param filename the path to the new PDF document
  * @throws DocumentException
  * @throws IOException
  */
 public void createPdf(String filename) throws IOException, DocumentException {
   // step 1
   Document document = new Document(new Rectangle(360, 360));
   // step 2
   PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
   // step 3
   document.open();
   writer.addJavaScript(Utilities.readFileToString(RESOURCE));
   // step 4
   // add the keys for the digits
   for (int i = 0; i < 10; i++) {
     addPushButton(writer, digits[i], String.valueOf(i), "this.augment(" + i + ")");
   }
   // add the keys for the operators
   addPushButton(writer, plus, "+", "this.register('+')");
   addPushButton(writer, minus, "-", "this.register('-')");
   addPushButton(writer, mult, "x", "this.register('*')");
   addPushButton(writer, div, ":", "this.register('/')");
   addPushButton(writer, equals, "=", "this.calculateResult()");
   // add the other keys
   addPushButton(writer, clearEntry, "CE", "this.reset(false)");
   addPushButton(writer, clear, "C", "this.reset(true)");
   addTextField(writer, result, "result");
   addTextField(writer, move, "move");
   // step 5
   document.close();
 }