Hola Buen día por primera vez estoy haciendo un pdf desde una tabla pero no me sale quise hacerlo de esta manera con este código
<div>
<div style="width: -10%; float:right">
<button id="imprimir" class="btn btn-info">Imprimir</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery.print/1.6.0/jQuery.print.min.js" integrity="sha256-s/wuIT+s0uE5Igk30VS2UAcs5Ck6SDt+iTlUzYQBn/4=" crossorigin="anonymous"></script>
<script>
$(document).ready(() => {
$('#imprimir').click(function() {
$.print('#imprimible');
});
});
</script>
</div>
</div>
Como se puede observar si imprime lo que quiero nada mas que sale con los botones entonces decidi hacerlo manualmente por medio de la libreria FPDF pero en la consulta me sale error esto es lo que llevo de código en el PDF
<?php
require('fpdf.php');
class PDF extends FPDF
{
// Cabecera de página
function Header()
{
// Logo
//IMAGE (RUTA,X,Y,ANCHO,ALTO,EXTEN)
// Arial bold 15
$this->SetFont('Arial','B',15);
// Movernos a la derecha
$this->Cell(90);
// Título
$this->Cell(90,12, utf8_decode('Hoja de Costos'),1,5,'C');
// Salto de línea
$this->Ln(25);
}
// Pie de página
function Footer()
{
// Posición: a 1,5 cm del final
$this->SetY(-15);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Número de página
// $this->Cell(0,10,utf8_decode('Página ').$this->PageNo().'/{nb}',0,0,'C');
}
}
include '../includes/db.php';
$folio_hoja= $_GET['folio_hoja'];
$emp_query = mysqli_query($conn,"SELECT * FROM hoja_costos
where folio_hoja='$folio_hoja' ");
$row= mysqli_fetch_assoc($emp_query);
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
while($row=$row->fetch_assoc()){
$pdf->Cell(10,10,$row['cantidad'],1,0,'C', 0);
$pdf->Cell(10,10, $row['descripcion'],1,0,'C', 0);
$pdf->Cell(10,10,$row['precio_refac'],1,0,'C', 0);
$pdf->Cell(10,10,$row['total_refac'],1,0,'C', 0);
$pdf->Cell(10,10, $row['mano_obra'],1,0,'C', 0);
$pdf->Cell(10,10,$row['importe_total'],1,0,'C', 0);
$pdf->Cell(10,10,$row['proveedor'],1,1,'C', 0);
}
$pdf->Output();
?>
ESTE ES EL CÓDIGO DE LA VENTANA DONDE QUIERO QUE SALGA EL PDF
<!DOCTYPE html>
<html>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<script src='https://kit.fontawesome.com/a076d05399.js' crossorigin='anonymous'></script>
<!--Get your own code at fontawesome.com-->
</head>
<?php
//activamos almacenamiento en el buffer
ob_start();
require 'header.php';
?>
<style>
.panel .form-group{
margin:unset;
}
.columna {
width:33%;
float:left;
}
@media (max-width: 500px) {
.columna {
width:auto;
float:none;
}
* {
margin:0;
padding:0;
}
#columna1 {
width:50%;
float:left;
font-size: 12px;
}
#columna2 {
width:50%;
float:right;
font-size: 12px;
}
#columna3 {
width:70%;
float:right;
font-size: 12px;
}
}
</style>
<div class="col-md-12">
<?php
include '../includes/db.php';
$folio_hoja= $_GET['folio_hoja'];
$emp_query = mysqli_query($conn,"SELECT * FROM hoja_costos
where folio_hoja='$folio_hoja' ");
$row= mysqli_fetch_assoc($emp_query);
?>
</div>
<div class="content-wrapper">
<!-- Main content -->
<section class="content">
<!-- Default box -->
<div class="col-md-13">
<div class="panel panel-default">
<br>
<div class="panel-body">
<div class="col-md-13">
<center>
<label class="control-label" style="font-size:25px !important">Detalle Hoja de Costos</label>
</center>
<br>
<form action="orden_entrada.php" method="get" align="right">
<input type="submit" value="Regresar"
name="Submit" class="btn btn-md btn-info" />
</form>
<br>
<hr style="border-bottom:1px solid black"></hr>
</div>
<div class="col-md-12">
<div class="row form-group">
<hr>
<div class="col-md-6">
<div class="row form-group" id="columna1">
<label class="control-label">Folio:</label>
<label class="control-label"><?php echo $row['folio_hoja'] ?></label>
</div>
<div class="row form-group" id="columna1">
<label class="control-label">Fecha:</label>
<label class="control-label"><?php echo $row['fecha'] ?></label>
</div>
<div class="row form-group" id="columna1">
<label class="control-label">VIN:</label>
<label class="control-label"><?php echo $row['VIN'] ?></label>
</div>
</div>
<div class="col-md-6">
<div class="row form-group" id="columna2">
<label class="control-label">Placas:</label>
<label class="control-label"><?php echo $row['placas'] ?></label>
</div>
<div class="row form-group" id="columna2">
<label class="control-label">KMS:</label>
<label class="control-label"><?php echo $row['kms']?></label>
</div>
<div class="row form-group" id="columna2">
<label class="control-label">Factura:</label>
<label class="control-label"><?php echo $row['factura']?></label>
</div>
<br>
<br>
</div>
</div>
<!-- COMIENZO TABLA -->
<table id="hoja" class="table table-bordered table-condensed">
<thead>
<tr id="heads">
<th class="col-md-1 text-center">Cantidad</th>
<th class="col-md-1 text-center">Descripción</th>
<th class="col-md-1 text-center">Precio Unitario Refacciones</th>
<th class="col-md-1 text-center">Importe total Refacciones</th>
<th class="col-md-1 text-center">Mano de Obra</th>
<th class="col-md-1 text-center">Importe Total</th>
<th class="col-md-1 text-center">Proveedor</th>
<th class="col-md-1 text-center"></th>
</tr>
</thead>
<tbody>
<?php
include '../includes/db.php';
$folio_hoja=$_GET['folio_hoja'];
$query= mysqli_query($conn, "SELECT * FROM hoja_costos where folio_hoja='$folio_hoja'");
while($row = mysqli_fetch_assoc($query)) {
?>
<tr>
<td style="text-transform:capitalize" class="text-center"><?php echo $row['cantidad'] ?></td>
<td style="text-transform:capitalize" class="text-center"><?php echo $row['descripcion'] ?></td>
<td style="text-transform:capitalize" class="text-center"><?php echo $row['precio_refac'] ?></td>
<td style="text-transform:capitalize" class="text-center"><?php echo $row['total_refac'] ?></td>
<td style="text-transform:capitalize" class="text-center"><?php echo $row['mano_obra'] ?></td>
<td style="text-transform:capitalize" class="text-center"><?php echo $row['importe_total'] ?></td>
<td style="text-transform:capitalize" class="text-center"><?php echo $row['proveedor'] ?></td>
<td style="text-transform:capitalize" class="text-center"><button class="btn btn-warning btn-xs" a href="#costos<?php echo $row['ID']?>" data-toggle="modal" a title="Editar" ><i class="fa fa-edit"></i></button> </td>
</tr>
<?php
include '../includes/hoja_update.php';
};
?>
</tbody>
</table>
<!-- FIN TABLA -->
<table id="hoja" class="table" >
<thead >
<tr id="heads">
<th class="col-md-3" ></th>
<th class="col-md-4"></th>
<th class="col-md-4"></th>
<th class="col-md"></th>
</tr>
</thead>
<tbody>
<tr>
<td >
<a class=" btn btn-md btn-info" href="#cost" data-toggle="modal"><center> Agregar </center></a>
</td>
<?php
include '../includes/db.php';
$folio_hoja=$_GET['folio_hoja'];
$query= mysqli_query($conn, "SELECT SUM(importe_total) as sumtotal FROM hoja_costos where folio_hoja='$folio_hoja'");
while($row = mysqli_fetch_assoc($query))
$output=$row['sumtotal'];
?>
<td >
<center> <div >
<h4>
<label class="control-label">Total:</label>
<FONT COLOR="TEAL"> <b> <?php echo $output?> </FONT></h4>
</div> </center>
</td>
<td >
<div>
<div style="width: -10%; float:right">
<button id="imprimir" class="btn btn-info">Imprimir</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery.print/1.6.0/jQuery.print.min.js" integrity="sha256-s/wuIT+s0uE5Igk30VS2UAcs5Ck6SDt+iTlUzYQBn/4=" crossorigin="anonymous"></script>
<script>
$(document).ready(() => {
$('#imprimir').click(function() {
$.print('#imprimible');
});
});
</script>
</div>
</div></td>
<td>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div id="cost" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="modal-content modal-md">
<div class="modal-header">
<h4 class="modal-title" id='head'>
<center> <i class=""></i> Nuevo Hoja de Costos </center>
</h4>
</div>
<form method="POST" id='hoja_form' >
<div class="modal-body">
<div class="form-horizontal">
<div class="form-group" id="form-login">
<label class="col-sm-4 control-label"> Folio:</label>
<div class="col-sm-8">
<input class="form-control" autocomplete="off" id="folio_hoja" name="folio_hoja" type="text" placeholder="INGRESE EL FOLIO" required>
</div>
</div>
<div class="form-group" id="form-login">
<label class="col-sm-4 control-label">Cantidad:</label>
<div class="col-sm-8">
<input class="form-control" style="text-transform: uppercase" autocomplete="off" id="cantidad" name="cantidad" type="text" maxlength="4" placeholder="Ingrese la cantidad" >
</div>
</div>
<div class="form-group" id="form-login">
<label class="col-sm-4 control-label">Descripción:</label>
<div class="col-sm-8">
<input class="form-control" style="text-transform: uppercase" autocomplete="off" id="descripcion" name="descripcion" type="text" placeholder="Ingrese la descripción" >
</div>
</div>
<div class="form-group" id="form-login">
<label class="col-sm-4 control-label">Precio Unitario Refaccciones:</label>
<div class="col-sm-8">
<input class="form-control" style="text-transform: uppercase" autocomplete="off" id="precio_refac" name="precio_refac" type="text" placeholder="Ingrese el Precio Unitario" >
</div>
</div>
<div class="form-group" id="form-login">
<label class="col-sm-4 control-label">Mano de Obra:</label>
<div class="col-sm-8">
<input class="form-control" style="text-transform: uppercase" autocomplete="off" id="mano_obra" name="mano_obra" type="text" value=0 >
</div>
</div>
<div class="form-group" id="form-login">
<label class="col-sm-4 control-label">Proveedor:</label>
<div class="col-sm-8">
<input class="form-control" style="text-transform: uppercase" autocomplete="off" id="proveedor" name="proveedor" type="text" placeholder="Ingrese el Proveedor" >
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-info btn-sm" id="btn_sub">Guardar</button>
<button data-dismiss="modal" class="btn btn-info btn-sm"><i class="glyphicon glyphicon-close"></i>Cancelar</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<script>
jQuery(document).ready(function(){
jQuery("#hoja_form").submit(function(e){
e.preventDefault();
var formData = jQuery(this).serialize();
$.ajax({
type: "POST",
url: "../forms/add_hoja.php?action=hoja",
data: formData,
success: function(html){
$('#retCode1').html(html);
var delay = 2000;
setTimeout(function(){ window.location = "detalle_hoja.php?folio_hoja=<?php echo $folio_hoja?>"; }, delay);
}
});
return false;
});
});
</script>
<footer class="main-footer">
<div class="pull-right hidden-xs">
<b>Version 2.0</b>
</div>
<strong>Copyright © 2023 Todo los derechos reservados.
</footer>
**QUISIERA SABER SI ME PODRIAN AYUDAR DE FAVOR COMO HACER EL PDF DEL CODIGO QUE LES MOSTRE **