/// <summary>Sets the value of the collection item.</summary> /// <param name="key"/> /// <param name="value"/> public virtual iText.Kernel.Pdf.Collection.PdfCollectionItem AddItem(String key, String value) { PdfCollectionField field = schema.GetField(key); GetPdfObject().Put(new PdfName(key), field.GetValue(value)); return(this); }
public virtual void GetTextValueTest() { String textValue = "some text"; PdfDictionary pdfObject = new PdfDictionary(); pdfObject.Put(PdfName.Subtype, PdfName.S); PdfCollectionField field = new PdfCollectionField(pdfObject); NUnit.Framework.Assert.AreEqual(new PdfString(textValue), field.GetValue(textValue)); }
public virtual void GetDateValueTest() { String timeValueAsString = "D:19860426012347+04'00'"; PdfDictionary pdfObject = new PdfDictionary(); pdfObject.Put(PdfName.Subtype, PdfName.D); PdfCollectionField field = new PdfCollectionField(pdfObject); NUnit.Framework.Assert.IsTrue(((PdfString)field.GetValue(timeValueAsString)).GetValue().StartsWith("D:1986" )); }
public virtual void GetNumberValueTest() { double numberValue = 125; String numberValueAsString = numberValue.ToString(); PdfDictionary pdfObject = new PdfDictionary(); pdfObject.Put(PdfName.Subtype, PdfName.N); PdfCollectionField field = new PdfCollectionField(pdfObject); NUnit.Framework.Assert.AreEqual(numberValue, ((PdfNumber)field.GetValue(numberValueAsString)).GetValue(), 0.0001); }
public virtual void GetUnsupportedTypeValueTest() { String stringValue = "string value"; String fieldName = "fieldName"; NUnit.Framework.Assert.That(() => { PdfCollectionField field = new PdfCollectionField(fieldName, PdfCollectionField.FILENAME); // this line will throw an exception as getValue() method is not // supported for subType which differs from S, N and D. field.GetValue(stringValue); } , NUnit.Framework.Throws.InstanceOf <PdfException>().With.Message.EqualTo(MessageFormatUtil.Format(PdfException._1IsNotAnAcceptableValueForTheField2, stringValue, fieldName))) ; }
public virtual void AddDateItemTest() { String fieldName = "fieldName"; String timeValueAsString = "D:19860426012347+04'00'"; PdfDictionary pdfObject = new PdfDictionary(); pdfObject.Put(PdfName.Subtype, PdfName.D); PdfCollectionField field = new PdfCollectionField(pdfObject); PdfCollectionSchema schema = new PdfCollectionSchema(); schema.AddField(fieldName, field); PdfCollectionItem item = new PdfCollectionItem(schema); item.AddItem(fieldName, new PdfDate(PdfDate.Decode(timeValueAsString))); NUnit.Framework.Assert.IsTrue(((PdfString)field.GetValue(timeValueAsString)).GetValue().StartsWith("D:1986" )); }