Forum How do I...?

Prince within Laravel

vcatlan
I would just like to know if anyone has tried to integrate Prince withing the Laravel framework? That's the framework i am currently working on and i am looking at trying to get it working on it. Has anyone experienced any problems or any thoughts you might want to share before i start digging.
Also i am running on a Windows machine.

Thanks
mikeday
I'm not familiar with Laravel, but if it's PHP-based then you would want to start with the Prince PHP wrapper. If you need help capturing HTML output to pass to Prince, then you will probably need to ask on the Laravel forums.
vcatlan
Well i got it working to convert a simple html string to pdf. But now if i have a whole php file, for example student.blade.php how would i get to convert the contents of that page exactly how it looks? Would it be easier to user the url based approach?

Edited by vcatlan

mikeday
You could try using Prince to retrieve the URL, or you could can use ob_start() and ob_get_clean() to capture the output from a PHP page and pass it to Prince with convert_sting_to_passthru().
vcatlan
I can capture the output just fine with the ob_start(). Problem is that when it tries to access the js scripts and css links they have a https url and it complains about the certificate not being trusted. Even with the Insecure set to true. If i take the html head part out it outputs the pdf file but that page doesn't look right..
<?php
use PrinceXMLPhp\PrinceWrapper;
function callback($buffer) {
	$prince = new PrinceWrapper ( "C:\Program Files (x86)\Prince\Engine\bin\prince" );
	$prince->setInsecure ( true );
	$prince->setHTML ( true );
	$prince->setInputType ( "html" );
	
	$prince->setLog ( "log.txt" );
	$prince->setFileRoot ( "points to public root folder" );
	$prince->addStyleSheet ( "css\bootstrap\css\bootstrap.min.css" );
	$prince->addStyleSheet ( "css\global.css" );
	$prince->addScript("js\phdm-app.js");
	$prince->setJavaScript ( true );
	
	$file = "phpOutput.txt";
	file_put_contents ( $file, $buffer, FILE_APPEND | LOCK_EX );
	
	//header ( 'Content-Type: application/pdf' );
	//header ( 'Content-Disposition: attachment; filename="test.pdf"' );
	
	$convert = $prince->convert_string_to_file ( $buffer, "test.pdf" );
	// $prince->convert_string_to_passthru(ob_get_contents());
}

ob_start ( "callback" );
?>

<html> 

all my page code is here 

</html>

<?php
ob_end_clean();
?>

Edited by vcatlan

mikeday
You might want to try the latest Prince alpha, which has updated SSL support which should hopefully fix the certificate issue.