PHP: Вземете прикачен файл от PDF

Как мога да извлека прикачените файлове от PDF файл? PDF файловете, които чета, имат прикачен XML файл и не мога да намеря начин да ги получа.


person ColdFox    schedule 28.10.2015    source източник


Отговори (2)


В крайна сметка инсталирах poppler-utils, който има командата pdfdetach

person ColdFox    schedule 28.10.2015

Чрез използване на основния 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.

person SWAPNIL KUWAR    schedule 10.12.2020