/// <summary>Fixes the GPS Timestamp in EXIF.</summary>
        /// <param name="exifSchema">the EXIF schema node</param>
        /// <exception cref="iText.Kernel.XMP.XMPException">Thrown if the date conversion fails.
        ///     </exception>
        private static void FixGPSTimeStamp(XMPNode exifSchema)
        {
            // Note: if dates are not found the convert-methods throws an exceptions,
            //       and this methods returns.
            XMPNode gpsDateTime = XMPNodeUtils.FindChildNode(exifSchema, "exif:GPSTimeStamp", false);

            if (gpsDateTime == null)
            {
                return;
            }

            try {
                XMPDateTime binGpsStamp = XMPUtils.ConvertToDate(gpsDateTime.GetValue());
                if (binGpsStamp.GetYear() != 0 || binGpsStamp.GetMonth() != 0 || binGpsStamp.GetDay() != 0)
                {
                    return;
                }

                XMPNode otherDate = XMPNodeUtils.FindChildNode(exifSchema, "exif:DateTimeOriginal", false);
                otherDate = otherDate ?? XMPNodeUtils.FindChildNode(exifSchema, "exif:DateTimeDigitized", false);

                XMPDateTime binOtherDate = XMPUtils.ConvertToDate(otherDate.GetValue());
                XMPCalendar cal          = binGpsStamp.GetCalendar();
                DateTime    dt           = new DateTime(binOtherDate.GetYear(), binOtherDate.GetMonth(), binOtherDate.GetDay(),
                                                        cal.GetDateTime().Hour, cal.GetDateTime().Minute, cal.GetDateTime().Second, cal.GetDateTime().Millisecond);
                cal.SetDateTime(dt);
                binGpsStamp = new XMPDateTimeImpl(cal);
                gpsDateTime.SetValue(XMPUtils.ConvertFromDate(binGpsStamp));
            }
            catch (XMPException) {
            }
        }
        /// <summary>
        /// Fixes the GPS Timestamp in EXIF. </summary>
        /// <param name="exifSchema"> the EXIF schema node </param>
        /// <exception cref="XmpException"> Thrown if the date conversion fails. </exception>
        private static void FixGpsTimeStamp(XmpNode exifSchema)
        {
            // Note: if dates are not found the convert-methods throws an exceptions,
            //       and this methods returns.
            XmpNode gpsDateTime = XmpNodeUtils.FindChildNode(exifSchema, "exif:GPSTimeStamp", false);

            if (gpsDateTime == null)
            {
                return;
            }

            try {
                XMPDateTime binGpsStamp = XMPUtils.ConvertToDate(gpsDateTime.Value);
                if (binGpsStamp.Year != 0 || binGpsStamp.Month != 0 || binGpsStamp.Day != 0)
                {
                    return;
                }

                XmpNode otherDate = XmpNodeUtils.FindChildNode(exifSchema, "exif:DateTimeOriginal", false);
                otherDate = otherDate ?? XmpNodeUtils.FindChildNode(exifSchema, "exif:DateTimeDigitized", false);

                XMPDateTime binOtherDate = XMPUtils.ConvertToDate(otherDate.Value);
                XmpCalendar cal          = binGpsStamp.Calendar;
                DateTime    dt           = new DateTime(binOtherDate.Year, binOtherDate.Month, binOtherDate.Day, cal.DateTime.Hour,
                                                        cal.DateTime.Minute, cal.DateTime.Second, cal.DateTime.Millisecond);
                cal.DateTime      = dt;
                binGpsStamp       = new XmpDateTimeImpl(cal);
                gpsDateTime.Value = XMPUtils.ConvertFromDate(binGpsStamp);
            }
            catch (XmpException) {
            }
        }
        private byte[] RemoveAlwaysDifferentEntries(byte[] cmpBytes)
        {
            XMPMeta xmpMeta = XMPMetaFactory.ParseFromBuffer(cmpBytes);

            XMPUtils.RemoveProperties(xmpMeta, XMPConst.NS_XMP, PdfConst.CreateDate, true, true);
            XMPUtils.RemoveProperties(xmpMeta, XMPConst.NS_XMP, PdfConst.ModifyDate, true, true);
            XMPUtils.RemoveProperties(xmpMeta, XMPConst.NS_XMP, PdfConst.MetadataDate, true, true);
            XMPUtils.RemoveProperties(xmpMeta, XMPConst.NS_PDF, PdfConst.Producer, true, true);
            cmpBytes = XMPMetaFactory.SerializeToBuffer(xmpMeta, new SerializeOptions(SerializeOptions.SORT));
            return(cmpBytes);
        }
