Прежде всего, извините за мой английский.с помощью DOMPDF для получения PDF-файла с помощью jQuery
Я пытаюсь создать pdf-файл с частью html, используя jQuery, Ajax и DomPDF.
В моей стороне сервера я использую следующий код:
require_once './dompdf/autoload.inc.php';
if(!empty($_GET['pdf'])){
$html=$_GET['pdf'];
# Instanciamos un objeto de la clase DOMPDF.
$mipdf = new Dompdf();
# Definimos el tamaño y orientación del papel que queremos.
# O por defecto cogerá el que está en el fichero de configuración.
$mipdf ->setPaper("A4", "portrait");
# Cargamos el contenido HTML.
$mipdf ->loadHtml(utf8_decode($html));
# Renderizamos el documento PDF.
$mipdf ->render();
# Enviamos el fichero PDF al navegador.
//$mipdf ->stream("Claustro.pdf");
echo base64_encode($mipdf->output());
}
В стороне клиента, в JQuery У меня есть:
$("#imprimir").click(function(){
console.log(datos);
$.ajax({
type: "GET",
dataType: 'text',
url: "./librerias/php/funciones.php",
data: {pdf:datos},
success: function(pdf) {
var modalWidth = $(window).width() - 400;
var modalHeight = $(window).height() - 400
var iframeWidth = modalWidth - 20;
var iframeHeight = modalHeight - 20;
$("#display_dialog").html('<iframe width="' + iframeWidth + '" height="' + iframeHeight + '" src="data:application/pdf;base64,' + pdf + '"></object>');
$("#display_dialog").dialog({
width: modalWidth,
height: modalHeight,
modal: true,
close: function(event, ui) {
$("#display_dialog").html("");
}
});
}
});
});//fin imprimir
У меня есть все HTML код в вар «Datos» Я хочу, чтобы в PDF.
Чтобы показать IFRAME У меня есть скрытый DIV:
<div id="display_dialog"></div>
, но я не могу получить PDF, The IFrame работает, но нет данных.
любое решение? Кто-нибудь может мне помочь? Спасибо всем!