How to cear several pages pdf in TCPDF in a dynamic way?

0

The detail is that I am creating pdf, through ids, which if I enter a single id, it creates the document all right with the information it needs but, when I pass two ids there generates the problem, because when I send them it seems to me in the following way:

Customer data Name: xxxxxxxxxxxxxxxxx surname: xxxxxxxxxxxx

Customer data Name: xxxxxxxxxxxxxxxxx surname: xxxxxxxxxxxx

Address street: xxxxxxxxxxxxxxx colony: xxxxxxxxx

Address street: xxxxxxxxxxxxxxx colony: xxxxxxxxx

and which I require that I leave as follows

Customer data Name: xxxxxxxxxxxxxxxxx surname: xxxxxxxxxxxx

Address street: xxxxxxxxxxxxxxx colony: xxxxxxxxx

Customer data Name: xxxxxxxxxxxxxxxxx surname: xxxxxxxxxxxx

Address street: xxxxxxxxxxxxxxx colony: xxxxxxxxx

I do not know if I made myself understood but they would be of great help if someone had handled the tcpdf library

public function impresion_masiva($ids){

        $ventas  = $this->ventasModel->getVentasExportar($ids);
        $partidas  = $this->ventasModel->getPartidasExportar($ids);
        $abonos = $this->ventasModel->getAbonosExportar($ids);
        $empresa = $this->configuracionesModel->getEmpresa();
        $rutas = $this->ventasModel->getRuta();

        foreach ($ventas as $row):
            $status = '';
            //condicion para tipo Estatus (1: Pedido / 2: Venta Abierta / 3: Venta Cerrada)
            if($row->ve_etapa ==1){
                $status = 'PEDIDO';
            }else if(($row->ve_etapa ==2 || $row->ve_etapa ==3)&&($row->ve_porcentaje_maquila==0 || $row->ve_porcentaje_abonos==0 || $row->ve_porcentaje_entrega==0)){
                $status = 'VENTA ABIERTA';
            }else if($row->ve_etapa==3 && $row->ve_porcentaje_maquila==1 && $row->ve_porcentaje_abonos==1 && $row->ve_porcentaje_entrega==1){
                $status = 'VENTA CERRADA';
            }

            //Condicion para el tipo de fecha
            if($row->ve_etapa==1){
                $tipoFecha = 'FECHA DE PEDIDO';
                $fecha = date("d/m/Y", strtotime($row->ve_fecha_pedido));
            }else if($row->ve_etapa==2){
                $tipoFecha = 'FECHA DE PEDIDO';
                $fecha = date("d/m/Y", strtotime($row->ve_fecha_pedido));
            }else if($row->ve_etapa==3){
                $tipoFecha = 'FECHA DE VENTA';
                $fecha = date("d/m/Y", strtotime($row->ve_fecha_venta));
            }



        define ('PDF_HEADER_LOGO', $empresa->em_logo);

        define ('PDF_HEADER_TITLE', $empresa->em_razon_social);

        define ('PDF_HEADER_STRING', "R.F.C. ".strtoupper($empresa->em_rfc)."\nC.U.R.P".strtoupper($empresa->em_curp)."\nTel./Fax ".$empresa->em_telefono."\n".$empresa->em_correo_ventas."\n".wordwrap($empresa->em_calle.' Nº '.$empresa->em_numero_exterior.' Col. '.$empresa->em_colonia.' '.$empresa->ci_nombre.', '.$empresa->es_nombre,48,"\n"));


        $leyenda = "NOTA: ESTE DOCUMENTO\nNO REPRESENTA UN COMPROBANTE FISCAL";
        $leyenda2 = "-SE FACTURA AL PAGO-";
        $firma = "FIRMA DE CONFORMIDAD____________________";

        define('PDF_HEADER_DATA', $status."\n# ".$row->ve_id_venta."\n\n".$tipoFecha."\n".$fecha);

        define('PDF_FOOTER_DATA', $leyenda);
        define('PDF_FOOTER_TITLE', $leyenda2);
        define('PDF_FOOTER_FIRMA', $firma);
        $this->load->library('Pdf');
        $pdf = new Pdf('P', 'mm', 'A5', true, 'UTF-8', false);
        $pdf->SetCreator(PDF_CREATOR);
        $pdf->SetAuthor('Ma.Concepción Hernández García');
        $pdf->SetTitle('Reporte PDF de Venta a '.date("Y-m-d h:m:s"));
        $pdf->SetSubject('Usuarios');
        $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
 tcpdf_config_alt.php de libraries/config
        $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING, PDF_HEADER_DATA);
        $pdf->setFooterData(PDF_FOOTER_DATA, PDF_FOOTER_TITLE, PDF_FOOTER_FIRMA);
        $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
        $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
        $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
        $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
        $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
        $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
        $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
        $pdf->setFontSubsetting(true);
        $pdf->SetFont('freemono', '', 14, '', true);
        $pdf->AddPage();
        $pdf->setTextShadow(array('disable' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));

        //$pdf->writeHTMLCell($w = 0, $h = 0, $x = '', $y = '', $html, $border = 0, $ln = 1, $fill = 0, $reseth = true, $align = '', $autopadding = true);

        $nombre_archivo = utf8_decode("Pedidos_".date("Ymdhms").".pdf");
        $pdf->Output($nombre_archivo, 'I');
        endforeach;
    
asked by Cesar Vieyra 20.07.2017 в 19:43
source

1 answer

0

The truth is that in the code I can not find where you write the data you comment, in fact, in your code you do not write anything in the PDF. Therefore I will give a generic answer.

The AddPage () method creates a new page, so you should simply put it as the first line in the loop.

$pdf->SetFont("","",12);
foreach($dataArray as $data) {
    $pdf->AddPage();
    $pdf->MultiCell(0, 6, $data);
}

This code will create a document with as many pages as elements have $ dataArray and in each one will come the text content with previous format that have the elements of $ dataArray.

    
answered by 27.09.2017 в 22:50