I do not generate the pdf I want in Google Chrome

-1

I have a little problem with the FPDF tool on my website, the thing is that localhost everything works perfectly, but by taking my php to the online hosting and requesting the pdf the page is completely blank, without printing any results or error.

my php code is as follows:

 <?php

require('fpdf.php');



$pdf=new FPDF();

$pdf->AddPage();



$pdf->Line(20,20,190,20);


$pdf->Image('../imagenes/logo.png',10,6,30);
$pdf->SetFont('Helvetica','B',35);

$pdf->Cell(0,40,'ORDEN DE COMPRA',0,1,'C');



$pdf->Line(20,38,190,38);

$pdf->Rect(20,38,100,14);

$pdf->Rect(120,38,70,14);



$conexion = mysqli_connect('localhost','id5532765_martita_admin','969895752','id5532765_martita');



$compras=mysqli_query($conexion, "SELECT cliente.nombres,apellidos, compras.num_venta,nombre,imagen,cantidad,precio,psubtotal,fecha,direccion,celular FROM cliente INNER JOIN compras ON cliente.id_usuario=compras.id_usuario WHERE num_venta=".$_GET['num_venta']);

$numeroventa=0;

while ($row=mysqli_fetch_array($compras)){

if($numeroventa!=$row['num_venta']){

$pdf->SetFont('Helvetica','B',23);

$pdf->Cell(12);

$pdf->Cell(0,-9,utf8_decode('PEDIDO N°'.$row['num_venta']),0,1,'L');



$pdf->SetFont('Helvetica','B',23);

$pdf->Cell(125);

$pdf->Cell(0,9,utf8_decode($row['fecha']),0,1,'L');



//Nombre

$pdf->SetFont('Helvetica','B',14);

$pdf->Cell(10);

$pdf->Cell(0,25,utf8_decode("SOLICITADO(A) POR:"),0,1,'L');



$pdf->Rect(75,58,115,8);

$pdf->SetFont('Helvetica','',14);

$pdf->Cell(67);

$pdf->Cell(0,-25,utf8_decode($row['nombres']."\n".$row['apellidos']),0,1,'L');



//Direccion

$pdf->SetFont('Helvetica','B',14);

$pdf->Cell(10);

$pdf->Cell(0,49,utf8_decode("DIRECCIÓN:"),0,1,'L');



$pdf->Rect(52,70,138,8);

$pdf->SetFont('Helvetica','',14);

$pdf->Cell(43);

$pdf->Cell(0,-49,utf8_decode($row['direccion']),0,1,'L');



//Celular

$pdf->SetFont('Helvetica','B',14);

$pdf->Cell(10);

$pdf->Cell(0,73,utf8_decode("CELULAR O TELÉFONO DE REFERENCIA:"),0,1,'L');



$pdf->Rect(124,82,66,8);

$pdf->SetFont('Helvetica','',14);

$pdf->Cell(115);

$pdf->Cell(0,-73,utf8_decode($row['celular']),0,1,'L');



$pdf->Ln(44);

//Comentario



//Tabla

$pdf->Ln(22);

$pdf->SetFont('Helvetica','B',11);

$pdf->Cell(11,5,'',0,'C',false);

$pdf->Cell(85,10,utf8_decode("DESCRIPCIÓN DEL PRODUCTO"),1,0,'L',false);

$pdf->Cell(17,10,'CANT.',1,0,'C',false);

$pdf->Cell(32,10,'PRECIO UNIT.',1,0,'C',false);

$pdf->Cell(35,10,'PRECIO TOTAL',1,0,'C',false);



}

$numeroventa=$row['num_venta'];

//Parte de los detalles

$pdf->SetFont('Helvetica','',10);

$pdf->Ln(10);

$pdf->Cell(11,5,'',0,'C',false);

$pdf->Cell(85,10,utf8_decode($row[3]),1,0,'L',false);

$pdf->Cell(17,10,$row[5],1,0,'C',false);

$pdf->Cell(32,10,'S/.'.number_format($row[6], 2, '.', ''),1,0,'R',false);

$pdf->Cell(35,10,'S/.'.number_format($row[7], 2, '.', ''),1,0,'R',false);

}



