/**
 * Creates a new instance of PdfStructureElement.
 * @param parent the parent of this node
 * @param structureType the type of structure. It may be a standard type or a user type mapped by the role map
 */
 public PdfStructureElement(PdfStructureElement parent, PdfName structureType)
 {
     top = parent.top;
     Init(parent, structureType);
     this.parent = parent;
     Put(PdfName.P, parent.reference);
 }
Esempio n. 2
0
 static PdfAppearance()
 {
     stdFieldFontNames["Courier-BoldOblique"] = new PdfName("CoBO");
     stdFieldFontNames["Courier-Bold"] = new PdfName("CoBo");
     stdFieldFontNames["Courier-Oblique"] = new PdfName("CoOb");
     stdFieldFontNames["Courier"] = new PdfName("Cour");
     stdFieldFontNames["Helvetica-BoldOblique"] = new PdfName("HeBO");
     stdFieldFontNames["Helvetica-Bold"] = new PdfName("HeBo");
     stdFieldFontNames["Helvetica-Oblique"] = new PdfName("HeOb");
     stdFieldFontNames["Helvetica"] = PdfName.HELV;
     stdFieldFontNames["Symbol"] = new PdfName("Symb");
     stdFieldFontNames["Times-BoldItalic"] = new PdfName("TiBI");
     stdFieldFontNames["Times-Bold"] = new PdfName("TiBo");
     stdFieldFontNames["Times-Italic"] = new PdfName("TiIt");
     stdFieldFontNames["Times-Roman"] = new PdfName("TiRo");
     stdFieldFontNames["ZapfDingbats"] = PdfName.ZADB;
     stdFieldFontNames["HYSMyeongJo-Medium"] = new PdfName("HySm");
     stdFieldFontNames["HYGoThic-Medium"] = new PdfName("HyGo");
     stdFieldFontNames["HeiseiKakuGo-W5"] = new PdfName("KaGo");
     stdFieldFontNames["HeiseiMin-W3"] = new PdfName("KaMi");
     stdFieldFontNames["MHei-Medium"] = new PdfName("MHei");
     stdFieldFontNames["MSung-Light"] = new PdfName("MSun");
     stdFieldFontNames["STSong-Light"] = new PdfName("STSo");
     stdFieldFontNames["MSungStd-Light"] = new PdfName("MSun");
     stdFieldFontNames["STSongStd-Light"] = new PdfName("STSo");
     stdFieldFontNames["HYSMyeongJoStd-Medium"] = new PdfName("HySm");
     stdFieldFontNames["KozMinPro-Regular"] = new PdfName("KaMi");
 }
Esempio n. 3
0
 // methods
 internal void Add(PdfName key, PdfDictionary resource)
 {
     if (resource.Size == 0)
         return;
     PdfDictionary dic = GetAsDict(key);
     if (dic == null)
         Put(key, resource);
     else
         dic.Merge(resource);
 }
Esempio n. 4
0
 public void SetAdditionalActions(PdfName key, PdfAction action)
 {
     PdfDictionary dic;
     PdfObject obj = Get(PdfName.AA);
     if (obj != null && obj.IsDictionary())
         dic = (PdfDictionary)obj;
     else
         dic = new PdfDictionary();
     dic.Put(key, action);
     Put(PdfName.AA, dic);
 }
Esempio n. 5
0
 /**
 * Adds a template to the document but not to the page resources.
 * @param template the template to add
 * @param forcedName the template name, rather than a generated one. Can be null
 * @return the <CODE>PdfName</CODE> for this template
 */
 internal PdfName AddDirectTemplateSimple(PdfTemplate template, PdfName forcedName)
 {
     PdfIndirectReference refa = template.IndirectReference;
     Object[] obj = (Object[])formXObjects[refa];
     PdfName name = null;
     if (obj == null) {
         if (forcedName == null) {
             name = new PdfName("Xf" + formXObjectsCounter);
             ++formXObjectsCounter;
         }
         else
             name = forcedName;
         if (template.Type == PdfTemplate.TYPE_IMPORTED) {
             // If we got here from PdfCopy we'll have to fill importedPages
             PdfImportedPage ip = (PdfImportedPage)template;
             PdfReader r = ip.PdfReaderInstance.Reader;
             if (!importedPages.ContainsKey(r)) {
                 importedPages[r] = ip.PdfReaderInstance;
             }
             template = null;
         }
         formXObjects[refa] = new Object[]{name, template};
     }
     else
         name = (PdfName)obj[0];
     return name;
 }
