Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
RPort71 opened this issue Aug 9, 2022 · 3 comments

Comments

@RPort71
Copy link

RPort71 commented Aug 9, 2022

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
Copy link

anibaltillero commented Mar 28, 2023

////////////////////////////////////////////////////////////////////////////////
// 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
Copy link
Collaborator

ole1986 commented Apr 2, 2023

Thank you for reporting and also providing an example code.

Trying to fix it asap

@ole1986
Copy link
Collaborator

ole1986 commented Apr 11, 2023

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]);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants