// your dompdf setup
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
// add the header
$canvas = $dompdf->get_canvas();
$font = Font_Metrics::get_font("helvetica", "bold");
// the same call as in my previous example
$canvas->page_text(72, 18, "Header: {PAGE_NUM} of {PAGE_COUNT}",
$font, 6, array(0,0,0));
# Instanciamos un objeto de la clase DOMPDF.
$dompdf = 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.
$dompdf->set_paper("Letter", "portrait");
# Cargamos el contenido HTML.
$dompdf->load_html(utf8_decode($html));
# Renderizamos el documento PDF.
$dompdf->render();
#Esto es lo que imprime en el PDF el numero de paginas
$canvas = $dompdf->get_canvas();
$footer = $canvas->open_object();
$w = $canvas->get_width();
$h = $canvas->get_height();
$canvas->page_text($w-60,$h-28,"Página {PAGE_NUM} de {PAGE_COUNT}", Font_Metrics::get_font('helvetica'),6);
$canvas->page_text($w-590,$h-28,"El pie de página del lado izquiero, Guadalajara, Jalisco C.P. XXXXX Tel. XX (XX) XXXX XXXX", Font_Metrics::get_font('helvetica'),6);
$canvas->close_object();
$canvas->add_object($footer,"all");
# Enviamos el fichero PDF al navegador.
//$dompdf->stream('FicheroEjemplo.pdf');
# Para grabar en fichero en ruta especifica
$output = $dompdf->output();
file_put_contents('ejemplo.pdf',$output);
#Liberamos
unset($dompdf);
5条答案
按热度按时间e5nszbig1#
在0.6.0代码中,您将能够使用HTML+CSS来生成页眉和页脚。与使用内联PHP相比,有一些限制(例如还没有PAGE_COUNT占位符),因此这是否可行取决于您的需要。
下面的代码将生成一个two-page document with a header and footer:
如果需要访问某些缺少的功能,也可以组合使用这两种样式。使用
page_text
方法添加的PDF对象和文本呈现在HTML内容的顶部。whlutmcx2#
在DOMPDF wiki上有一个FAQ条目:* 是否有方法添加页眉和页脚或页码?*.
因此,您可以将以下“inline PHP”-snippet添加到您的HTML-input(为您的页脚添加类似的
page_text
-call):如果你想在你的调用端实现它(直接在PHP代码中),你必须调用DOMPDFS的
get_canvas()
-方法,它返回底层的PDF-Renderer,允许你像上面的例子一样调用page_text
方法。让我告诉你我的意思:最后,您必须在
load_html
之后调用page_text
(只需尝试一下)。ztyzrc3y3#
如果你想得到类似的东西:
定义如下,页眉,页脚和文档的内容:
bq8i3lrv4#
你需要这个代码,希望对你有帮助
问候...
daolsyd05#
用刀片只与这样的东西
在此之后,将在每个PDF中呈现标题
记住!标记头必须在主体上,在标记main之前