Posted By

poxet on 11/10/10


Tagged

pdf


Versions (?)

Get properties from a PDF file


 / Published in: C#
 

Provide the PDF document content as a string and it will return the data content of properties like Title or Subject.

  1. private static string GetPropertyValueEx(string pdfData, string propertyName)
  2. {
  3. var result = "";
  4.  
  5. var propertyNameLength = propertyName.Length + 3;
  6. var leadLength = 4;
  7.  
  8. var r2 = new Regex(string.Format("/{0} <[A-Za-z0-9]*>", propertyName));
  9. var m = r2.Match(pdfData);
  10. if (m.Success)
  11. {
  12. //System.Diagnostics.Debug.WriteLine(m.Index);
  13. var valueRaw = m.Value.Substring(propertyNameLength, m.Value.Length - propertyNameLength - 1);
  14. for (int i = leadLength; i < valueRaw.Length; i = i + 4)
  15. {
  16. var hexVal = valueRaw.Substring(i, 4);
  17. var num = (Convert.ToUInt32(hexVal, 16));
  18. result += (char)num;
  19. }
  20. }
  21.  
  22. return result;
  23. }

Report this snippet  

You need to login to post a comment.