Esempio n. 6
0
 /**
 * @see com.lowagie.text.pdf.interfaces.PdfVersion#setPdfVersion(com.lowagie.text.pdf.PdfName)
 */
 public void SetPdfVersion(PdfName version)
 {
     if (catalog_version == null || catalog_version.CompareTo(version) < 0) {
         this.catalog_version = version;
     }
 }
Esempio n. 7
0
 /** Creates new PdfSignature */
 public PdfSignature(PdfName filter, PdfName subFilter)
     : base(PdfName.SIG)
 {
     Put(PdfName.FILTER, filter);
     Put(PdfName.SUBFILTER, subFilter);
 }
Esempio n. 8
0
 /** Sets the field value and the display string. The display string
 * is used to build the appearance in the cases where the value
 * is modified by Acrobat with JavaScript and the algorithm is
 * known.
 * @param name the fully qualified field name or the partial name in the case of XFA forms
 * @param value the field value
 * @param display the string that is used for the appearance. If <CODE>null</CODE>
 * the <CODE>value</CODE> parameter will be used
 * @return <CODE>true</CODE> if the field was found and changed,
 * <CODE>false</CODE> otherwise
 * @throws IOException on error
 * @throws DocumentException on error
 */
 public bool SetField(String name, String value, String display)
 {
     if (writer == null)
         throw new DocumentException("This AcroFields instance is read-only.");
     if (xfa.XfaPresent) {
         name = xfa.FindFieldName(name, this);
         if (name == null)
             return false;
         String shortName = XfaForm.Xml2Som.GetShortName(name);
         XmlNode xn = xfa.FindDatasetsNode(shortName);
         if (xn == null) {
             xn = xfa.DatasetsSom.InsertNode(xfa.DatasetsNode, shortName);
         }
         xfa.SetNodeText(xn, value);
     }
     Item item = (Item)fields[name];
     if (item == null)
         return false;
     PdfDictionary merged = item.GetMerged( 0 );
     PdfName type = merged.GetAsName(PdfName.FT);
     if (PdfName.TX.Equals(type)) {
         PdfNumber maxLen = merged.GetAsNumber(PdfName.MAXLEN);
         int len = 0;
         if (maxLen != null)
             len = maxLen.IntValue;
         if (len > 0)
             value = value.Substring(0, Math.Min(len, value.Length));
     }
     if (display == null)
         display = value;
     if (PdfName.TX.Equals(type) || PdfName.CH.Equals(type)) {
         PdfString v = new PdfString(value, PdfObject.TEXT_UNICODE);
         for (int idx = 0; idx < item.Size; ++idx) {
             PdfDictionary valueDic = item.GetValue(idx);
             valueDic.Put(PdfName.V, v);
             valueDic.Remove(PdfName.I);
             MarkUsed(valueDic);
             merged = item.GetMerged(idx);
             merged.Remove(PdfName.I);
             merged.Put(PdfName.V, v);
             PdfDictionary widget = item.GetWidget(idx);
             if (generateAppearances) {
                 PdfAppearance app = GetAppearance(merged, display, name);
                 if (PdfName.CH.Equals(type)) {
                     PdfNumber n = new PdfNumber(topFirst);
                     widget.Put(PdfName.TI, n);
                     merged.Put(PdfName.TI, n);
                 }
                 PdfDictionary appDic = widget.GetAsDict(PdfName.AP);
                 if (appDic == null) {
                     appDic = new PdfDictionary();
                     widget.Put(PdfName.AP, appDic);
                     merged.Put(PdfName.AP, appDic);
                 }
                 appDic.Put(PdfName.N, app.IndirectReference);
                 writer.ReleaseTemplate(app);
             }
             else {
                 widget.Remove(PdfName.AP);
                 merged.Remove(PdfName.AP);
             }
             MarkUsed(widget);
         }
         return true;
     }
     else if (PdfName.BTN.Equals(type)) {
         PdfNumber ff = item.GetMerged(0).GetAsNumber(PdfName.FF);
         int flags = 0;
         if (ff != null)
             flags = ff.IntValue;
         if ((flags & PdfFormField.FF_PUSHBUTTON) != 0) {
             //we'll assume that the value is an image in base64
             Image img;
             try {
                 img = Image.GetInstance(Convert.FromBase64String(value));
             }
             catch {
                 return false;
             }
             PushbuttonField pb = GetNewPushbuttonFromField(name);
             pb.Image = img;
             ReplacePushbuttonField(name, pb.Field);
             return true;
         }
         PdfName v = new PdfName(value);
         ArrayList lopt = new ArrayList();
         PdfArray opts = item.GetValue(0).GetAsArray(PdfName.OPT);
         if (opts != null) {
             for (int k = 0; k < opts.Size; ++k) {
                 PdfString valStr = opts.GetAsString(k);
                 if (valStr != null)
                     lopt.Add(valStr.ToUnicodeString());
                 else
                     lopt.Add(null);
             }
         }
         int vidx = lopt.IndexOf(value);
         PdfName valt = null;
         PdfName vt;
         if (vidx >= 0) {
             vt = valt = new PdfName(vidx.ToString());
         }
         else
             vt = v;
         for (int idx = 0; idx < item.Size; ++idx) {
             merged = item.GetMerged(idx);
             PdfDictionary widget = item.GetWidget(idx);
             PdfDictionary valDict = item.GetValue(idx);
             MarkUsed(item.GetValue(idx));
             if (valt != null) {
                 PdfString ps = new PdfString(value, PdfObject.TEXT_UNICODE);
                 valDict.Put(PdfName.V, ps);
                 merged.Put(PdfName.V, ps);
             }
             else {
                 valDict.Put(PdfName.V, v);
                 merged.Put(PdfName.V, v);
             }
             MarkUsed(widget);
             if (IsInAP(widget,  vt)) {
                 merged.Put(PdfName.AS, vt);
                 widget.Put(PdfName.AS, vt);
             }
             else {
                 merged.Put(PdfName.AS, PdfName.Off_);
                 widget.Put(PdfName.AS, PdfName.Off_);
             }
         }
         return true;
     }
     return false;
 }
