コード例 #1
0
ファイル: AcroFields.cs プロジェクト: pixelia-es/RazorPDF2
 internal PdfAppearance GetAppearance(PdfDictionary merged, String text, String fieldName)
 {
     topFirst = 0;
     TextField tx = null;
     if (fieldCache == null || !fieldCache.ContainsKey(fieldName)) {
         tx = new TextField(writer, null, null);
         tx.SetExtraMargin(extraMarginLeft, extraMarginTop);
         tx.BorderWidth = 0;
         tx.SubstitutionFonts = substitutionFonts;
         DecodeGenericDictionary(merged, tx);
         //rect
         PdfArray rect = merged.GetAsArray(PdfName.RECT);
         Rectangle box = PdfReader.GetNormalizedRectangle(rect);
         if (tx.Rotation == 90 || tx.Rotation == 270)
             box = box.Rotate();
         tx.Box = box;
         if (fieldCache != null)
             fieldCache[fieldName] = tx;
     }
     else {
         tx = (TextField)fieldCache[fieldName];
         tx.Writer = writer;
     }
     PdfName fieldType = merged.GetAsName(PdfName.FT);
     if (PdfName.TX.Equals(fieldType)) {
         tx.Text = text;
         return tx.GetAppearance();
     }
     if (!PdfName.CH.Equals(fieldType))
         throw new DocumentException("An appearance was requested without a variable text field.");
     PdfArray opt = merged.GetAsArray(PdfName.OPT);
     int flags = 0;
     PdfNumber nfl = merged.GetAsNumber(PdfName.FF);
     if (nfl != null)
         flags = nfl.IntValue;
     if ((flags & PdfFormField.FF_COMBO) != 0 && opt == null) {
         tx.Text = text;
         return tx.GetAppearance();
     }
     if (opt != null) {
         String[] choices = new String[opt.Size];
         String[] choicesExp = new String[opt.Size];
         for (int k = 0; k < opt.Size; ++k) {
             PdfObject obj = opt[k];
             if (obj.IsString()) {
                     choices[k] = choicesExp[k] = ((PdfString)obj).ToUnicodeString();
             }
             else {
                 PdfArray a = (PdfArray) obj;
                 choicesExp[k] = a.GetAsString(0).ToUnicodeString();
                 choices[k] = a.GetAsString(1).ToUnicodeString();
             }
         }
         if ((flags & PdfFormField.FF_COMBO) != 0) {
             for (int k = 0; k < choices.Length; ++k) {
                 if (text.Equals(choicesExp[k])) {
                     text = choices[k];
                     break;
                 }
             }
             tx.Text = text;
             return tx.GetAppearance();
         }
         int idx = 0;
         for (int k = 0; k < choicesExp.Length; ++k) {
             if (text.Equals(choicesExp[k])) {
                 idx = k;
                 break;
             }
         }
         tx.Choices = choices;
         tx.ChoiceExports = choicesExp;
         tx.ChoiceSelection = idx;
     }
     PdfAppearance app = tx.GetListAppearance();
     topFirst = tx.TopFirst;
     return app;
 }
コード例 #2
0
 /** Creates a new event. This constructor will be used if you need to position fields with a Cell Event.
 * @throws DocumentException
 * @throws IOException*/
 public FieldPositioningEvents(PdfWriter writer, PdfFormField parent, String text)
 {
     this.parent = parent;
     TextField tf = new TextField(writer, new Rectangle(0, 0), text);
     tf.FontSize = 14;
     cellField = tf.GetTextField();
 }
コード例 #3
0
 /**
 * @see com.lowagie.text.pdf.PdfPageEvent#onGenericTag(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document, com.lowagie.text.Rectangle, java.lang.String)
 */
 public override void OnGenericTag(PdfWriter writer, Document document,
         Rectangle rect, String text)
 {
     rect.Bottom = rect.Bottom - 3;
     PdfFormField field = (PdfFormField) genericChunkFields[text];
     if (field == null) {
         TextField tf = new TextField(writer, new Rectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding)), text);
         tf.FontSize = 14;
         field = tf.GetTextField();
     }
     else {
         field.Put(PdfName.RECT,  new PdfRectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding)));
     }
     if (parent == null)
         writer.AddAnnotation(field);
     else
         parent.AddKid(field);
 }
コード例 #4
0
 /** Creates a new event. This constructor will be used if you need to position fields with a Cell Event.
 * @throws DocumentException
 * @throws IOException*/
 public FieldPositioningEvents(PdfWriter writer, String text)
 {
     this.fieldWriter = writer;
     TextField tf = new TextField(writer, new Rectangle(0, 0), text);
     tf.FontSize = 14;
     cellField = tf.GetTextField();
 }