Programmatically check if pdf is a Form with iTextSharp

余生长醉 提交于 2019-12-11 15:58:52

问题


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

UPDATE

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.

回答1:


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

EDIT

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


来源:https://stackoverflow.com/questions/19381957/programmatically-check-if-pdf-is-a-form-with-itextsharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!