01.
<?php
02.
03.
function
expandDirectories(
$base_dir
)
04.
{
05.
$directories
=
array
();
06.
foreach
(scandir(
$base_dir
)
as
$file
)
07.
{
08.
if
(
$file
==
'.'
||
$file
==
'..'
)
continue
;
09.
$dir
=
$base_dir
.DIRECTORY_SEPARATOR.
$file
;
10.
if
(
is_dir
(
$dir
))
11.
{
12.
$directories
[] =
$dir
;
13.
$directories
=
array_merge
(
$directories
, expandDirectories(
$dir
));
14.
}
elseif
(
end
(
explode
(
"."
,
end
(
explode
(
"/"
,
$dir
)))) ==
'pdf'
)
15.
{
16.
17.
$filename
=
explode
(
"."
,
end
(
explode
(
"/"
,
$dir
)))[0];
18.
$dirname
=
"PDF/test.pdf"
.
$filename
.
".pdf"
;
19.
try
20.
{
21.
$command
=
"pdftotext -enc UTF-8 -nopgbrk "
.
str_replace
(
" "
,
"\ "
,
$dir
) .
" pdftotxt/"
.
$filename
.
".txt"
;
22.
echo
$command
.
"\n"
;
23.
shell_exec(
$command
);
24.
25.
}catch (Exception
$e
)
26.
{
27.
echo
"error \n"
;
28.
}
29.
}
30.
}
31.
return
$directories
;
32.
}
33.
34.
$directories
= expandDirectories(dirname(
__FILE__
));
35.
36.
?>
37.
38.
เอาไปใช้ยังไงครับ พอผมรันหน้านี้แล้วมัน error ครับ
39.
Notice: Only variables should be passed by reference in C:\xampp\htdocs\know_how\pdt_to text.php on line 14
40.
41.
Notice: Only variables should be passed by reference in C:\xampp\htdocs\know_how\pdt_to text.php on line 17
42.
pdftotext -enc UTF-8 -nopgbrk C:\xampp\htdocs\know_how\PdfToText\examples\image-extraction\sample.pdf pdftotxt/C:\xampp\htdocs\know_how\PdfToText\examples\image-extraction\sample.txt