有没有办法确定 PDF 文件的类型:现有 PDF 文件是扫描图像还是使用 iTextSharp 和 C# 从数据文件创建的?
问问题
2773 次
3 回答
0
也许您可以将一些元数据添加到您使用 iTextSharp 创建的 PDF 中。
于 2012-11-16T23:32:40.903 回答
-1
文档属性/高级/Pdf Producer
于 2012-11-16T23:28:23.520 回答
-1
在 PdfWriter 对象的监视窗口中搜索正确位置后,我刚刚使用此方法替换 PDF Producer,它更改了 PDF 中的“PDF Creator”,因为默认情况下无法访问:
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)
{
}
}
}
}
}
于 2013-08-16T11:23:08.947 回答