Esempio n. 9
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);
 }
 public static PdfDictionary OutputNamedDestinationAsNames(Hashtable names, PdfWriter writer)
 {
     PdfDictionary dic = new PdfDictionary();
     foreach (String key in names.Keys) {
         try {
             String value = (String)names[key];
             PdfArray ar = CreateDestinationArray(value, writer);
             PdfName kn = new PdfName(key);
             dic.Put(kn, ar);
         }
         catch {
             // empty on purpose
         }
     }
     return dic;
 }
Esempio n. 11
0
 private static String GetNameString(PdfDictionary dic, PdfName key)
 {
     PdfObject obj = PdfReader.GetPdfObject(dic.Get(key));
     if (obj == null || !obj.IsString())
         return null;
     return ((PdfString)obj).ToUnicodeString();
 }
Esempio n. 12
0
 public void SetMKIconFit(PdfName scale, PdfName scalingType, float leftoverLeft, float leftoverBottom, bool fitInBounds)
 {
     PdfDictionary dic = new PdfDictionary();
     if (!scale.Equals(PdfName.A))
         dic.Put(PdfName.SW, scale);
     if (!scalingType.Equals(PdfName.P))
         dic.Put(PdfName.S, scalingType);
     if (leftoverLeft != 0.5f || leftoverBottom != 0.5f) {
         PdfArray array = new PdfArray(new PdfNumber(leftoverLeft));
         array.Add(new PdfNumber(leftoverBottom));
         dic.Put(PdfName.A, array);
     }
     if (fitInBounds)
         dic.Put(PdfName.FB, PdfBoolean.PDFTRUE);
     MK.Put(PdfName.IF, dic);
 }
Esempio n. 13
0
 protected static PdfAnnotation CreateLink(PdfWriter writer, Rectangle rect, PdfName highlight)
 {
     PdfAnnotation annot = new PdfAnnotation(writer, rect);
     annot.Put(PdfName.SUBTYPE, PdfName.LINK);
     if (!highlight.Equals(HIGHLIGHT_INVERT))
         annot.Put(PdfName.H, highlight);
     return annot;
 }
Esempio n. 14
0
 /**
 * Sets the annotation's highlighting mode. The values can be
 * <CODE>HIGHLIGHT_NONE</CODE>, <CODE>HIGHLIGHT_INVERT</CODE>,
 * <CODE>HIGHLIGHT_OUTLINE</CODE> and <CODE>HIGHLIGHT_PUSH</CODE>;
 * @param highlight the annotation's highlighting mode
 */
 public void SetHighlighting(PdfName highlight)
 {
     if (highlight.Equals(HIGHLIGHT_INVERT))
         Remove(PdfName.H);
     else
         Put(PdfName.H, highlight);
 }
Esempio n. 15
0
        public void SetAppearance(PdfName ap, string state, PdfTemplate template)
        {
            PdfDictionary dicAp = (PdfDictionary)Get(PdfName.AP);
            if (dicAp == null)
                dicAp = new PdfDictionary();

            PdfDictionary dic;
            PdfObject obj = dicAp.Get(ap);
            if (obj != null && obj.IsDictionary())
                dic = (PdfDictionary)obj;
            else
                dic = new PdfDictionary();
            dic.Put(new PdfName(state), template.IndirectReference);
            dicAp.Put(ap, dic);
            Put(PdfName.AP, dicAp);
            if (!form)
                return;
            if (templates == null)
                templates = new Hashtable();
            templates[template] = null;
        }
Esempio n. 16
0
 public void SetAppearance(PdfName ap, PdfTemplate template)
 {
     PdfDictionary dic = (PdfDictionary)Get(PdfName.AP);
     if (dic == null)
         dic = new PdfDictionary();
     dic.Put(ap, template.IndirectReference);
     Put(PdfName.AP, dic);
     if (!form)
         return;
     if (templates == null)
         templates = new Hashtable();
     templates[template] = null;
 }
Esempio n. 17
0
 internal PdfName AddSimplePattern(PdfPatternPainter painter)
 {
     PdfName name = (PdfName)documentPatterns[painter];
     if ( name == null ) {
         name = new PdfName("P" + patternNumber);
         ++patternNumber;
         documentPatterns[painter] = name;
     }
     return name;
 }
Esempio n. 18
0
 /**
 * Adds an image to the document but not to the page resources. It is used with
 * templates and <CODE>Document.Add(Image)</CODE>.
 * @param image the <CODE>Image</CODE> to add
 * @param fixedRef the reference to used. It may be <CODE>null</CODE>,
 * a <CODE>PdfIndirectReference</CODE> or a <CODE>PRIndirectReference</CODE>.
 * @return the name of the image added
 * @throws PdfException on error
 * @throws DocumentException on error
 */
 public PdfName AddDirectImageSimple(Image image, PdfIndirectReference fixedRef)
 {
     PdfName name;
     // if the images is already added, just retrieve the name
     if (images.ContainsKey(image.MySerialId)) {
         name = (PdfName) images[image.MySerialId];
     }
     // if it's a new image, add it to the document
     else {
         if (image.IsImgTemplate()) {
             name = new PdfName("img" + images.Count);
             if (image is ImgWMF){
                 ImgWMF wmf = (ImgWMF)image;
                 wmf.ReadWMF(PdfTemplate.CreateTemplate(this, 0, 0));
             }
         }
         else {
             PdfIndirectReference dref = image.DirectReference;
             if (dref != null) {
                 PdfName rname = new PdfName("img" + images.Count);
                 images[image.MySerialId] = rname;
                 imageDictionary.Put(rname, dref);
                 return rname;
             }
             Image maskImage = image.ImageMask;
             PdfIndirectReference maskRef = null;
             if (maskImage != null) {
                 PdfName mname = (PdfName)images[maskImage.MySerialId];
                 maskRef = GetImageReference(mname);
             }
             PdfImage i = new PdfImage(image, "img" + images.Count, maskRef);
             if (image is ImgJBIG2) {
                 byte[] globals = ((ImgJBIG2) image).GlobalBytes;
                 if (globals != null) {
                     PdfDictionary decodeparms = new PdfDictionary();
                     decodeparms.Put(PdfName.JBIG2GLOBALS, GetReferenceJBIG2Globals(globals));
                     i.Put(PdfName.DECODEPARMS, decodeparms);
                 }
             }
             if (image.HasICCProfile()) {
                 PdfICCBased icc = new PdfICCBased(image.TagICC, image.CompressionLevel);
                 PdfIndirectReference iccRef = Add(icc);
                 PdfArray iccArray = new PdfArray();
                 iccArray.Add(PdfName.ICCBASED);
                 iccArray.Add(iccRef);
                 PdfArray colorspace = i.GetAsArray(PdfName.COLORSPACE);
                 if (colorspace != null) {
                     if (colorspace.Size > 1 && PdfName.INDEXED.Equals(colorspace[0]))
                         colorspace[1] = iccArray;
                     else
                         i.Put(PdfName.COLORSPACE, iccArray);
                 }
                 else
                     i.Put(PdfName.COLORSPACE, iccArray);
             }
             Add(i, fixedRef);
             name = i.Name;
         }
         images[image.MySerialId] = name;
     }
     return name;
 }
