我正在尝试检测图层并从PDF文档中提取它们。 好吧,我找不到任何关于检测它们的主题,只能找到如何创建它们。 这似乎对我有用。使用SetaPDF和FPDF尝试但无法获取图层。有任何想法吗?
提前致谢。
托马斯
答案 0 :(得分:0)
要访问PDF文档的图层,您可以使用SetaPDF-Core组件(我们的产品不是免费的!)。通常在GUI界面中显示的所有图层的简单迭代如下所示:
require_once 'SetaPDF/Autoload.php';
$document = SetaPDF_Core_Document::loadByFilename('paht/to/the.pdf');
$oc = $document->getCatalog()->getOptionalContent();
$iterator = $oc->getIterator();
foreach ($iterator AS $entry) {
echo $iterator->getDepth() . ' ';
echo str_repeat(' ', $iterator->getDepth() * 4);
if ($entry instanceof SetaPDF_Core_Document_OptionalContent_Group) {
echo 'Layer: ' . $entry->getName();
} elseif ($entry instanceof SetaPDF_Core_Type_StringValue) {
echo '<i>Label: ' . SetaPDF_Core_Encoding::convertPdfString($entry->getValue()) . '</i>';
}
echo '<br />';
}
无论如何实际上不可能隔离特定图层的内容并创建它的新文档。
可以通过usage()
方法访问状态:
$viewsState = $entry->usage()->getViewState();