Пример #1
0
 /**
  * Add a text field.
  *
  * @param writer the PdfWriter
  * @param rect the position of the text field
  * @param name the name of the text field
  */
 public void addTextField(PdfWriter writer, Rectangle rect, String name) {
   PdfFormField field = PdfFormField.createTextField(writer, false, false, 0);
   field.setFieldName(name);
   field.setWidget(rect, PdfAnnotation.HIGHLIGHT_NONE);
   field.setQuadding(PdfFormField.Q_RIGHT);
   field.setFieldFlags(PdfFormField.FF_READ_ONLY);
   writer.addAnnotation(field);
 }
 public void cellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases) {
   final PdfWriter writer = canvases[0].getPdfWriter();
   final TextField textField = new TextField(writer, rectangle, fieldname);
   try {
     final PdfFormField field = textField.getTextField();
     writer.addAnnotation(field);
   } catch (final IOException ioe) {
     throw new ExceptionConverter(ioe);
   } catch (final DocumentException de) {
     throw new ExceptionConverter(de);
   }
 }
Пример #3
0
 /**
  * Implementation of the cellLayout method.
  *
  * @see com.itextpdf.text.pdf.PdfPCellEvent#cellLayout( com.itextpdf.text.pdf.PdfPCell,
  *     com.itextpdf.text.Rectangle, com.itextpdf.text.pdf.PdfContentByte[])
  */
 public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
   try {
     PdfAnnotation annotation =
         PdfAnnotation.createFileAttachment(
             writer,
             new Rectangle(
                 position.getLeft() - 20,
                 position.getTop() - 15,
                 position.getLeft() - 5,
                 position.getTop() - 5),
             description,
             fs);
     annotation.setName(description);
     writer.addAnnotation(annotation);
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Пример #4
0
 /**
  * Create a pushbutton for a key
  *
  * @param writer the PdfWriter
  * @param rect the position of the key
  * @param btn the label for the key
  * @param script the script to be executed when the button is pushed
  */
 public void addPushButton(PdfWriter writer, Rectangle rect, String btn, String script) {
   float w = rect.getWidth();
   float h = rect.getHeight();
   PdfFormField pushbutton = PdfFormField.createPushButton(writer);
   pushbutton.setFieldName("btn_" + btn);
   pushbutton.setWidget(rect, PdfAnnotation.HIGHLIGHT_PUSH);
   PdfContentByte cb = writer.getDirectContent();
   pushbutton.setAppearance(
       PdfAnnotation.APPEARANCE_NORMAL, createAppearance(cb, btn, BaseColor.GRAY, w, h));
   pushbutton.setAppearance(
       PdfAnnotation.APPEARANCE_ROLLOVER, createAppearance(cb, btn, BaseColor.RED, w, h));
   pushbutton.setAppearance(
       PdfAnnotation.APPEARANCE_DOWN, createAppearance(cb, btn, BaseColor.BLUE, w, h));
   pushbutton.setAdditionalActions(PdfName.U, PdfAction.javaScript(script, writer));
   pushbutton.setAdditionalActions(
       PdfName.E, PdfAction.javaScript("this.showMove('" + btn + "');", writer));
   pushbutton.setAdditionalActions(PdfName.X, PdfAction.javaScript("this.showMove(' ');", writer));
   writer.addAnnotation(pushbutton);
 }