I am using Mpdf which is working fine locally, the trouble I am having is that the pdf wont output and just get a blank screen
Here is the error
Fatal error: Uncaught Mpdf\MpdfException: Data has already been sent to output (/customers/3/c/2/includes/header.php at line 14), unable to output PDF file in /customers/3/c/2/pdf/vendor/mpdf/mpdf/src/Mpdf.php:9510 Stack trace: #0 /customers/3/c/2: Mpdf\Mpdf->Output('sold.pdf', 'I') #1 /customers/3/c/2/include('/customers/3/c/...') #2 {main} thrown in /customers/3/c/2/pdf/vendor/mpdf/mpdf/src/Mpdf.php on line 9510
Couple of things I have tried, encoding is correct at UTF and NOT DOM, I have no white space, and everything seems to be ok
This is the header code
<?php
session_start();
if(empty($_SESSION['user_id']))
{
header("Location: https://www.home.co.uk");
}
require '../dbcon/database.php';
$db = DB();
require '../lib/library.php';
$app = new WIDGET();
require '../lib/carbon.php';
$user = $app->UserDetails($_SESSION['user_id']);
?>
I have also tried
<?php
session_start();
require '../dbcon/database.php';
$db = DB();
require '../lib/library.php';
$app = new WIDGET();
require '../lib/carbon.php';
$user = $app->UserDetails($_SESSION['user_id']);
?>
Which has made no difference.
And this is the code in line 9510 of Mdpf.php
case Destination::INLINE:
if (headers_sent($filename, $line)) {
throw new \Mpdf\MpdfException(
sprintf('Data has already been sent to output (%s at line %s), unable to output PDF file', $filename, $line)
);
}
Like mentioned all I am getting is a blank page, if I output to an iframe it works ok. Works fine on 127.0.0.1
Any help much appreciated and thanks in advance for any help
Update:
Sorry forgot to mention or show the code calling the pdf.
I have already tried ob_clean() and still no go
require_once 'pdf/vendor/autoload.php';
if(ob_get_length() > 0) {
ob_clean();
}
$mpdf = new \Mpdf\Mpdf();
$html ='<html>
<body>
<h2 style="font-size: 120px; text-align:center;">SOLD</h2>
<h2 style="font-size: 50px; text-transform: uppercase; text-align:center;">'. $row->widget_model .'</h2>
<h2 style="font-size: 50px; text-transform: uppercase; text-align:center;">'. $row->widget_serial .'</h2><br>
<h2 style="font-size: 30px; text-transform: uppercase; text-align:center;">Delivery Date: '. (new DateTime($_POST['expdelivery']))->format('d-m-Y') .'</h2>
<br>
<h2 style="font-size: 20px; text-align:center;">Contact: '. $_POST['name'] .'</h2>
</body>
</html>';
$mpdf->WriteHTML($html);
$mpdf->Output('sold.pdf','I');
ob_end_flush();
}
EDIT 2:-
Looking at the network Tab it is just showing all the js calls and favicon.ico
It also shows this page updatewidget.php?id=2178
<?php
$page_title = "Widget Tracker - Amend Widget";
$page = '';
include "includes/header.php";
include "includes/sidebar.php";
$id = isset($_GET['id']) ? $_GET['id'] : NULL;
$sth = $db->prepare("SELECT * FROM `widgettracker` WHERE `id` = :id");
$sth->bindParam(':id', $id, PDO::PARAM_INT);
$sth->setFetchMode(PDO::FETCH_OBJ);
$sth->execute();
$row = $sth->fetch();
?>
<section class="content">
<div class="container-fluid">
<?php
if($row->widgetstatus == "Sold")
{include "sold.php";}
else
{include "widgetdetails.php";}
?>
</div>
</section>
<?php
include "includes/footer.php";
include "includes/customjs.php";
?>
And the page that has the Mpdf on is "widgetdetails.php" I need to insert a Sold date and update and generate the pdf. Then the error
?>tags but with the little snippets you've provided, it's unclear to see where it is originating from. If all else fails, you could callob_clean()before attempting to output the Mpdf result. - Reece