Exemple #1
0
 private void addFieldResources(PdfDictionary catalog) throws IOException {
   if (fieldArray == null) return;
   PdfDictionary acroForm = new PdfDictionary();
   catalog.put(PdfName.ACROFORM, acroForm);
   acroForm.put(PdfName.FIELDS, fieldArray);
   acroForm.put(PdfName.DA, new PdfString("/Helv 0 Tf 0 g "));
   if (fieldTemplates.isEmpty()) return;
   PdfDictionary dr = new PdfDictionary();
   acroForm.put(PdfName.DR, dr);
   for (PdfTemplate template : fieldTemplates) {
     PdfFormField.mergeResources(dr, (PdfDictionary) template.getResources());
   }
   // if (dr.get(PdfName.ENCODING) == null) dr.put(PdfName.ENCODING, PdfName.WIN_ANSI_ENCODING);
   PdfDictionary fonts = dr.getAsDict(PdfName.FONT);
   if (fonts == null) {
     fonts = new PdfDictionary();
     dr.put(PdfName.FONT, fonts);
   }
   if (!fonts.contains(PdfName.HELV)) {
     PdfDictionary dic = new PdfDictionary(PdfName.FONT);
     dic.put(PdfName.BASEFONT, PdfName.HELVETICA);
     dic.put(PdfName.ENCODING, PdfName.WIN_ANSI_ENCODING);
     dic.put(PdfName.NAME, PdfName.HELV);
     dic.put(PdfName.SUBTYPE, PdfName.TYPE1);
     fonts.put(PdfName.HELV, addToBody(dic).getIndirectReference());
   }
   if (!fonts.contains(PdfName.ZADB)) {
     PdfDictionary dic = new PdfDictionary(PdfName.FONT);
     dic.put(PdfName.BASEFONT, PdfName.ZAPFDINGBATS);
     dic.put(PdfName.NAME, PdfName.ZADB);
     dic.put(PdfName.SUBTYPE, PdfName.TYPE1);
     fonts.put(PdfName.ZADB, addToBody(dic).getIndirectReference());
   }
 }
 public void setUsed() {
   used = true;
   if (parent != null) put(PdfName.PARENT, parent.getIndirectReference());
   if (kids != null) {
     PdfArray array = new PdfArray();
     for (int k = 0; k < kids.size(); ++k) array.add(kids.get(k).getIndirectReference());
     put(PdfName.KIDS, array);
   }
   if (templates == null) return;
   PdfDictionary dic = new PdfDictionary();
   for (PdfTemplate template : templates) {
     mergeResources(dic, (PdfDictionary) template.getResources());
   }
   put(PdfName.DR, dic);
 }
 /**
  * Constructs a <CODE>PdfFormXObject</CODE>-object.
  *
  * @param template the template
  */
 PdfFormXObject(PdfTemplate template) // throws BadPdfFormatException
     {
   super();
   put(PdfName.TYPE, PdfName.XOBJECT);
   put(PdfName.SUBTYPE, PdfName.FORM);
   put(PdfName.RESOURCES, template.getResources());
   put(PdfName.BBOX, new PdfRectangle(template.getBoundingBox()));
   put(PdfName.FORMTYPE, ONE);
   if (template.getLayer() != null) put(PdfName.OC, template.getLayer().getRef());
   if (template.getGroup() != null) put(PdfName.GROUP, template.getGroup());
   PdfArray matrix = template.getMatrix();
   if (matrix == null) put(PdfName.MATRIX, MATRIX);
   else put(PdfName.MATRIX, matrix);
   bytes = template.toPdf(null);
   put(PdfName.LENGTH, new PdfNumber(bytes.length));
   flateCompress();
 }