首页 文章

如何以编程方式检测XFA(Adobe XML Forms Architecture)动态PDF

提问于
浏览
1

我有一个将pdf转换为tif的系统 . 基本上它是一个用csharp编写的程序,它使用iTextSharp获取有关pdf和pdf2tif(http://pdftotif.sourceforge.net/)的元数据以转换为该文件 . 我注意到一些pdf没有正确转换 . 在Acrobat和Foxit中,它们以多页面形式打开,但在任何其他查看器(Ghostscript ...)中,它们作为1页文档打开并显示消息

"To view the full contents of this document, you need a later version of the PDF viewer. You can upgrade to the latest version of Adobe Reader from " www.adobe.com/products/acrobat/readstep2.html“如需进一步支持,请转至http://www.adobe.com/support/products/acrreader.html

一些傻笑告诉我这些是XFA动态PDF有什么方法我可以编程检测到所以我可以尝试处理这些pdf的不同?

2 回答

  • 1

    iText API是一个好的开始 .

    在iTextSharp中,您可以访问对象的属性,而不是调用方法 . (如果你用iTextSharp完成了大量的工作,你可能已经知道了这一点)

    无论如何,这是一个使用HTTP Handler的简单示例:

    <%@ WebHandler Language="C#" Class="iTextXfa" %>
    using System;
    using System.Web;
    using iTextSharp.text;  
    using iTextSharp.text.pdf;
    
    public class iTextXfa : IHttpHandler {
      public void ProcessRequest (HttpContext context) {
        HttpServerUtility Server = context.Server;
        string[] testFiles = { 
          Server.MapPath("./non-XFA.pdf"), Server.MapPath("./XFA.pdf") 
        };
        foreach (string file in testFiles) {
          XfaForm xfa = new XfaForm(new PdfReader(file));
          context.Response.Write(string.Format(
            "<p>File: {0} is XFA: {1}</p>",
            file,
            xfa.XfaPresent ? "YES" : "NO"
          ));
        }
      }
      public bool IsReusable { get { return false; } }
    }
    
  • 0

    命令行方法:

    strings document.pdf | grep XFA
    

    如果你得到一两行,你可能正在使用XFA PDF:

    <</Names[(!ADBE::0100_VersChkStrings) 364 0 R(!ADBE::0100_VersChkVars) 365 0 R(!ADBE::0200_VersChkCode_XFACheck) 366 0 R]>>
    

相关问题