Exemple #1
0
 /**
 * Creates a PdfPattern object.
 * @param   painter a pattern painter instance
 * @param   compressionLevel the compressionLevel for the stream
 * @since   2.1.3
 */
 internal PdfPattern(PdfPatternPainter painter, int compressionLevel)
     : base()
 {
     PdfNumber one = new PdfNumber(1);
     PdfArray matrix = painter.Matrix;
     if ( matrix != null ) {
         Put(PdfName.MATRIX, matrix);
     }
     Put(PdfName.TYPE, PdfName.PATTERN);
     Put(PdfName.BBOX, new PdfRectangle(painter.BoundingBox));
     Put(PdfName.RESOURCES, painter.Resources);
     Put(PdfName.TILINGTYPE, one);
     Put(PdfName.PATTERNTYPE, one);
     if (painter.IsStencil())
         Put(PdfName.PAINTTYPE, new PdfNumber(2));
     else
         Put(PdfName.PAINTTYPE, one);
     Put(PdfName.XSTEP, new PdfNumber(painter.XStep));
     Put(PdfName.YSTEP, new PdfNumber(painter.YStep));
     bytes = painter.ToPdf(null);
     Put(PdfName.LENGTH, new PdfNumber(bytes.Length));
     FlateCompress(compressionLevel);
 }
Exemple #2
0
 /**
 * Sets a field property. Valid property names are:
 * <p>
 * <ul>
 * <li>flags - a set of flags specifying various characteristics of the field’s widget annotation.
 * The value of this entry replaces that of the F entry in the form’s corresponding annotation dictionary.<br>
 * <li>setflags - a set of flags to be set (turned on) in the F entry of the form’s corresponding
 * widget annotation dictionary. Bits equal to 1 cause the corresponding bits in F to be set to 1.<br>
 * <li>clrflags - a set of flags to be cleared (turned off) in the F entry of the form’s corresponding
 * widget annotation dictionary. Bits equal to 1 cause the corresponding
 * bits in F to be set to 0.<br>
 * <li>fflags - a set of flags specifying various characteristics of the field. The value
 * of this entry replaces that of the Ff entry in the form’s corresponding field dictionary.<br>
 * <li>setfflags - a set of flags to be set (turned on) in the Ff entry of the form’s corresponding
 * field dictionary. Bits equal to 1 cause the corresponding bits in Ff to be set to 1.<br>
 * <li>clrfflags - a set of flags to be cleared (turned off) in the Ff entry of the form’s corresponding
 * field dictionary. Bits equal to 1 cause the corresponding bits in Ff
 * to be set to 0.<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, int 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);
     if (Util.EqualsIgnoreCase(name, "flags")) {
         PdfNumber num = new PdfNumber(value);
         for (int k = 0; k < item.Size; ++k) {
             if (hit.IsHit(k)) {
                 item.GetMerged(k).Put(PdfName.F, num);
                 item.GetWidget(k).Put(PdfName.F, num);
                 MarkUsed(item.GetWidget(k));
             }
         }
     }
     else if (Util.EqualsIgnoreCase(name, "setflags")) {
         for (int k = 0; k < item.Size; ++k) {
             if (hit.IsHit(k)) {
                 PdfNumber num = item.GetWidget(k).GetAsNumber(PdfName.F);
                 int val = 0;
                 if (num != null)
                     val = num.IntValue;
                 num = new PdfNumber(val | value);
                 item.GetMerged(k).Put(PdfName.F, num);
                 item.GetWidget(k).Put(PdfName.F, num);
                 MarkUsed(item.GetWidget(k));
             }
         }
     }
     else if (Util.EqualsIgnoreCase(name, "clrflags")) {
         for (int k = 0; k < item.Size; ++k) {
             if (hit.IsHit(k)) {
                 PdfDictionary widget = item.GetWidget( k );
                 PdfNumber num = widget.GetAsNumber(PdfName.F);
                 int val = 0;
                 if (num != null)
                     val = num.IntValue;
                 num = new PdfNumber(val & (~value));
                 item.GetMerged(k).Put(PdfName.F, num);
                 widget.Put(PdfName.F, num);
                 MarkUsed(widget);
             }
         }
     }
     else if (Util.EqualsIgnoreCase(name, "fflags")) {
         PdfNumber num = new PdfNumber(value);
         for (int k = 0; k < item.Size; ++k) {
             if (hit.IsHit(k)) {
                 item.GetMerged(k).Put(PdfName.FF, num);
                 item.GetValue(k).Put(PdfName.FF, num);
                 MarkUsed(item.GetValue(k));
             }
         }
     }
     else if (Util.EqualsIgnoreCase(name, "setfflags")) {
         for (int k = 0; k < item.Size; ++k) {
             if (hit.IsHit(k)) {
                 PdfDictionary valDict = item.GetValue( k );
                 PdfNumber num = valDict.GetAsNumber( PdfName.FF );
                 int val = 0;
                 if (num != null)
                     val = num.IntValue;
                 num = new PdfNumber(val | value);
                 item.GetMerged(k).Put(PdfName.FF, num);
                 valDict.Put(PdfName.FF, num);
                 MarkUsed(valDict);
             }
         }
     }
     else if (Util.EqualsIgnoreCase(name, "clrfflags")) {
         for (int k = 0; k < item.Size; ++k) {
             if (hit.IsHit(k)) {
                 PdfDictionary valDict = item.GetValue( k );
                 PdfNumber num = valDict.GetAsNumber(PdfName.FF);
                 int val = 0;
                 if (num != null)
                     val = num.IntValue;
                 num = new PdfNumber(val & (~value));
                 item.GetMerged(k).Put(PdfName.FF, num);
                 valDict.Put(PdfName.FF, num);
                 MarkUsed(valDict);
             }
         }
     }
     else
         return false;
     return true;
 }
Exemple #3
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;
 }
 private void AdjustTabOrder(PdfArray annots, PdfIndirectReference ind, PdfNumber nn)
 {
     int v = nn.IntValue;
     ArrayList t = (ArrayList)tabOrder[annots] ;
     if (t == null) {
         t = new ArrayList();
         int size = annots.Size - 1;
         for (int k = 0; k < size; ++k) {
             t.Add(zero);
         }
         t.Add(v);
         tabOrder[annots] =  t;
         annots.Add(ind);
     }
     else {
         int size = t.Count - 1;
         for (int k = size; k >= 0; --k) {
             if ((int)t[k] <= v) {
                 t.Insert(k + 1, v);
                 annots.Add(k + 1, ind);
                 size = -2;
                 break;
             }
         }
         if (size != -2) {
             t.Insert(0, v);
             annots.Add(0, ind);
         }
     }
 }
Exemple #5
0
 /**
 * Adds a <CODE>PdfNumber</CODE> to the <CODE>PdfArray</CODE>.
 *
 * @param  number   displacement of the string
 */
 public void Add(PdfNumber number)
 {
     Add((float)number.DoubleValue);
 }