以编程方式检查pdf是否为带有iTextSharp的表单
我正在尝试在我们的服务器上收集有关pdf文件的一些元数据.我想知道它们是否为表格,如果是,是否可以保存或必须打印.像iTextSharp这样的东西会暴露这种信息吗?
I'm trying to collect some metadata about pdf files on our server. I'd like to know whether or not they are a form, and if so, if they can be saved or must be printed. Does something like iTextSharp expose that kind of information?
这是我可以使用的代码示例
Here's a code sample where I can
Private Sub GetPDFInfo(ByVal path As String)
If File.Exists(path) Then
Dim reader As New PdfReader(path)
'sample metadata exposed
Dim numberOfPages = reader.NumberOfPages
'what to call to get form info?
End If
End Sub
更新
这就是我能保存或不保存的意思: 我不确定这些信息在哪里,但是每种表单都有某种形式的指示,表明是否可以将表单数据保存在本地.
Here's what I mean by being able to save or not: I'm not sure where this information lives, but each form has some kind of indication of whether or not the form data can be saved locally.
检查表单的最简单方法是查看PdfReader
的AcroForm
字段是否为空:
The simplest way to check for a form would be to see if the PdfReader
's AcroForm
field is null:
Dim HasForm = reader.AcroForm IsNot Nothing
编辑
我没有Adobe Reader,但是我认为当未在表单上启用使用权时会生成该消息.您应该可以使用:
I don't have Adobe Reader laying around but I think that message is generated when usage rights aren't enabled on a form. You should be able to use:
Dim CanUserSave = reader.HasUsageRights()