Exemple #4
0
 protected override void AddCustomMetadataExtensions(XMPMeta xmpMeta)
 {
     if (this.IsTagged())
     {
         try {
             XMPMeta taggedExtensionMeta = XMPMetaFactory.ParseFromString(PdfAXMPUtil.PDF_UA_EXTENSION);
             XMPUtils.AppendProperties(taggedExtensionMeta, xmpMeta, true, false);
         }
         catch (XMPException exc) {
             ILogger logger = LoggerFactory.GetLogger(typeof(iText.Pdfa.PdfADocument));
             logger.Error(LogMessageConstant.EXCEPTION_WHILE_UPDATING_XMPMETADATA, exc);
         }
     }
 }
Exemple #5
0
        /// <summary>
        /// Converts the node value to String, apply special conversions for defined
        /// types in XMP.
        /// </summary>
        /// <param name="value">
        ///            the node value to set </param>
        /// <returns> Returns the String representation of the node value. </returns>
        internal static string SerializeNodeValue(object value)
        {
            string strValue;

            if (value == null)
            {
                strValue = null;
            }
            else if (value is bool?)
            {
                strValue = XMPUtils.ConvertFromBoolean((bool)((bool?)value));
            }
            else if (value is int?)
            {
                strValue = XMPUtils.ConvertFromInteger((int)((int?)value));
            }
            else if (value is long?)
            {
                strValue = XMPUtils.ConvertFromLong((long)((long?)value));
            }
            else if (value is double?)
            {
                strValue = XMPUtils.ConvertFromDouble((double)((double?)value));
            }
            else if (value is XMPDateTime)
            {
                strValue = XMPUtils.ConvertFromDate((XMPDateTime)value);
            }
            else if (value is XmpCalendar)
            {
                XMPDateTime dt = XMPDateTimeFactory.CreateFromCalendar((XmpCalendar)value);
                strValue = XMPUtils.ConvertFromDate(dt);
            }
            else if (value is byte[])
            {
                strValue = XMPUtils.EncodeBase64((byte[])value);
            }
            else
            {
                strValue = value.ToString();
            }

            return(strValue != null?Utils.RemoveControlChars(strValue) : null);
        }
Exemple #6
0
 protected override void UpdateXmpMetadata()
 {
     try {
         XMPMeta xmpMeta = UpdateDefaultXmpMetadata();
         xmpMeta.SetProperty(XMPConst.NS_PDFA_ID, XMPConst.PART, checker.GetConformanceLevel().GetPart());
         xmpMeta.SetProperty(XMPConst.NS_PDFA_ID, XMPConst.CONFORMANCE, checker.GetConformanceLevel().GetConformance
                                 ());
         if (this.IsTagged())
         {
             XMPMeta taggedExtensionMeta = XMPMetaFactory.ParseFromString(PdfAXMPUtil.PDF_UA_EXTENSION);
             XMPUtils.AppendProperties(taggedExtensionMeta, xmpMeta, true, false);
         }
         SetXmpMetadata(xmpMeta);
     }
     catch (XMPException e) {
         ILogger logger = LoggerFactory.GetLogger(typeof(iText.Pdfa.PdfADocument));
         logger.Error(LogMessageConstant.EXCEPTION_WHILE_UPDATING_XMPMETADATA, e);
     }
 }
        /// <summary>Adds the ZUGFeRD RDF description.</summary>
        /// <param name="xmpMeta">the xmp meta</param>
        /// <param name="zugferdConformanceLevel">the zugferd conformance level</param>
        /// <exception cref="iText.Kernel.XMP.XMPException">the XMP exception</exception>
        private void AddZugferdRdfDescription(XMPMeta xmpMeta, ZugferdConformanceLevel zugferdConformanceLevel)
        {
            switch (zugferdConformanceLevel)
            {
            case ZugferdConformanceLevel.ZUGFeRDBasic:
            case ZugferdConformanceLevel.ZUGFeRDComfort:
            case ZugferdConformanceLevel.ZUGFeRDExtended: {
                // fallthrough
                // fallthrough
                XMPMeta taggedExtensionMetaComfort = XMPMetaFactory.ParseFromString(GetZugferdExtension(zugferdConformanceLevel
                                                                                                        ));
                XMPUtils.AppendProperties(taggedExtensionMetaComfort, xmpMeta, true, false);
                break;
            }

            default: {
                break;
            }
            }
        }
        /// <summary>Fixes the GPS Timestamp in EXIF.</summary>
        /// <param name="exifSchema">the EXIF schema node</param>
        /// <exception cref="Com.Adobe.Xmp.XMPException">Thrown if the date conversion fails.</exception>
        private static void FixGPSTimeStamp(XMPNode exifSchema)
        {
            // Note: if dates are not found the convert-methods throws an exceptions,
            //       and this methods returns.
            XMPNode gpsDateTime = XMPNodeUtils.FindChildNode(exifSchema, "exif:GPSTimeStamp", false);

            if (gpsDateTime == null)
            {
                return;
            }
            try
            {
                XMPDateTime binGPSStamp;
                XMPDateTime binOtherDate;
                binGPSStamp = XMPUtils.ConvertToDate(gpsDateTime.GetValue());
                if (binGPSStamp.GetYear() != 0 || binGPSStamp.GetMonth() != 0 || binGPSStamp.GetDay() != 0)
                {
                    return;
                }
                XMPNode otherDate = XMPNodeUtils.FindChildNode(exifSchema, "exif:DateTimeOriginal", false);
                if (otherDate == null)
                {
                    otherDate = XMPNodeUtils.FindChildNode(exifSchema, "exif:DateTimeDigitized", false);
                }
                binOtherDate = XMPUtils.ConvertToDate(otherDate.GetValue());
                Sharpen.Calendar cal = binGPSStamp.GetCalendar();
                cal.Set(Sharpen.CalendarEnum.Year, binOtherDate.GetYear());
                cal.Set(Sharpen.CalendarEnum.Month, binOtherDate.GetMonth());
                cal.Set(Sharpen.CalendarEnum.DayOfMonth, binOtherDate.GetDay());
                binGPSStamp = new XMPDateTimeImpl(cal);
                gpsDateTime.SetValue(XMPUtils.ConvertFromDate(binGPSStamp));
            }
            catch (XMPException)
            {
                // Don't let a missing or bad date stop other things.
                return;
            }
        }
