我有下面的方法应该返回 PDF 中的层数,但它似乎不起作用。当我将路径传递给包含两个图层的 PDF 文件时,图层计数属性的值为 1。我通过两个不同的 PDF 阅读器确认 PDF 中有两个图层。我唯一的想法是 ABCPDF 在阅读过程中将 PDF 图层展平。如果是这样,我怎样才能防止返回 PDF 中层数的准确计数?
谢谢
public static int GetPDFLayerCount(string pdfFile)
{
int layerCount = 0;
Doc doc = new Doc();
doc.SetInfo(0, "License", _License);
// Attempt to read File
try
{
if (System.IO.File.Exists(pdfFile) == false)
{
throw new ApplicationException("File does not exist.");
}
doc.Read(pdfFile);
layerCount = doc.LayerCount;
doc.Clear();
doc.Dispose();
}
catch (Exception ex)
{
System.ApplicationException appException = new ApplicationException(ex.Message + "\r\n\r\n" + pdfFile,ex);
throw appException;
}
return layerCount;
}