public static DateTime?GetMetaTextAsDate(IntPtr document, string tag) { string dt = CallNative.GetMetaText(document, tag); DateTime parseDate; if (string.IsNullOrEmpty(dt)) { return(null); } Regex dtRegex = new Regex( @"(?:D:)(?<year>\d\d\d\d)(?<month>\d\d)(?<day>\d\d)(?<hour>\d\d)(?<minute>\d\d)(?<second>\d\d)(?<tz_offset>[+-zZ])?(?<tz_hour>\d\d)?'?(?<tz_minute>\d\d)?'?"); Match match = dtRegex.Match(dt); if (match.Success) { var year = match.Groups["year"].Value; var month = match.Groups["month"].Value; var day = match.Groups["day"].Value; var hour = match.Groups["hour"].Value; var minute = match.Groups["minute"].Value; var second = match.Groups["second"].Value; var tzOffset = match.Groups["tz_offset"]?.Value; var tzHour = match.Groups["tz_hour"]?.Value; var tzMinute = match.Groups["tz_minute"]?.Value; string formattedDate = $"{year}-{month}-{day}T{hour}:{minute}:{second}.0000000"; if (!string.IsNullOrEmpty(tzOffset)) { switch (tzOffset) { case "Z": case "z": formattedDate += "+0"; break; case "+": case "-": formattedDate += $"{tzOffset}{tzHour}:{tzMinute}"; break; } } if (!DateTime.TryParse(formattedDate, out parseDate)) { throw new FormatException(); } return(parseDate); } return(null); }
public PdfInformation GetInformation() { var pdfInfo = new PdfInformation(); pdfInfo.Creator = CallNative.GetMetaText(_doc, "Creator"); pdfInfo.Title = CallNative.GetMetaText(_doc, "Title"); pdfInfo.Author = CallNative.GetMetaText(_doc, "Author"); pdfInfo.Subject = CallNative.GetMetaText(_doc, "Subject"); pdfInfo.Keywords = CallNative.GetMetaText(_doc, "Keywords"); pdfInfo.Producer = CallNative.GetMetaText(_doc, "Producer"); pdfInfo.CreationDate = CallNative.GetMetaTextAsDate(_doc, "CreationDate"); pdfInfo.ModificationDate = CallNative.GetMetaTextAsDate(_doc, "ModDate"); return(pdfInfo); }