以编程方式检查pdf是否为带有iTextSharp的表单 [英] Programmatically check if pdf is a Form with iTextSharp

查看:84
本文介绍了以编程方式检查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.

推荐答案

检查表单的最简单方法是查看PdfReaderAcroForm字段是否为空:

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()

这篇关于以编程方式检查pdf是否为带有iTextSharp的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