0

次のスニペットは「http://pdfx.cs.man.ac.uk/usage」からのものです。この非常に優れたツールで、pdf の科学論文を xml に変換します。

curl --data-binary @"/path/to/my.pdf"
     -H "Content-Type: application/pdf" 
     -L "http://pdfx.cs.man.ac.uk"

このコードは UNIX コマンド ライン コードであり、その PHP バージョンが必要です。私が試してみました

$pdfFile = fopen('jucs_18_05_0623_0649_hasan.pdf', 'r');
$fileSize = filesize ('jucs_18_05_0623_0649_hasan.pdf');
$url="http://pdfx.cs.man.ac.uk";
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_INFILE, $pdfFile);
curl_setopt($ch, CURLOPT_INFILESIZE, $fileSize);
curl_setopt($ch, CURLOPT_VERBOSE, true);

$fp = fopen("test.xml", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);

if (! $res = curl_exec($ch))
    echo "Error: ".curl_error($ch);
else {
    echo "Success";
}   
curl_close($ch);

問題は、test.xml への出力が、提供された記事の変換された xml バージョンではなく、インデックス ファイルの html コードであることです。

専門家の意見をお待ちしています...

前もって感謝します

4

1 に答える 1

1

置く必要はありません。content-length が必要です。

<?php
$pdfFile = fopen('1.pdf', 'r');
$fileSize = filesize ('1.pdf');
$url="http://pdfx.cs.man.ac.uk";
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/pdf","Content-length: ".$fileSize));
curl_setopt($ch, CURLOPT_INFILE, $pdfFile);
curl_setopt($ch, CURLOPT_INFILESIZE, $fileSize);
curl_setopt($ch, CURLOPT_VERBOSE, true);

$fp = fopen("test.xml", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);

if (! $res = curl_exec($ch))
    echo "Error: ".curl_error($ch);
else {
    echo "Success";
}
curl_close($ch);
?>
于 2012-10-04T13:19:59.450 に答える