2012-11-16 24 views
6

是否有方法可以确定PDF文件的类型:如果现有PDF文件是扫描图像,还是使用iTextSharp和C#从数据文件创建?如何使用iTextSharp确定PDF文件类型

+1

你的标准是什么?您如何区分扫描仪的PDF和其他类型的文档?这是打印的字符数量吗?图像覆盖的页面面积是多少?它是创建PDF的程序的名称? iTextSharp可以帮助您确定这些值,但您必须提前准备好标准。 – mkl

+0

“您如何区分扫描仪的PDF文件...” - 您甚至无法选择文本 – ESB

+0

Hhmmm,但情况并非如此。有一些扫描解决方案会执行一些额外的OCR,然后通过不可见但可选择的文本丰富扫描的PDF。另一方面,使用iTextSharp和C#*可以很容易地从数据文件中创建* PDF *,而无需任何可选文本。那么,我是否可以解释您的问题,以便您实际上想区分具有可选文本和没有文本的PDF? – mkl

回答

0

文档属性/高级/ PDF制作

+0

请你详细说明一下吗?代码示例可能... – ESB

0

我刚才提出这个方法的PdfWriter对象的监视窗口中搜索合适的位置后,以取代PDF制作,它改变了PDF的“PDF造物主”,因为它是不是默认访问:

private static void ReplacePdfCreator(PdfWriter writer) 
    { 
     /* 

     Warning 
     * 
     This is not an option offered as is and i had to workaround it by using Reflection and change it 
     manually. 
     * 
     Alejandro 

     */ 
     Type writerType = writer.GetType(); 
     PropertyInfo writerProperty = 
      writerType.GetProperties(BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance) 
         .FirstOrDefault(p => p.PropertyType == typeof(PdfDocument)); 

     if (writerProperty != null) 
     { 
      PdfDocument pd = (PdfDocument)writerProperty.GetValue(writer); 
      Type pdType = pd.GetType(); 
      FieldInfo infoProperty = 
       pdType.GetFields(BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance) 
         .FirstOrDefault(p => p.Name == "info"); 

      if (infoProperty != null) 
      { 
       PdfDocument.PdfInfo pdfInfo = (PdfDocument.PdfInfo)infoProperty.GetValue(pd); 

       if (pdfInfo != null) 
       { 
        string creator = pdfInfo.GetAsString(new PdfName("Producer")).ToLowerInvariant(); 

     if(creator.Contains("itextsharp")) 
     { 
      // created with itext sharp 
     } 
     else if(creator.Contains("adobe")) 
     { 
      // created with adobe something (distiller, photoshop, whatever) 
     } 
     else if(creator.Contains("pdfpro")) 
     { 
      // created with pdf pro 
     } 
     else if(add your own comparison here, for example a scanner manufacturer software like HP's one) 
     { 
     } 
       } 
      } 
     } 
} 
+0

那么问题的答案在哪里?你能解释一下吗? – NREZ

+0

抱歉,我把它粘贴在错误的线程中,但解释一下呢? 但是,您可以使用此代码进行小改编,以确定它是如何创建的,更新了上面的代码。 – coloboxp

相关问题