2013-05-30 2 views
14

Wkhtmltopdf으로 생성 된 내 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 PHP 스크립트로 이것을 작성할 수 있는지 알지 못한다. Windows 7을 사용하고 있습니다.

+0

wkhtmltopdf 명령 바로 다음에 두 개의 플래그'-O landscape'를 전달합니다. 예 :'wkhtmltopdf -O landscape foobar.html foobar.pdf' –

답변

24

옵션 -O landscape이 트릭을 수행합니다.

나도이에 문제가 있었다

하지만 설정했다 --orientation을 :

그냥 나는이 또한 여기에서 언급 할 가치가있다 생각

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"); 

을 CHAGE "가로"또한 - 페이지 높이 '210mm'와 - 페이지 너비 '297mm'를 설정했습니다.

내 pdf의 초상화가 계속 나오고 매우 실망 스럽습니다.

나는 너무 명백했습니다. 페이지 높이 및 페이지 너비 옵션을 사용하면 문제가 해결됨

+0

리틀 로직 트랩이 있습니다. 너비가 너비보다 큰 경우, 가로 방향은 너비와 높이를 바꾸기 때문에 세로 방향처럼 보입니다. – DylanYoung