Exemple #9
0
        /// <summary>
        /// Converts the node value to String, apply special conversions for defined
        /// types in XMP.
        /// </summary>
        /// <param name="value">the node value to set</param>
        /// <returns>Returns the String representation of the node value.</returns>
        internal static string SerializeNodeValue(object value)
        {
            string strValue;

            if (value == null)
            {
                strValue = null;
            }
            else
            {
                if (value is bool)
                {
                    strValue = XMPUtils.ConvertFromBoolean(((bool)value));
                }
                else
                {
                    if (value is int)
                    {
                        strValue = XMPUtils.ConvertFromInteger(((int)value).IntValue());
                    }
                    else
                    {
                        if (value is long)
                        {
                            strValue = XMPUtils.ConvertFromLong(((long)value).LongValue());
                        }
                        else
                        {
                            if (value is double)
                            {
                                strValue = XMPUtils.ConvertFromDouble(((double)value).DoubleValue());
                            }
                            else
                            {
                                if (value is XMPDateTime)
                                {
                                    strValue = XMPUtils.ConvertFromDate((XMPDateTime)value);
                                }
                                else
                                {
                                    if (value is Sharpen.GregorianCalendar)
                                    {
                                        XMPDateTime dt = XMPDateTimeFactory.CreateFromCalendar((Sharpen.GregorianCalendar)value);
                                        strValue = XMPUtils.ConvertFromDate(dt);
                                    }
                                    else
                                    {
                                        if (value is sbyte[])
                                        {
                                            strValue = XMPUtils.EncodeBase64((sbyte[])value);
                                        }
                                        else
                                        {
                                            strValue = value.ToString();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(strValue != null?Utils.RemoveControlChars(strValue) : null);
        }
		/// <summary>
		/// Evaluates a raw node value to the given value type, apply special
		/// conversions for defined types in XMP.
		/// </summary>
		/// <param name="valueType">an int indicating the value type</param>
		/// <param name="propNode">the node containing the value</param>
		/// <returns>Returns a literal value for the node.</returns>
		/// <exception cref="iText.Kernel.XMP.XMPException">
		/// if the value of <code>propNode</code> is <code>null</code> or empty or the conversion fails.
		/// </exception>
		private Object EvaluateNodeValue(int valueType, XMPNode propNode)
		{
			Object value;
			String rawValue = propNode.GetValue();
			switch (valueType)
			{
				case VALUE_BOOLEAN:
				{
					value = XMPUtils.ConvertToBoolean(rawValue);
					break;
				}

				case VALUE_INTEGER:
				{
					value = XMPUtils.ConvertToInteger(rawValue);
					break;
				}

				case VALUE_LONG:
				{
					value = XMPUtils.ConvertToLong(rawValue);
					break;
				}

				case VALUE_DOUBLE:
				{
					value = XMPUtils.ConvertToDouble(rawValue);
					break;
				}

				case VALUE_DATE:
				{
					value = XMPUtils.ConvertToDate(rawValue);
					break;
				}

				case VALUE_CALENDAR:
				{
					XMPDateTime dt = XMPUtils.ConvertToDate(rawValue);
					value = dt.GetCalendar();
					break;
				}

				case VALUE_BASE64:
				{
					value = XMPUtils.DecodeBase64(rawValue);
					break;
				}

				case VALUE_STRING:
				default:
				{
					// leaf values return empty string instead of null
					// for the other cases the converter methods provides a "null"
					// value.
					// a default value can only occur if this method is made public.
					value = rawValue != null || propNode.GetOptions().IsCompositeProperty() ? rawValue
						 : "";
					break;
				}
			}
			return value;
		}