rospdf / pdf-php

Official R&OS PHP Pdf repository
http://pdf-php.sourceforge.net/
Other
140 stars 63 forks source link

Adding the same image to different pages (PNG or JPEG) only works for the first image #162

Open RPort71 opened 2 years ago

RPort71 commented 2 years ago

I have a multi-page PDF that I am creating. When I use addPngFromFile or addJpegFromFile, only the first one appears. The subsequent ones do not appear.

If I comment out the first one, the second one works, but the subsequent ones do not. Is there a way around this? I tried creating the same image as a jpg and a png and using both, but still only get the first one.

anibaltillero commented 1 year ago

//////////////////////////////////////////////////////////////////////////////// // Function : uf_print_encabezado_pagina //
// Description: funcion que imprime los encabezados por pagina // Creado Por: Ing. Anibal Tillero // Fecha Creacion: 23/04/2023 //
// Access : private // Arguments: as_titulo // Titulo del Reporte // io_pdf // Instancia de objeto pdf // //////////////////////////////////////////////////////////////////////////////// function uf_print_encabezado_pagina($as_titulo, $pdf) { $all = $pdf->openObject(); $pdf->saveState(); $pdf->setStrokeColor(0,0,0,1);

if (file_exists('../imagenes/logo.png')){ $pdf->addpngFromFile('../imagenes/logo.png',20, 740, 125, 30 ); } $pdf->addText(25,736,7, $_SESSION['empresa'] ); $pdf->addText(25,710,10, "". strtoupper( $as_titulo ) ."");

$pdf->addText(470,730,7,  "<b>Fecha Impresión:</b>" . date("d/m/Y") );
$pdf->addText(480,720,7,  "<b>Hora Impresión :</b>"  . date("H:i:s") );

$pdf->line(30,30,578,30);

$pdf->restoreState();
$pdf->closeObject();
// termina las lineas
$pdf->addObject($all,'all');
//
//termina el objeto.
//

}// end function uf_print_encabezadopagina

ole1986 commented 1 year ago

Thank you for reporting and also providing an example code.

Trying to fix it asap

ole1986 commented 1 year ago

Sorry, I could not reproduce this with your function by using the below example code. Which version are you using?

<?php
set_include_path('../src/'.PATH_SEPARATOR.get_include_path());
date_default_timezone_set('UTC');

include 'Cezpdf.php';

$pdf = new Cezpdf('a4', 'portrait');

$pdf->ezSetMargins(20, 20, 20, 20);

$mainFont = 'Times-Roman';
// select a font
$pdf->selectFont($mainFont);
$size = 12;

function uf_print_encabezado_pagina($as_titulo, $pdf) {
    $all = $pdf->openObject();
    $pdf->saveState();
    $pdf->setStrokeColor(0,0,0,1);

    if (file_exists('./images/test_alpha.png')){
    $pdf->addpngFromFile('./images/test_alpha.png',20, 740, 125, 30 );
    }
    $pdf->addText(25,736,7, "TEST" );
    $pdf->addText(25,710,10, "". strtoupper( $as_titulo ) ."");

    $pdf->addText(470,730,7,  "<b>Fecha Impresión:</b>" . date("d/m/Y") );
    $pdf->addText(480,720,7,  "<b>Hora Impresión :</b>"  . date("H:i:s") );

    $pdf->line(30,30,578,30);

    $pdf->restoreState();
    $pdf->closeObject();
    // termina las lineas
    $pdf->addObject($all,'all');
}

uf_print_encabezado_pagina("TEST 123", $pdf);

$pdf->ezNewPage();

$pdf->ezText('Hello World');

if (isset($_GET['d']) && $_GET['d']) {
    echo $pdf->ezOutput(true);
} else {
    $pdf->ezStream(['compress' => 0]);
}