Esempio n. 19
0
 /**
 * return the <CODE>PdfIndirectReference</CODE> to the image with a given name.
 *
 * @param name the name of the image
 * @return a <CODE>PdfIndirectReference</CODE>
 */
 internal virtual PdfIndirectReference GetImageReference(PdfName name)
 {
     return (PdfIndirectReference) imageDictionary.Get(name);
 }
Esempio n. 20
0
 /** Adds a viewer preference
 * @param preferences the viewer preferences
 * @see PdfViewerPreferences#addViewerPreference
 */
 public virtual void AddViewerPreference(PdfName key, PdfObject value)
 {
     pdf.AddViewerPreference(key, value);
 }
Esempio n. 21
0
 private void AddASEvent(PdfName eventa, PdfName category)
 {
     PdfArray arr = new PdfArray();
     foreach (PdfLayer layer in documentOCG.Keys) {
         PdfDictionary usage = (PdfDictionary)layer.Get(PdfName.USAGE);
         if (usage != null && usage.Get(category) != null)
             arr.Add(layer.Ref);
     }
     if (arr.Size == 0)
         return;
     PdfDictionary d = (PdfDictionary)vOCProperties.Get(PdfName.D);
     PdfArray arras = (PdfArray)d.Get(PdfName.AS);
     if (arras == null) {
         arras = new PdfArray();
         d.Put(PdfName.AS, arras);
     }
     PdfDictionary asa = new PdfDictionary();
     asa.Put(PdfName.EVENT, eventa);
     asa.Put(PdfName.CATEGORY, new PdfArray(category));
     asa.Put(PdfName.OCGS, arr);
     arras.Add(asa);
 }
Esempio n. 22
0
 /** Additional-actions defining the actions to be taken in
 * response to various trigger events affecting the document
 * as a whole. The actions types allowed are: <CODE>DOCUMENT_CLOSE</CODE>,
 * <CODE>WILL_SAVE</CODE>, <CODE>DID_SAVE</CODE>, <CODE>WILL_PRINT</CODE>
 * and <CODE>DID_PRINT</CODE>.
 *
 * @param actionType the action type
 * @param action the action to execute in response to the trigger
 * @throws PdfException on invalid action type
 */
 public virtual void SetAdditionalAction(PdfName actionType, PdfAction action)
 {
     if (!(actionType.Equals(DOCUMENT_CLOSE) ||
     actionType.Equals(WILL_SAVE) ||
     actionType.Equals(DID_SAVE) ||
     actionType.Equals(WILL_PRINT) ||
     actionType.Equals(DID_PRINT))) {
         throw new PdfException("Invalid additional action type: " + actionType.ToString());
     }
     pdf.AddAdditionalAction(actionType, action);
 }
