dompdf can't print the desired result - php

Im trying to generate report but all im getting is this:
The PDF output I wanted to print out date from my database but instead im only getting this one word. I think it has to do with php error but im not able to find my mistake. im new to this, i hope u guys can help me out. thanks.
My model:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class GeneratePdfController extends CI_Controller {
function index()
{
$this->load->model('model_user');
$this->load->library('pdf');
$post_id = $this->uri->segment(3);
$x['data'] = $this->model_user->get_user_by_nip($post_id);
$html = $this->load->view('GeneratePdfView', $x, [], true);
$this->pdf->createPDF($html, 'mypdf', false);
}
}
?>
My View file
<?php
$b = $data->row_array();
?>
<!DOCTYPE html>
<html>
<head>
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<meta charset="utf-8">
<title>Create PDF from View in CodeIgniter Example</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
</head>
<body>
<h1 class="text-center bg-info">Generate PDF from View using DomPDF</h1>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>#</th>
<th>Nama</th>
<th>Nip Baru</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><?php echo $b['n']; ?></td>
<td><?php echo $b['nipBaru']; ?></td>
</tr>
<tbody>
</table>
</body>
</html>

Related

Use the information of a PHP table to generate a PDF file

I have a table that I generate using PHP, with the fields of name, id and the name of the file that contains the person's photo. How can I store the information of each row of the table in variables and use them in another PHP page, so that when clicking on the name of the person that appears in the table, a PDF document that I generated with FPDF is opened and use the data from the table (name and file name of the photograph) to fill the PDF.
This is the code where the table is generated:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<?php
$link = new PDO('mysql:host=localhost;dbname=employers', 'root', '');
?>
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>NAME</th>
<th>FILENAME</th>
</tr>
</thead>
<?php foreach ($link->query('SELECT * from employers') as $row){ ?>
<tr>
<td><?php echo $row['ID'] ?></td>
<td><?php echo $row['NAME'] ?></td>
<td><?php echo $row['FILENAME'] ?></td>
<td><a href="/TCPDF/examples/example_051.php?ID=<? echo
$row['ID'];?>">view</a></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
This is the part of the code that generates the PDF where I want to use the information that comes from the table, the variables are the
$someString
:
$pdf->setFont('calibri', '', 48);
// add a page
$pdf->AddPage();
// Print a text
$subtable = '<table border="1" cellspacing="6" cellpadding="4"><tr><td><h1 style="font-size: 45px;text-align:left;"><br><br><br> '.$someString4.'</h1></td></tr><tr><td><h1 style="font-size: 150px;text-align:LEFT;"> '.$someString3.'</h1></td></tr></table>';
$html = '
<table cellpadding="10" cellspacing="7" border="1" style="text-align:center;">
<tr style="position:absolute; left:780px; top:120px;">
<td>'.$subtable.'</td>
<td><br><br><img src="images/'.$someString2.'" border="0" height="300" width="200" align="bottom" /><h2 style="font-size: 30px;">'.$someString.'</h2></td>
</tr>
</table>';
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
// reset pointer to the last page
$pdf->lastPage();

My table doesn't show up

I have the following code, and the tutorial I followed says that the table should show up, but it doesn't. All that shows up is the text inside the <h1> and <h4> tags, and the external CSS file is also not taking effect. The code I have is as follows:
<?php
include_once('connection.php');
$query="select * from myanimelist";
$result=mysql_query($query);
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles-2.css">
</head>
<body>
<h1> Callum Stewart's Amazing Website. </h1>
<h4> The Home of Entertainment. </h4>
<table align="center" border="1px" style="width: 300px" color="black">
<tr>
<th>Anime Database</th>
</tr>
<tr>
<th>Title</th>
<th>MediaType</th>
<th>Rating</th>
<th>NumOfEpisodes</th>
<th>NumOfVolumes</th>
</tr>
</table>
</body>
</html>

PHP Datatables, Invalid JSON

I have a table based on a SQL query that I'm running through PHP that I would like to apply Datatables to for presentation and sorting purposes. However, when I run the page in the browser, I receive an error that indicates that I have an invalid JSON response.
Here is my code:
PHP script (with HTML):
<?php
session_start();
include 'connect.php';
$sql = "SELECT *
FROM SCHEMA.DETAIL_TABLE";
$result = mysql_query($sql);
$row_count=mysql_num_rows($result);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/colreorder/1.3.3/css/colReorder.dataTables.min.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="javascript/detail_sorter.js" type="text/javascript"></script>
<script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/colreorder/1.3.3/js/dataTables.colReorder.min.js"></script>
</head>
<body>
<table id="disposalDetailTable" class="display">
<thead>
<tr>
<th>Ticket Number</th>
<th>Bay Number</th>
<th>Date Time</th>
<th>Customer</th>
<th>Driver</th>
<th>Total</th>
<th>Unload Time</th>
</tr>
</thead>
<tbody>
<?php
//This is the main detail data table. We loop through the SELECT statement.
while ($row = mysql_fetch_row($result)) {
echo "<tr>
<td>".($row[15])."</td>
<td>".($row[1])."</td>
<td>".($row[2])."</td>
<td>".($row[5])."</td>
<td>".($row[8])."</td>
<td>".(round($row[12], 1))."</td>
<td>".(round($row[13], 1))."</td>
</tr>";
}
?>
</tbody>
</table>
</body>
Here is my jQuery (filename = detail_sorter.js):
$(document).ready(function(){
$('#disposalDetailTable').DataTable();
});
I feel like I'm trying to keep it too simple. When use a static table the Datatables functionality works perfect. However, when I add the PHP dynamically I get the error that I mentioned.
Any help is appreciated.

Unable to stream pdf: headers already sent codeigniter

i had this error when i want to export my file to pdf
Unable to stream pdf: headers already sent
this is my function export_to_pdf inside the controller
function export_to_pdf() {
$this->load->helper('warsito_pdf_helper');
$this->load->model('gedung/gedung_model');
$data['row'] = $this->gedung_model->laporan_perawatan_keseluruhan();
$object = $this->load->view('manage/pdf_report_all', $data);
$filename = 'Report.pdf';
generate_pdf($object, $filename, true);
}
and i have helper with name warsito_pdf_helper like this
function generate_pdf($object, $filename, $direct_download = true) {
require_once 'dompdf/dompdf_config.inc.php';
$dompdf = new DOMPDF();
$dompdf->load_html($object);
$dompdf->render();
if($direct_download == true) {
$dompdf->stream($filename);
} else {
return $dompdf->output();
}
}
and finally the view for the pdf
pdf_report_all.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Favicons-->
<link rel="apple-touch-icon-precomposed" href="<?php echo base_url();?>assets/home/assets/img/favicon/apple-touch-icon-152x152.png">
<meta name="msapplication-TileColor" content="#FFFFFF">
<meta name="msapplication-TileImage" content="<?php echo base_url();?>assets/home/assets/img/favicon/mstile-144x144.png">
<link rel="icon" href="<?php echo base_url();?>assets/home/assets/img/favicon/favicon-32x32.png" sizes="32x32">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Materialize core CSS -->
<link href="<?php echo base_url();?>assets/home/materialize/css/materialize.css" rel="stylesheet" type="text/css">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="assets/js/html5shiv.js"></script>
<script src="assets/js/respond.min.js"></script>
<![endif]-->
<link href="<?php echo base_url();?>assets/home/template.css" rel="stylesheet" type="text/css">
</head>
<body>
<center><b><h5>Laporan Pembayaran Keseluruhan</h5></b></center>
<!--
<div class="container">
<div class="row">
<div class="col s12 m12"> -->
<table class="bordered" align="center">
<tr>
<th>No</th>
<th>No Ref</th>
<th>Jenis Perawatan</th>
<th>Tanggal Pembayaran Tagihan</th>
<th>Jumlah Pembayaran</th>
</tr>
<?php foreach($row as $row): $no = 1; $total_pembayaran = 0;?>
<tr>
<td><?php echo $no++?></td>
<td><?php echo $row['NO_ID']?></td>
<td><?php echo $row['NAMA_PERAWATAN']?></td>
<td><?php echo $row['TANGGAL_PEMBAYARAN']?></td>
<td><?php echo "Rp. ".number_format($row['BIAYA'])?></td>
</tr>
<?php $total_pembayaran = $row['BIAYA'] + $total_pembayaran?>
<?php endforeach;?>
</table>
<table style="display: inline-block;">
<tr>
<td><b>Total Pembayaran Keseluruhan: </b></td>
<td><b><?php echo "Rp. ".number_format($total_pembayaran)?></b></td>
</tr>
</table>
<!--
</div>
</div>
</div> -->
<script src="<?php echo base_url();?>assets/home/assets/js/jquery.min.js"></script>
<script src="<?php echo base_url();?>assets/home/materialize/js/materialize.js"></script>
<script src="<?php echo base_url();?>assets/home/index.js"></script>
</body>
</html>
i have googling my problem before, mostly says this error occurs because i have an extra lines in my file i already try the solution from this link DOMPDF: Unable to stream pdf: headers already sent
and add the following code after the stream();
$f;
$l;
if(headers_sent($f,$l))
{
echo $f,'<br/>',$l,'<br/>';
die('now detect line');
}
but the error still happens, so anyone can tell me whats wrong with my method or my code, thanks
In your controller change $object = $this->load->view('manage/pdf_report_all', $data);
to $object = $this->load->view('manage/pdf_report_all', $data, TRUE);
And also change your view to
`
<center><b><h5>Laporan Pembayaran Keseluruhan</h5></b></center>
<table class="bordered" align="center">
<tr>
<th>No</th>
<th>No Ref</th>
<th>Jenis Perawatan</th>
<th>Tanggal Pembayaran Tagihan</th>
<th>Jumlah Pembayaran</th>
</tr>
<?php foreach($row as $row): $no = 1; $total_pembayaran = 0;?>
<tr>
<td><?php echo $no++?></td>
<td><?php echo $row['NO_ID']?></td>
<td><?php echo $row['NAMA_PERAWATAN']?></td>
<td><?php echo $row['TANGGAL_PEMBAYARAN']?></td>
<td><?php echo "Rp. ".number_format($row['BIAYA'])?></td>
</tr>
<?php $total_pembayaran = $row['BIAYA'] + $total_pembayaran?>
<?php endforeach;?>
</table>
<table style="display: inline-block;">
<tr>
<td><b>Total Pembayaran Keseluruhan: </b></td>
<td><b><?php echo "Rp. ".number_format($total_pembayaran)?></b></td>
</tr>
</table>

Can't display image on dreamweaver from phpmyadmin

I upload some image to phpMyAdmin, and write some code on Dreamweaver.
Then got this:
The code is on below:
<?php
require_once("connection.php");
$result = mysql_query("SELECT * FROM food");
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Food & Beverages</title>
</head>
<body>
<form>
<table width="400" border="1">
<tbody>
<?php
while($row = mysql_fetch_assoc($result)){
?>
<tr>
<td width="240" height="130"><img src="<?php echo $row['image']?>"></td>
<td><?php echo $row['info'];?></td>
</tr>
<?php }?>
</tbody>
</table>
</form>
</body>
</html>
How to solve this problem?

Categories