簡體   English   中英

PHP:從 PDF 獲取附件文件

[英]PHP: Get attachment file from PDF

如何從 PDF 文件中提取附件? 我正在閱讀的 PDF 附有一個 XML 文件,但我找不到獲取它們的方法。

我最終安裝了具有命令 pdfdetach 的 poppler-utils

通過使用核心 PHP:

#$file_path = absolute file path
#$attachment_extension = attachment extension eg. xml

$content = @file_get_contents($file_path, FILE_BINARY);

preg_match_all('/Type\/Filespec\/UF\((.*?)\)>>/', $content, $match);

$file_names = $match[1];
preg_match_all("#$attachment_extension>>stream(.*)endstream#ismU", $content, $attachments); 
$attachments = $attachments[1];

for($i=0; $i < count($attachments); $i++){
    $final_attrs[$file_names[$i]] = @gzuncompress(trim($attachments[$i]));  
}

#$final_attrs this is the array of files.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM