0

I would like to get the date of creation of a PDF using iText7.

I am running into various problems doing so, so I would like to ask for a working solution.

So far, I have not found one.

Thank you.

tmighty
  • 10,734
  • 21
  • 104
  • 218
  • 1
    *"I am running into various problems doing so"* - which problems exactly are you running into? – mkl Aug 21 '22 at 16:59
  • I have tried to following along this post: https://stackoverflow.com/questions/38425925/get-the-creation-date-of-a-pdf-file-using-itext-7 However, I am getting a compiler error at "Dim mypdfobject = documentinfo.GetPdfObject", so I can't even test this. And even if it compiles, I am still stuck because I have no idea how to parse this document info. – tmighty Aug 21 '22 at 17:49
  • 1
    OK, first of all you point to a VB example. From your question alone I've imagined you're talking about a Java example. Or probably a C# one. You probably should have mentioned a preference for VB. Also you mention a *compiler error*. What error exactly? – mkl Aug 21 '22 at 20:48
  • 1
    That being said, have your tried removing that `Dim mypdfobject = documentinfo.GetPdfObject` line? And doing something like `Dim creationDate = doxumentinfo.GetMoreInfo("CreationDate")` or `Dim modificationDate = doxumentinfo.GetMoreInfo("ModDate")`? – mkl Aug 21 '22 at 21:14
  • @mkl Now that I have tried it again, I am already getting a compiler error in this line: Dim PDFDocument = New iTextSharp.text.pdf.PdfDocument(PDFReader). The error is"too many arguments to 'Public Overloads Sub New'. – tmighty Aug 22 '22 at 22:18
  • ps: I find it *really* hard to fight my way through iText because most of the code that I find online doesn't even compile for me.... For example New PdfDocument now suddenly doesn't accept any arguments anymore while some days ago it did. Perhaps I have switched from an older iText version to a new one which introduces total changes. And for most samples, it is not clear which iText version they were written for. Correct me if I am wrong and if I just don't understand it! – tmighty Aug 22 '22 at 22:21
  • @mkl Thank you very much. Your code works. I have added the answer. If you want to post yourself, I will delete my answer. – tmighty Aug 22 '22 at 22:26
  • @KJ To parse this ISO date to a date in VB.NET, should I remove the leading "D:"? I am asking because this throws an error (format exception): Dim d As Date d = DateTime.Parse("D:20220817113241+00'00'", Nothing, System.Globalization.DateTimeStyles.RoundtripKind) – tmighty Aug 22 '22 at 22:29

1 Answers1

0

@mkl wrote the answer to my question. Thank you very much!

        Dim pdfDoc As iText.Kernel.Pdf.PdfDocument
        pdfDoc = New iText.Kernel.Pdf.PdfDocument(New iText.Kernel.Pdf.PdfReader(uPath))

        Dim documentinfo As iText.Kernel.Pdf.PdfDocumentInfo = pdfDoc.GetDocumentInfo

        Dim author As String = documentinfo.GetAuthor
        Dim creator As String = documentinfo.GetCreator
        Dim creationDate = documentinfo.GetMoreInfo("CreationDate")
        Dim modificationDate = documentinfo.GetMoreInfo("ModDate")
tmighty
  • 10,734
  • 21
  • 104
  • 218