[英]sample php code to convert pdf file to html
我想要一個PHP示例代碼將我的pdf轉換為html輸出
請嘗試所有解決方案,但找不到能滿足我需求的解決方案。
生病只想要從pdf到html的相同輸出
提前致謝
1)下載.exe文件並將其解壓縮到以下文件夾中: http : //sourceforge.net/projects/pdftohtml/
2)創建一個.php文件,並放置以下代碼(假設pdftohtml.exe位於該文件夾內,同時也包含源sample.pdf):
<?php
$source_pdf="sample.pdf";
$output_folder="MyFolder";
if (!file_exists($output_folder)) { mkdir($output_folder, 0777, true);}
$a= passthru("pdftohtml $source_pdf $output_folder/new_file_name",$b);
var_dump($a);
?>
3)輸入MyFolder ,您將看到轉換后的文件(取決於頁數。)
ps我不知道,但是也有很多商業或試用版api。
解決信貸@從T.Todua 這里
<?php
$c = curl_init();
$cfile = curl_file_create('test.pdf', 'application/pdf');
$apikey = 'YOUR_API_KEY'; // from https://pdftables.com/api
curl_setopt($c, CURLOPT_URL, "https://pdftables.com/api?key=$apikey&format=html");
curl_setopt($c, CURLOPT_POSTFIELDS, array('file' => $cfile));
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_FAILONERROR,true);
curl_setopt($c, CURLOPT_ENCODING, "gzip,deflate");
$result = curl_exec($c);
if (curl_errno($c) > 0) {
print('Error calling PDFTables: '.curl_error($c).PHP_EOL);
} else {
// save the HTML we got from PDFTables to a file
file_put_contents ("test.html", $result);
}
curl_close($c);
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.