Esempio n. 23
0
 /**
 * Sets a field property. Valid property names are:
 * <p>
 * <ul>
 * <li>textfont - sets the text font. The value for this entry is a <CODE>BaseFont</CODE>.<br>
 * <li>textcolor - sets the text color. The value for this entry is a <CODE>java.awt.Color</CODE>.<br>
 * <li>textsize - sets the text size. The value for this entry is a <CODE>Float</CODE>.
 * <li>bgcolor - sets the background color. The value for this entry is a <CODE>java.awt.Color</CODE>.
 *     If <code>null</code> removes the background.<br>
 * <li>bordercolor - sets the border color. The value for this entry is a <CODE>java.awt.Color</CODE>.
 *     If <code>null</code> removes the border.<br>
 * </ul>
 * @param field the field name
 * @param name the property name
 * @param value the property value
 * @param inst an array of <CODE>int</CODE> indexing into <CODE>AcroField.Item.merged</CODE> elements to process.
 * Set to <CODE>null</CODE> to process all
 * @return <CODE>true</CODE> if the property exists, <CODE>false</CODE> otherwise
 */
 public bool SetFieldProperty(String field, String name, Object value, int[] inst)
 {
     if (writer == null)
         throw new Exception("This AcroFields instance is read-only.");
     Item item = (Item)fields[field];
     if (item == null)
         return false;
     InstHit hit = new InstHit(inst);
     PdfDictionary merged;
     PdfString da;
     if (Util.EqualsIgnoreCase(name, "textfont")) {
         for (int k = 0; k < item.Size; ++k) {
             if (hit.IsHit(k)) {
                 merged = item.GetMerged( k );
                 da = merged.GetAsString(PdfName.DA);
                 PdfDictionary dr = merged.GetAsDict(PdfName.DR);
                 if (da != null && dr != null) {
                     Object[] dao = SplitDAelements(da.ToUnicodeString());
                     PdfAppearance cb = new PdfAppearance();
                     if (dao[DA_FONT] != null) {
                         BaseFont bf = (BaseFont)value;
                         PdfName psn = (PdfName)PdfAppearance.stdFieldFontNames[bf.PostscriptFontName];
                         if (psn == null) {
                             psn = new PdfName(bf.PostscriptFontName);
                         }
                         PdfDictionary fonts = dr.GetAsDict(PdfName.FONT);
                         if (fonts == null) {
                             fonts = new PdfDictionary();
                             dr.Put(PdfName.FONT, fonts);
                         }
                         PdfIndirectReference fref = (PdfIndirectReference)fonts.Get(psn);
                         PdfDictionary top = reader.Catalog.GetAsDict(PdfName.ACROFORM);
                         MarkUsed(top);
                         dr = top.GetAsDict(PdfName.DR);
                         if (dr == null) {
                             dr = new PdfDictionary();
                             top.Put(PdfName.DR, dr);
                         }
                         MarkUsed(dr);
                         PdfDictionary fontsTop = dr.GetAsDict(PdfName.FONT);
                         if (fontsTop == null) {
                             fontsTop = new PdfDictionary();
                             dr.Put(PdfName.FONT, fontsTop);
                         }
                         MarkUsed(fontsTop);
                         PdfIndirectReference frefTop = (PdfIndirectReference)fontsTop.Get(psn);
                         if (frefTop != null) {
                             if (fref == null)
                                 fonts.Put(psn, frefTop);
                         }
                         else if (fref == null) {
                             FontDetails fd;
                             if (bf.FontType == BaseFont.FONT_TYPE_DOCUMENT) {
                                 fd = new FontDetails(null, ((DocumentFont)bf).IndirectReference, bf);
                             }
                             else {
                                 bf.Subset = false;
                                 fd = writer.AddSimple(bf);
                                 localFonts[psn.ToString().Substring(1)] = bf;
                             }
                             fontsTop.Put(psn, fd.IndirectReference);
                             fonts.Put(psn, fd.IndirectReference);
                         }
                         ByteBuffer buf = cb.InternalBuffer;
                         buf.Append(psn.GetBytes()).Append(' ').Append((float)dao[DA_SIZE]).Append(" Tf ");
                         if (dao[DA_COLOR] != null)
                             cb.SetColorFill((Color)dao[DA_COLOR]);
                         PdfString s = new PdfString(cb.ToString());
                         item.GetMerged(k).Put(PdfName.DA, s);
                         item.GetWidget(k).Put(PdfName.DA, s);
                         MarkUsed(item.GetWidget(k));
                     }
                 }
             }
         }
     }
     else if (Util.EqualsIgnoreCase(name, "textcolor")) {
         for (int k = 0; k < item.Size; ++k) {
             if (hit.IsHit(k)) {
                 merged = item.GetMerged( k );
                 da = merged.GetAsString(PdfName.DA);
                 if (da != null) {
                     Object[] dao = SplitDAelements(da.ToUnicodeString());
                     PdfAppearance cb = new PdfAppearance();
                     if (dao[DA_FONT] != null) {
                         ByteBuffer buf = cb.InternalBuffer;
                         buf.Append(new PdfName((String)dao[DA_FONT]).GetBytes()).Append(' ').Append((float)dao[DA_SIZE]).Append(" Tf ");
                         cb.SetColorFill((Color)value);
                         PdfString s = new PdfString(cb.ToString());
                         item.GetMerged(k).Put(PdfName.DA, s);
                         item.GetWidget(k).Put(PdfName.DA, s);
                         MarkUsed(item.GetWidget(k));
                     }
                 }
             }
         }
     }
     else if (Util.EqualsIgnoreCase(name, "textsize")) {
         for (int k = 0; k < item.Size; ++k) {
             if (hit.IsHit(k)) {
                 merged = item.GetMerged( k );
                 da = merged.GetAsString(PdfName.DA);
                 if (da != null) {
                     Object[] dao = SplitDAelements(da.ToUnicodeString());
                     PdfAppearance cb = new PdfAppearance();
                     if (dao[DA_FONT] != null) {
                         ByteBuffer buf = cb.InternalBuffer;
                         buf.Append(new PdfName((String)dao[DA_FONT]).GetBytes()).Append(' ').Append((float)value).Append(" Tf ");
                         if (dao[DA_COLOR] != null)
                             cb.SetColorFill((Color)dao[DA_COLOR]);
                         PdfString s = new PdfString(cb.ToString());
                         item.GetMerged(k).Put(PdfName.DA, s);
                         item.GetWidget(k).Put(PdfName.DA, s);
                         MarkUsed(item.GetWidget(k));
                     }
                 }
             }
         }
     }
     else if (Util.EqualsIgnoreCase(name, "bgcolor") || Util.EqualsIgnoreCase(name, "bordercolor")) {
         PdfName dname = (Util.EqualsIgnoreCase(name, "bgcolor") ? PdfName.BG : PdfName.BC);
         for (int k = 0; k < item.Size; ++k) {
             if (hit.IsHit(k)) {
                 merged = item.GetMerged( k );
                 PdfDictionary mk = merged.GetAsDict(PdfName.MK);
                 if (mk == null) {
                     if (value == null)
                         return true;
                     mk = new PdfDictionary();
                     item.GetMerged(k).Put(PdfName.MK, mk);
                     item.GetWidget(k).Put(PdfName.MK, mk);
                     MarkUsed(item.GetWidget(k));
                 } else {
                     MarkUsed( mk );
                 }
                 if (value == null)
                     mk.Remove(dname);
                 else
                     mk.Put(dname, PdfFormField.GetMKColor((Color)value));
             }
         }
     }
     else
         return false;
     return true;
 }
