5

I have to create a tool which adds to several .pdf file names their creation date. I'd like to use the creationdate stored internally in pdfs and for this I downloaded iText Community Edition.

Now, my code starts like this (VB)

Module Module1

    Sub Main()

        Dim filename As String = My.Application.CommandLineArgs(0)

        Dim PDFReader = New Pdf.PdfReader(filename)
        Dim PDFDocument = New Pdf.PdfDocument(PDFReader)

        Dim documentinfo As Pdf.PdfDocumentInfo = PDFDocument.GetDocumentInfo

        Dim author As String = documentinfo.GetAuthor
        Dim creator As String = documentinfo.GetCreator
        Dim mypdfobject = documentinfo.GetPdfObject

    End Sub

End Module

I got the GetAuthor and GetCreator together with several other Get method, but I can't find something like GetCreationDate, only AddCreationDate.

If I go further into mypdfobject I find into map a /Creationdate tag, so I thought to use that, but, while it is often in the format D:20160704132234+02'00', sometimes I find something which seems binary data and I don't know how to decode that.

Is there any better way to get the creation date ?

Thanks

Stefano

Alexey Subach
  • 11,903
  • 7
  • 34
  • 60
  • The creation date is a PDF string value. There are two ways to represent a string. You already know this way: `(D:20160704132234+02'00')`, but there's also a hexadecimal notation, for instance: `<443A32303136303730343133323233342b303227303027>`. Does the latter look familiar to you when you say *I find something which seems binary data and I don't know how to decode that*? – Bruno Lowagie Jul 18 '16 at 02:08
  • You should show your code for your sentence "If I go further into mypdfobject", so that others can learn from it. – tmighty Aug 21 '22 at 15:37
  • Also, your code does not compile at "Dim mypdfobject = documentinfo.GetPdfObject" – tmighty Aug 21 '22 at 15:38
  • @tmighty Unfortunately the question is more than 6 years old. 5 years ago `PdfDocumentInfo` stopped being derived from `PdfObjectWrapper` and so lost the `GetObject` method... – mkl Aug 21 '22 at 21:07

1 Answers1

4

The creation date is a PDF string value. There are two ways to represent a string. You already know this way: (D:20160704132234+02'00'), but there's also a hexadecimal notation, for instance: <443A32303136303730343133323233342b303227303027>.

When you have a PdfString, you can get the value in different ways: there's toString(), but there's also toUnicodeString(). When you have a String version, you can get a Calendar object from the PdfDate class:

Calendar date = PdfDate.decode(s);

If you want the date in W3C format, you can do something like this:

string w3cDate = PdfDate.getW3CDate(s);
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165