1

I require make mediantes reports query the database, so my idea is to write "text" in a PDF with the model view controller know how to perform queries and this is the code I use the controller to generate the PDF

public function mensualAction() {

    //Para cargar la librería:
    require_once 'Zend/Pdf.php';
    require_once 'Zend/Loader/Autoloader.php';

    //Para crear un nuevo documento PDF:
    $pdf = new Zend_Pdf();

    //Para crear una nueva página:
    $pdf->pages[] = ($page = $pdf->newPage('A4'));
    $pdf->pages[] = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
    $pdf->pages[] = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);

    //Obtener ancho y alto de la página:
    $ancho = $page->getWidth();
    $alto = $page->getHeight();

    //Usar estilos:
    $estilo = new Zend_Pdf_Style();
    $estilo->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));
    $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
    $estilo->setFont($font, 10);
    $estilo->setStyle($style);

    //Escribir texto:
    $page->drawText("Hola Mundo", $x, $y);

    //Insertar imágenes:
    //$img = Zend_Pdf_ImageFactory::factory('sentidoweb.png');
    //$page->drawImage($img, $x, $y, $x+&ancho, $y+$alto);
    //Devolver la salida:
    echo $pdf->render();

    //Eso sí, antes hay que tener en cuenta que tenemos que devolver al inicio del script el Content-Type:

    header("Content-Type: application/pdf");
    // Si queremos que se devuelva como un fichero adjunto
    header("Content-Disposition: attachment; filename=\"prueba.pdf\"");
}

Error in browser:

 Fatal error: Call to undefined method Zend_Pdf_Style::setStyle() in ../application/controllers/ReportesController.php on line 32

Line 32:

$estilo->setStyle($style);
Jhosman
  • 555
  • 2
  • 8
  • 20

1 Answers1

0

I have two comments:
1 - $style is not defined.
2 - setStyle() is not a method of Zend_Pdf_Style.

However, SetStyle() is a method of Zend_Pdf_Canvas_Abstract and Zend_Pdf_Page extends Zend_Pdf_Canvas_Abstract.

So maybe what you want to do is:

 $page->setStyle($estilo);

I hope it will help. :)

doydoy44
  • 5,720
  • 4
  • 29
  • 45