Esempio n. 24
0
 /**
 * Sets the default colorspace that will be applied to all the document.
 * The colorspace is only applied if another colorspace with the same name
 * is not present in the content.
 * <p>
 * The colorspace is applied immediately when creating templates and at the page
 * end for the main document content.
 * @param key the name of the colorspace. It can be <CODE>PdfName.DEFAULTGRAY</CODE>, <CODE>PdfName.DEFAULTRGB</CODE>
 * or <CODE>PdfName.DEFAULTCMYK</CODE>
 * @param cs the colorspace. A <CODE>null</CODE> or <CODE>PdfNull</CODE> removes any colorspace with the same name
 */
 public void SetDefaultColorspace(PdfName key, PdfObject cs)
 {
     if (cs == null || cs.IsNull())
         defaultColorspace.Remove(key);
     defaultColorspace.Put(key, cs);
 }
Esempio n. 25
0
 /**
 * This function writes the given key/value pair to all the instances
 * of merged, widget, and/or value, depending on the <code>writeFlags</code> setting
 *
 * @since 2.1.5
 *
 * @param key        you'll never guess what this is for.
 * @param value      if value is null, the key will be removed
 * @param writeFlags ORed together WRITE_* flags
 */
 public void WriteToAll(PdfName key, PdfObject value, int writeFlags)
 {
     int i;
     PdfDictionary curDict = null;
     if ((writeFlags & WRITE_MERGED) != 0) {
         for (i = 0; i < merged.Count; ++i) {
             curDict = GetMerged(i);
             curDict.Put(key, value);
         }
     }
     if ((writeFlags & WRITE_WIDGET) != 0) {
         for (i = 0; i < widgets.Count; ++i) {
             curDict = GetWidget(i);
             curDict.Put(key, value);
         }
     }
     if ((writeFlags & WRITE_VALUE) != 0) {
         for (i = 0; i < values.Count; ++i) {
             curDict = GetValue(i);
             curDict.Put(key, value);
         }
     }
 }
