xpdf pdfinfo 결과 파싱 함수(parsing function)
● pdfinfo parsing 결과 파싱
이 함수는 응용해서 여러가지로 사용할 수 있습니다. http 헤더에 대한것도 일부 가능할것으로 보이고 라인단위로 분리한 다음 구분자를 기준으로 한번더 분리하여 그것을 배열로 리턴해 주는 그런 함수 입니다.
# ./tt.php get_data
if ( $MODE == 'get_data' )
{
# 아래 결과로 나온 결과이다.
# [root@pabburi /xpdf] xpdf-tools-linux-4.03/bin64/pdfinfo test.pdf
$str = "
Author: 01
Creator: QuarkXPress(MAC): LaserWriter 8 KH-8.7.1
Producer: Acrobat Distiller 5.002001-01-22:00 for Macintosh
CreationDate: Sun Apr 30 18:16:52 2006
ModDate: Sun Apr 30 18:16:52 2006
Tagged: no
Form: none
Pages: 24
Encrypted: no
Page size: 595 x 842 pts (A4) (rotated 270 degrees)
File size: 5357040 bytes
Optimized: yes
PDF version: 1.3
";
$aPdfinfo = get_str_explode_keyval_array( $str );
if ( $aPdfinfo ) {
extract($aPdfinfo);
print_r($aPdfinfo);
}
}
/**
* 문자열 분리하여 배열로 리턴
*/
function get_str_explode_keyval_array( $str, $gstr1="\n", $gstr2=':', $mode='notSpace')
{
$aRst = array();
$aTemp = explode($gstr1, $str);
foreach( $aTemp as $idx => $val ) {
$val = trim($val);
if ( !$val ) continue;
$aTemp2 = explode($gstr2, $val);
$aTempT = $aTemp2;
unset($aTempT[0]);
$rKey = $aTemp2[0];
$rVal = implode(':', $aTempT);
if ( $mode == 'notSpace' ) {
$rKey = str_replace(' ', '_', $rKey);
}
$aRst[$rKey]= trim($rVal);
}
return $aRst;
}
* 결과
Array
(
[Author] => 01
[Creator] => QuarkXPress(MAC): LaserWriter 8 KH-8.7.1
[Producer] => Acrobat Distiller 5.002001-01-22:00 for Macintosh
[CreationDate] => Sun Apr 30 18:16:52 2006
[ModDate] => Sun Apr 30 18:16:52 2006
[Tagged] => no
[Form] => none
[Pages] => 24
[Encrypted] => no
[Page_size] => 595 x 842 pts (A4) (rotated 270 degrees)
[File_size] => 5357040 bytes
[Optimized] => yes
[PDF_version] => 1.3
)
