Esempio n. 1
0
 public void DecodeGenericDictionary(PdfDictionary merged, BaseField tx)
 {
     int flags = 0;
     // the text size and color
     PdfString da = merged.GetAsString(PdfName.DA);
     if (da != null) {
         Object[] dab = SplitDAelements(da.ToUnicodeString());
         if (dab[DA_SIZE] != null)
             tx.FontSize = (float)dab[DA_SIZE];
         if (dab[DA_COLOR] != null)
             tx.TextColor = (Color)dab[DA_COLOR];
         if (dab[DA_FONT] != null) {
             PdfDictionary font = merged.GetAsDict(PdfName.DR);
             if (font != null) {
                 font = font.GetAsDict(PdfName.FONT);
                 if (font != null) {
                     PdfObject po = font.Get(new PdfName((String)dab[DA_FONT]));
                     if (po != null && po.Type == PdfObject.INDIRECT) {
                         PRIndirectReference por = (PRIndirectReference)po;
                         BaseFont bp = new DocumentFont((PRIndirectReference)po);
                         tx.Font = bp;
                         int porkey = por.Number;
                         BaseFont porf = (BaseFont)extensionFonts[porkey];
                         if (porf == null) {
                             if (!extensionFonts.ContainsKey(porkey)) {
                                 PdfDictionary fo = (PdfDictionary)PdfReader.GetPdfObject(po);
                                 PdfDictionary fd = fo.GetAsDict(PdfName.FONTDESCRIPTOR);
                                 if (fd != null) {
                                     PRStream prs = (PRStream)PdfReader.GetPdfObject(fd.Get(PdfName.FONTFILE2));
                                     if (prs == null)
                                         prs = (PRStream)PdfReader.GetPdfObject(fd.Get(PdfName.FONTFILE3));
                                     if (prs == null) {
                                         extensionFonts[porkey] = null;
                                     }
                                     else {
                                         try {
                                             porf = BaseFont.CreateFont("font.ttf", BaseFont.IDENTITY_H, true, false, PdfReader.GetStreamBytes(prs), null);
                                         }
                                         catch {
                                         }
                                         extensionFonts[porkey] = porf;
                                     }
                                 }
                             }
                         }
                         if (tx is TextField)
                             ((TextField)tx).ExtensionFont = porf;
                     }
                     else {
                         BaseFont bf = (BaseFont)localFonts[dab[DA_FONT]];
                         if (bf == null) {
                             String[] fn = (String[])stdFieldFontNames[dab[DA_FONT]];
                             if (fn != null) {
                                 try {
                                     String enc = "winansi";
                                     if (fn.Length > 1)
                                         enc = fn[1];
                                     bf = BaseFont.CreateFont(fn[0], enc, false);
                                     tx.Font = bf;
                                 }
                                 catch {
                                     // empty
                                 }
                             }
                         }
                         else
                             tx.Font = bf;
                     }
                 }
             }
         }
     }
     //rotation, border and backgound color
     PdfDictionary mk = merged.GetAsDict(PdfName.MK);
     if (mk != null) {
         PdfArray ar = mk.GetAsArray(PdfName.BC);
         Color border = GetMKColor(ar);
         tx.BorderColor = border;
         if (border != null)
             tx.BorderWidth = 1;
         ar = mk.GetAsArray(PdfName.BG);
         tx.BackgroundColor = GetMKColor(ar);
         PdfNumber rotation = mk.GetAsNumber(PdfName.R);
         if (rotation != null)
             tx.Rotation = rotation.IntValue;
     }
     //flags
     PdfNumber nfl = merged.GetAsNumber(PdfName.F);
     flags = 0;
     tx.Visibility = BaseField.VISIBLE_BUT_DOES_NOT_PRINT;
     if (nfl != null) {
         flags = nfl.IntValue;
         if ((flags & PdfFormField.FLAGS_PRINT) != 0 && (flags & PdfFormField.FLAGS_HIDDEN) != 0)
             tx.Visibility = BaseField.HIDDEN;
         else if ((flags & PdfFormField.FLAGS_PRINT) != 0 && (flags & PdfFormField.FLAGS_NOVIEW) != 0)
             tx.Visibility = BaseField.HIDDEN_BUT_PRINTABLE;
         else if ((flags & PdfFormField.FLAGS_PRINT) != 0)
             tx.Visibility = BaseField.VISIBLE;
     }
     //multiline
     nfl = merged.GetAsNumber(PdfName.FF);
     flags = 0;
     if (nfl != null)
         flags = nfl.IntValue;
     tx.Options = flags;
     if ((flags & PdfFormField.FF_COMB) != 0) {
         PdfNumber maxLen = merged.GetAsNumber(PdfName.MAXLEN);
         int len = 0;
         if (maxLen != null)
             len = maxLen.IntValue;
         tx.MaxCharacterLength = len;
     }
     //alignment
     nfl = merged.GetAsNumber(PdfName.Q);
     if (nfl != null) {
         if (nfl.IntValue == PdfFormField.Q_CENTER)
             tx.Alignment = Element.ALIGN_CENTER;
         else if (nfl.IntValue == PdfFormField.Q_RIGHT)
             tx.Alignment = Element.ALIGN_RIGHT;
     }
     //border styles
     PdfDictionary bs = merged.GetAsDict(PdfName.BS);
     if (bs != null) {
         PdfNumber w = bs.GetAsNumber(PdfName.W);
         if (w != null)
             tx.BorderWidth = w.FloatValue;
         PdfName s = bs.GetAsName(PdfName.S);
         if (PdfName.D.Equals(s))
             tx.BorderStyle = PdfBorderDictionary.STYLE_DASHED;
         else if (PdfName.B.Equals(s))
             tx.BorderStyle = PdfBorderDictionary.STYLE_BEVELED;
         else if (PdfName.I.Equals(s))
             tx.BorderStyle = PdfBorderDictionary.STYLE_INSET;
         else if (PdfName.U.Equals(s))
             tx.BorderStyle = PdfBorderDictionary.STYLE_UNDERLINE;
     }
     else {
         PdfArray bd = merged.GetAsArray(PdfName.BORDER);
         if (bd != null) {
             if (bd.Size >= 3)
                 tx.BorderWidth = bd.GetAsNumber(2).FloatValue;
             if (bd.Size >= 4)
                 tx.BorderStyle = PdfBorderDictionary.STYLE_DASHED;
         }
     }
 }
Esempio n. 2
0
 internal bool IsInAP(PdfDictionary dic, PdfName check)
 {
     PdfDictionary appDic = dic.GetAsDict(PdfName.AP);
     if (appDic == null)
         return false;
     PdfDictionary NDic = appDic.GetAsDict(PdfName.N);
     return (NDic != null && NDic.Get(check) != null);
 }
Esempio n. 3
0
 internal static void MergeResources(PdfDictionary result, PdfDictionary source, PdfStamperImp writer)
 {
     PdfDictionary dic = null;
     PdfDictionary res = null;
     PdfName target = null;
     for (int k = 0; k < mergeTarget.Length; ++k) {
         target = mergeTarget[k];
         PdfDictionary pdfDict = source.GetAsDict(target);
         if ((dic = pdfDict) != null) {
             if ((res = (PdfDictionary)PdfReader.GetPdfObject(result.Get(target), result)) == null) {
                 res = new PdfDictionary();
             }
             res.MergeDifferent(dic);
             result.Put(target, res);
             if (writer != null)
                 writer.MarkUsed(res);
         }
     }
 }
Esempio n. 4
0
 private void AddFieldResources(PdfDictionary catalog)
 {
     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.Count == 0)
         return;
     PdfDictionary dr = new PdfDictionary();
     acroForm.Put(PdfName.DR, dr);
     foreach (PdfTemplate template in fieldTemplates.Keys) {
         PdfFormField.MergeResources(dr, (PdfDictionary)template.Resources);
     }
     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).IndirectReference);
     }
     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).IndirectReference);
     }
 }
Esempio n. 5
0
 internal PageStamp(PdfStamperImp stamper, PdfReader reader, PdfDictionary pageN)
 {
     this.pageN = pageN;
     pageResources = new PageResources();
     PdfDictionary resources = pageN.GetAsDict(PdfName.RESOURCES);
     pageResources.SetOriginalResources(resources, stamper.namePtr);
 }