$conexion = mysqli_connect('localhost','id5532765_martita_admin','969895752','id5532765_martita');



$sumar=mysqli_query($conexion, "SELECT SUM(psubtotal) AS suma FROM compras WHERE num_venta=".$_GET['num_venta']);

while($row=mysqli_fetch_array($sumar)){

//Total

$pdf->SetFont('Helvetica','B',11);

$pdf->Ln(10);

$pdf->Cell(11,5,'',0,'C',false);

$pdf->Cell(134,10,'TOTAL A PAGAR:',1,0,'C',false);

$pdf->SetFont('Helvetica','',10);

$pdf->Cell(35,10,'S/.'.number_format($row['suma'], 2, '.', ''),1,0,'R',false);

}



$conexion = mysqli_connect('localhost','id5532765_martita_admin','969895752','id5532765_martita');



$compras=mysqli_query($conexion, "SELECT cliente.nombres,apellidos, compras.num_venta,nombre,imagen,cantidad,precio,psubtotal,fecha,direccion,celular FROM cliente INNER JOIN compras ON cliente.id_usuario=compras.id_usuario WHERE num_venta=".$_GET['num_venta']);

$numeroventa=0;

while ($row=mysqli_fetch_array($compras)){

if($numeroventa!=$row['num_venta']){

$pdf->Output('I', utf8_decode('PEDIDO N°'.$row['num_venta'].'.pdf'));

}

}

?>
    
asked by Moises Rojas 22.12.2018 в 22:21
source

2 answers

0

From my experience, the problem with FPDF is that if "something" (whatever it is, even a blank space) has been sent to the browser before using the Output() method, it throws an error and does not show the pdf Probably, your hosting has disabled the output of errors, for security reasons (the directive display_errors of php.ini ). If it's a shared hosting, you can not change that configuration on the server, and the provider will not change it.

However, if there are several things you can do. The first thing is to start your code by changing that directive at run time, like this:

<?php
    ini_set('display_errors', 'On');

That activates the error display for that particular script. Check then if FPDF shows you an error saying that content has already been sent to the browser and can not generate the pdf. The error is in English, of course, but it is very easy to understand. I do not remember the exact phrase that appears, but the problem is understood from it.

If that is the problem (which is usually the most common), start by removing all unnecessary tab stops and line breaks in your code. For example (playing a fragment of your own code):

$pdf->Cell(35,10,'S/.'.number_format($row['suma'], 2, '.', ''),1,0,'R',false);

}



$conexion = mysqli_connect('localhost','id5532765_martita_admin','969895752','id5532765_martita');



$compras=mysqli_query($conexion, "SELECT cliente.nombres,apellidos, compras.num_venta,nombre,imagen,cantidad,precio,psubtotal,fecha,direccion,celular FROM cliente INNER JOIN compras ON cliente.id_usuario=compras.id_usuario WHERE num_venta=".$_GET['num_venta']);

Sutit it for:

$pdf->Cell(35,10,'S/.'.number_format($row['suma'], 2, '.', ''),1,0,'R',false);
}
$conexion = mysqli_connect('localhost','id5532765_martita_admin','969895752','id5532765_martita');
$compras=mysqli_query($conexion, "SELECT cliente.nombres,apellidos, compras.num_venta,nombre,imagen,cantidad,precio,psubtotal,fecha,direccion,celular FROM cliente INNER JOIN compras ON cliente.id_usuario=compras.id_usuario WHERE num_venta=".$_GET['num_venta']);

That solves most of the problems of this type (which, by the way, with FPDF have passed us all at the beginning).

One way to see if you are introducing line breaks is to right click on the blank page that comes out, and click on see the source code of the page. Once it opens, right click on the source code, and Select all. If you are selected, even if it is a space or a line break, you know where the problem comes from.

If you need any clarification, tell me, and I will try to help you.

    
answered by 23.12.2018 в 16:56
0

You entered the sentence

$pdf->Output('I', utf8_decode('PEDIDO N°'.$row['num_venta'].'.pdf')); 

Inside a loop.

The output must be unique and the last before ending the script or before a die:.

    
answered by 23.12.2018 в 17:23