2013-05-30 48 views
14

で生成されたpdfファイルの向きをどのように変更できますか。私は、次のようにPHPでそれを呼び出す:wkhtmltopdfを使用して横向きを設定する

$file = fopen("tmp/html/pdfTmp_$numRand.html", 
    "w") or exit("Unable to open file!"); 
fwrite($file, $html); 
fclose($file); 

exec("..\library\wkhtmltopdf\wkhtmltopdf " . 
    "tmp/html/pdfTmp_$numRand.html tmp/pdf/pdfTmp_$numRand.pdf"); 

header('Content-Description: File Transfer'); 
header('Content-Type: application/octet-stream'); 
header("Content-Disposition: attachment; filename=".$nom."_".$residence.".pdf"); 
header('Content-Transfer-Encoding: binary'); 
header('Expires: 0'); 
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
header('Pragma: public'); 
header('Content-Length: ' . filesize("tmp/pdf/pdfTmp_$numRand.pdf")); 
ob_clean(); 
flush(); 
readfile("tmp/pdf/pdfTmp_$numRand.pdf"); 

$htmlは、HTMLでの私の全体のページが含まれており、これは一時的なファイルを開きます。

これにより、縦向きの.pdfが生成されます。 wkhtlktopdfにはオリエンテーションを変更するオプション-O landscapeがありますが、私はPHPスクリプトでこれをどこでどのように書くことができるのか分かりません。私はWindows 7を使用しています。

+0

wkhtmltopdfコマンドの直後に '-O landscape'という2つのフラグを渡します。例えば、' wkhtmltopdf -O landscape foobar.html foobar.pdf' –

答えて

24

オプション-O landscapeはトリックを行います。

ただ、私は、これはまた、ここに言及する価値があると思い

exec("..\library\wkhtmltopdf\wkhtmltopdf -O landscape tmp/html/pdfTmp_$numRand.html tmp/pdf/pdfTmp_$numRand.pdf"); 
+1

うん、それは本当に簡単でした!ありがとうございました。 – Daykeras

0

のようなものに

exec("..\library\wkhtmltopdf\wkhtmltopdf tmp/html/pdfTmp_$numRand.html tmp/pdf/pdfTmp_$numRand.pdf"); 

をチャゲ:

私もこれで問題を抱えていたが、私は--orientation設定していました"Landscape"と設定していた - ページ高さ '210mm'と - ページ幅 '297mm'

私のpdfはポートレートで出てきて、非常にイライラしました。

私はあまりにも明白でした。 page-heightとpage-widthオプションを使って私の問題を解決しました

+0

リトルロジックトラップがあります。あなたの幅があなたの高さよりも大きい場合、Landscapeは、(幅と高さを入れ替えるので)縦向きのように見えます。 – DylanYoung

関連する問題