Esempio n. 26
0
 public static PdfAnnotation CreateLink(PdfWriter writer, Rectangle rect, PdfName highlight, string namedDestination)
 {
     PdfAnnotation annot = CreateLink(writer, rect, highlight);
     annot.Put(PdfName.DEST, new PdfString(namedDestination));
     return annot;
 }
Esempio n. 27
0
 /** Each font used in a document has an instance of this class.
  * This class stores the characters used in the document and other
  * specifics unique to the current working document.
  * @param fontName the font name
  * @param indirectReference the indirect reference to the font
  * @param baseFont the <CODE>BaseFont</CODE>
  */
 internal FontDetails(PdfName fontName, PdfIndirectReference indirectReference, BaseFont baseFont)
 {
     this.fontName = fontName;
     this.indirectReference = indirectReference;
     this.baseFont = baseFont;
     fontType = baseFont.FontType;
     switch (fontType) {
         case BaseFont.FONT_TYPE_T1:
         case BaseFont.FONT_TYPE_TT:
             shortTag = new byte[256];
             break;
         case BaseFont.FONT_TYPE_CJK:
             cjkTag = new IntHashtable();
             cjkFont = (CJKFont)baseFont;
             break;
         case BaseFont.FONT_TYPE_TTUNI:
             longTag = new Hashtable();
             ttu = (TrueTypeFontUnicode)baseFont;
             symbolic = baseFont.IsFontSpecific();
             break;
     }
 }
Esempio n. 28
0
 /**
 * @see com.lowagie.text.pdf.interfaces.PdfVersion#setPdfVersion(com.lowagie.text.pdf.PdfName)
 */
 public void SetPdfVersion(PdfName version)
 {
     pdf_version.SetPdfVersion(version);
 }
Esempio n. 29
0
 /** Sets the open and close page additional action.
 * @param actionType the action type. It can be <CODE>PdfWriter.PAGE_OPEN</CODE>
 * or <CODE>PdfWriter.PAGE_CLOSE</CODE>
 * @param action the action to perform
 * @throws PdfException if the action type is invalid
 */
 public virtual void SetPageAction(PdfName actionType, PdfAction action)
 {
     if (!actionType.Equals(PAGE_OPEN) && !actionType.Equals(PAGE_CLOSE))
         throw new PdfException("Invalid page additional action type: " + actionType.ToString());
     pdf.SetPageAction(actionType, action);
 }
Esempio n. 30
0
 public static PdfAnnotation CreateLink(PdfWriter writer, Rectangle rect, PdfName highlight, int page, PdfDestination dest)
 {
     PdfAnnotation annot = CreateLink(writer, rect, highlight);
     PdfIndirectReference piref = writer.GetPageReference(page);
     dest.AddPage(piref);
     annot.Put(PdfName.DEST, dest);
     return annot;
 }