2017-05-17 1 views
0

PHP 페이지에서 PDF를 생성하려고합니다. 나는 아래와 같은 코드를 가지고 있으며 작동한다. 그러나 ob_get_clean()을 사용하려고 할 때 다른 사람이 본 것처럼 500 개의 오류가 발생합니다.PHP에서 생성 된 후 웹 페이지의 DOM/HTML 가져 오기

다른 방법으로 아이디어를 완성 된 페이지를 얻을 수 있습니까? Javascript가 작동합니까?

다른 문제는 페이지가 로그인해야하며 페이지를 쉽게 포착 할 수 없도록 POST 양식에 의해 생성된다는 것입니다.

</html> 
<?php 
$content = "This will work";//ob_get_clean(); 
require_once dirname(__FILE__).'/html2pdf/vendor/autoload.php'; 

use Spipu\Html2Pdf\Html2Pdf; 
use Spipu\Html2Pdf\Exception\Html2PdfException; 
use Spipu\Html2Pdf\Exception\ExceptionFormatter; 

try { 

    //ob_clean(); 
    $html2pdf = new Html2Pdf(); 
    $html2pdf->writeHTML($content); 
    $html2pdf->Output($_SERVER['DOCUMENT_ROOT'] . '/output.pdf', 'F'); 
} catch (Html2PdfException $e) { 
    $formatter = new ExceptionFormatter($e); 
    echo $formatter->getHtmlMessage(); 
} 


?> 
+0

500이면 오류가 error_log에 있습니다. 그것은 무엇을 말하는가? – delboy1978uk

+0

아무 것도 보지 못했습니다. –

+0

phpinfo()를 점검하고 error_log가 설정된 위치를 확인하십시오. 스크립트의 ini_set을 사용하여 사용자 정의 매개 변수를 설정할 수도 있습니다. 또한 error_reporting이 -로 설정되었는지 확인하고 다시 시도하십시오. – delboy1978uk

답변

0

서버가 fopen을 허용하는 경우 that question in Stack처럼 당신은 file_get_contents를 사용하거나 (나를 위해 보편적이고 가장 좋은 방법) CURL를 사용

</html> 
<?php 
require_once dirname(__FILE__).'/html2pdf/vendor/autoload.php'; 
$content = file_get_contents('yourphppage.php'); //first option 
//OR CURL MODE 
$c = curl_init('yourpage.php'); 
curl_setopt($c, CURLOPT_RETURNTRANSFER, true); 
//curl_setopt(... other options you want...) 

$content = curl_exec($c); 

if (curl_error($c)) 
    die(curl_error($c)); 

// Get the status code 
$status = curl_getinfo($c, CURLINFO_HTTP_CODE); 

curl_close($c); 
//execute your code bellow checking $status of cURL, else thrown an error 

use Spipu\Html2Pdf\Html2Pdf; 
use Spipu\Html2Pdf\Exception\Html2PdfException; 
use Spipu\Html2Pdf\Exception\ExceptionFormatter; 

try { 

    //ob_clean(); 
    $html2pdf = new Html2Pdf(); 
    $html2pdf->writeHTML($content); 
    $html2pdf->Output($_SERVER['DOCUMENT_ROOT'] . '/output.pdf', 'F'); 
} catch (Html2PdfException $e) { 
    $formatter = new ExceptionFormatter($e); 
    echo $formatter->getHtmlMessage(); 
} 

?> 

또는 당신은 스택에 that example 같은 jsPDF를 사용하여 자바 스크립트를 사용할 수 있습니다

var doc = new jsPDF(); 

// We'll make our own renderer to skip this editor PS: An example if you want to take out some elements from the renderer 
var specialElementHandlers = { 
    '#editor': function(element, renderer){ 
     return true; 
    } 
}; 

// All units are in the set measurement for the document 
// This can be changed to "pt" (points), "mm" (Default), "cm", "in" 
doc.fromHTML($('body').get(0), 15, 15, { 
    'width': 170, 
    'elementHandlers': specialElementHandlers 
}); 
관련 문제