【问题标题】:Get the Creation Date of a PDF file using iText 7使用 iText 7 获取 PDF 文件的创建日期
【发布时间】:2016-11-20 10:10:25
【问题描述】:

我必须创建一个工具,将它们的创建日期添加到几个 .pdf 文件名中。 我想使用内部存储在 pdf 中的创建日期,为此我下载了 iText 社区版。

现在,我的代码是这样开始的(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

我得到了 GetAuthor 和 GetCreator 以及其他几个 Get 方法,但我找不到像 GetCreationDate 这样的东西,只有 AddCreationDate。

如果我进一步了解 mypdfobject,我会在 map 中找到 /Creationdate 标签,所以我想使用它,但是,虽然它通常采用 D:20160704132234+02'00' 格式,但有时我会发现一些看起来像二进制的东西数据,我不知道如何解码。

有没有更好的方法来获取创建日期?

谢谢

斯特凡诺

【问题讨论】:

  • 创建日期是一个 PDF 字符串值。有两种表示字符串的方法。您已经知道这种方式:(D:20160704132234+02'00'),但也有十六进制表示法,例如:<443A32303136303730343133323233342b303227303027>。当您说我发现一些看似二进制数据但我不知道如何解码的东西时,您是否觉得后者很熟悉?

标签: vb.net date pdf itext7


【解决方案1】:

创建日期是一个 PDF 字符串值。有两种表示字符串的方法。您已经知道这种方式:(D:20160704132234+02'00'),但也有十六进制表示法,例如:<443A32303136303730343133323233342b303227303027>

当您拥有PdfString 时,您可以通过不同方式获取值:有toString(),但也有toUnicodeString()。当你有一个String 版本时,你可以从PdfDate 类中得到一个Calendar 对象:

Calendar date = PdfDate.decode(s);

如果你想要 W3C 格式的日期,你可以这样做:

string w3cDate = PdfDate.getW3CDate(s);

【讨论】:

  • 在Visual Studio中,调试的时候发现
  • Value {�%�����NR��q��}(这是我说的二进制形式)
  • 内容{Length=16},所以是16字节
  • 无间接参考
  • 状态0(不知道是什么意思)
猜你喜欢
  • 2014-12-26
  • 1970-01-01
  • 2013-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-04
  • 1970-01-01
相关资源
最近更新 更多