C# 如何使用iTextSharp确定PDF文件类型
有没有办法确定PDF文件的类型:现有PDF文件是扫描图像还是使用iTextSharp和C从数据文件创建的 文档属性/Advanced/Pdf Producer也许您可以向使用iTextSharp创建的Pdf添加一些元数据C# 如何使用iTextSharp确定PDF文件类型,c#,pdf,itextsharp,C#,Pdf,Itextsharp,有没有办法确定PDF文件的类型:现有PDF文件是扫描图像还是使用iTextSharp和C从数据文件创建的 文档属性/Advanced/Pdf Producer也许您可以向使用iTextSharp创建的Pdf添加一些元数据 我刚刚使用此方法来替换PDF生成器,在PdfWriter对象的监视窗口中搜索了正确的位置后,它更改了PDF中的PDF创建者,因为默认情况下无法访问: private static void ReplacePdfCreator(PdfWriter writer)
我刚刚使用此方法来替换PDF生成器,在PdfWriter对象的监视窗口中搜索了正确的位置后,它更改了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)
{
}
}
}
}
}
我不创建它们-我在我的文件夹中获得了大量的它们,需要在不打开每个PDF的情况下确定它们。您的标准是什么?如何区分扫描仪的PDF和其他类型的文档?是印刷的字符数吗?是图像覆盖的页面面积吗?是创建PDF的程序的名称吗?iTextSharp可以帮助您确定这些值,但您必须事先提出标准。如何区分PDF和扫描仪…-你甚至不能选择文本hhmmm,事实并非如此。有一些扫描解决方案可以进行一些额外的OCR,然后通过不可见但可选择的文本来丰富扫描的PDF。另一方面,使用iTextSharp和C从数据文件创建PDF很容易,而不需要任何可选文本。那么,我能否解释您的问题,以便您真正想要区分有可选文本的PDF和没有可选文本的PDF?@ESB PdfTextExtractor.GetTextFromPage可以帮助您确定它是否包含任何文本。那么,问题的答案在哪里。。?你能解释一下吗…?我把它贴错了线对不起,但也解释一下什么?但是,您可以将此代码稍加修改,以确定它是如何创建、更新上述代码的。。