https://pdfcrowd.com/doc/api/client-library/php/
Convertir una url en un PDF:
require 'pdfcrowd.php';
try
{
// create an API client instance
$client = new Pdfcrowd("xxx", "xxxx");
// convert a web page and store the generated PDF into a $pdf variable
$pdf = $client->convertURI('http://www.midominio.com/');
// set HTTP response headers
header("Content-Type: application/pdf");
header("Cache-Control: max-age=0");
header("Accept-Ranges: none");
header("Content-Disposition: attachment; filename=\"result.pdf\"");
// send the generated PDF
echo $pdf;
}
catch(PdfcrowdException $why)
{
echo "Pdfcrowd Error: " . $why;
}
Convertir tu propio código HTML en PDF:
require 'pdfcrowd.php';
try
{
// create an API client instance
$client = new Pdfcrowd("xxx", "xxxx");
//$client->setPageLayout(2);
$client->setPageHeight(-1); // para q no ponga el num pag
// convert a web page and store the generated PDF into a $pdf variable
//$pdf = $client->convertURI('http://www.tspplus.com/test/header.php');
//$client->setHeaderUrl('http://www.tspplus.com/test/header.php');
// set HTTP response headers
header("Content-Type: application/pdf");
header("Cache-Control: max-age=0");
header("Accept-Ranges: none");
header("Content-Disposition: attachment; filename=\"result.pdf\"");
$pdf_content = "";
for ($i=1;$i<100;$i++) {
$pdf_content .= "<p style='border: solid 1px black;'>Linea de relleno ".$i."</p>";
}
$pdf = $client->convertHtml("<head></head><body>".$pdf_content."</body>");
// send the generated PDF
echo $pdf;
}
catch(PdfcrowdException $why)
{
echo "Pdfcrowd Error: " . $why;
}
No hay comentarios:
Publicar un comentario