So if I just render the file like this :
<?php
// Include autoloader
require_once '../dompdf/autoload.inc.php';
// Reference the Dompdf namespace
use Dompdf\Dompdf;
// Instantiate and use the dompdf class
$dompdf = new Dompdf();
// Load content from html file
$html = file_get_contents("../orderconfirmation.php");
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF (1 = download and 0 = preview)
$dompdf->stream("codexworld", array("Attachment" => 0));
But this gives me a pdf file with no data from the database, so I tried converting the file to a HTML file as suggested by many different places.
I did the following:
<?php
ob_start();
include("orderconfirmation.php");
$php_to_html = ob_get_clean();
$html_encoded = htmlentities($php_to_html);
echo $html_encoded;
?>
But this gives me an empty file. Any suggestions?
BTW, this is the code for my orderconfirmation.php file :
<?php
session_start();
include 'includes/restrictions.inc.php';
logged_in();
$title = 'Order confirmation';
include_once 'includes/header.php';
include_once 'includes/dbh.inc.php';
?>
<div id="" class="section orderconsec content">
<div class="container">
<div class="pb-4">
<h3>Thank you for your order</h3>
</div>
<div class="border-new border border-dark rounded p-3">
<div class="pt-2 pr-4 pl-4">
<b><h3>Order number</h3></b>
<h3><?php
$order_id = $_SESSION["order_id"];
$ordernosql = "SELECT * FROM invoice WHERE order_id = ?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $ordernosql)) {
echo "SQL statement failed";
}
else
{
mysqli_stmt_bind_param($stmt, "s", $order_id);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if($row = mysqli_fetch_assoc($result))
{
echo $row['order_id'];
?></h3>
<form method="post" action="includes/printpdf.inc.php">
<button type="submit" name="print-vouchers" class="btn btn-danger mt-3">Print</button>
</form>
</div>
<hr>
<div>
<p>We are currently processing your order and we will email you with confirmation shortly.</p>
<p>For your convenience you may want to save your order confirmation.</p>
</div>
<div class="pt-5 pr-4 pl-4">
<b><h3>Delivery Details</h3></b>
</div>
<hr>
<div style="padding: 10px;">
<p><b>Delivery for</b></p>
<p>
<?php
echo $row['uidUsers'];
?>
</p>
</div>
<div style="padding: 10px;">
<p><b>Address</b></p>
<p>
<?php
echo $row['user_address'];
?>
</p>
</div>
<div style="padding: 10px;">
<p><b>Delivery method</b></p>
<p>
<?php
echo $row['delivery_method'];
?>
</p>
</div>
<div class="pt-5 pr-4 pl-4">
<b><h3>Order summary</h3></b>
</div>
<hr>
<div style="padding: 10px;">
<p>
<?php
$output = str_replace(',', '<br />', $row['order_summary']);
echo $output;
?>
</p>
</div>
<div class="pt-5 pr-4 pl-4">
<h3>Payment information</h3>
</div>
<hr>
<div style="padding: 10px;">
<p><b>Payment type</b></p>
<p>
<?php
echo $row['payment_type'];
?>
</p>
</div>
<div style="padding: 10px;">
<p><b>Billing address</b></p>
<p>
<?php
echo $row['billing_address'];
}
}
?>
</p>
</div>
</div>
</div>
</div>
<?php
include_once 'includes/footer.php';
?>
You're loading the content of a PHP file into a variable via file_get_contents then passing that variable to Dompdf:
$html = file_get_contents("../orderconfirmation.php");
$dompdf->loadHtml($html);
This won't work. Dompdf does not parse PHP prior to rendering, that's something you need to do yourself. Try:
ob_start();
require("../orderconfirmation.php");
$html = ob_get_clean();
ob_end_clearn();
$dompdf->loadHtml($html);
Related
I have a page that runs off a local webserver that is uses SQLite as its database. As its used local I am not worried about listing all results on one page as they load super fast. I am having an issue with it though as after 500 results are displayed from SQLite3 the formatting goes all wonky and starts stacking them on top of each other. Everything before that is fine. Its written in php. Info was entered into the database using htmlspecialchars so I dont believe that is the issue. The code that builds each record in the loop is
$list = '';
while($row = $results->fetchArray()) {
$id = $row["id"];
$MovieTitle = $row["MovieTitle"];
$MovieYear = $row["MovieDate"];
$MovieRes = $row["MovieRes"];
$FileName = $row["FileName"];
$Summary = $row["Summary"];
$Genres = $row["Genres"];
$PictureLocation = $row["PictureLocation"];
$Rating = $row["Rating"];
$ReleaseDate = $row["ReleaseDate"];
$list .= '<div class="box">
<div class="movie">
<div class="movie-image"><span class="play"><span class="name">'.$MovieTitle.'</span></span><img src="'.$ThumbnailPic.'" alt=""></div>
<div class="rating">
<p>RATING: '.$Rating.'</p>
<div class="stars">
<div class="'.$StarGraphic.'"></div>
</div>
<span class="comments"></span></div>
</div>';
}
and i just echo them them in the html as such
<html>
<body>
<div id="main">
<br>
<?php echo $list; ?>
</div>
</body>
</html>
Your HTML is wrong, you did not close <div class="box"> and <span class="play"> tags properly.
Correct HTML is:
<div class="box">
<div class="movie">
<div class="movie-image">
<span class="play">
<a href="movielist.php?movie='.$FileName.'">
<span class="name">'.$MovieTitle.'</span>
<img src="'.$ThumbnailPic.'" alt="">
</a>
</span>
</div>
<div class="rating">
<p>
RATING: '.$Rating.'
</p>
<div class="stars">
<div class="'.$StarGraphic.'"></div>
</div>
<span class="comments"></span>
</div>
</div>
</div>
Aso, you can have some tags or quotes in your database records. So you have to use escaping your variables before output http://php.net/manual/en/function.htmlspecialchars.php
Something like this:
$list = '';
while($row = $results->fetchArray()) {
$id = htmlspecialchars($row["id"]);
$MovieTitle = htmlspecialchars($row["MovieTitle"]);
$MovieYear = htmlspecialchars($row["MovieDate"]);
$MovieRes = htmlspecialchars($row["MovieRes"]);
$FileName = htmlspecialchars($row["FileName"]);
$Summary = htmlspecialchars($row["Summary"]);
$Genres = htmlspecialchars($row["Genres"]);
$PictureLocation = htmlspecialchars($row["PictureLocation"]);
$Rating = htmlspecialchars($row["Rating"]);
$ReleaseDate = htmlspecialchars($row["ReleaseDate"]);
$list .= '<div class="box">
<div class="movie">
<div class="movie-image"><span class="play"><span class="name">'.$MovieTitle.'</span></span><img src="'.$ThumbnailPic.'" alt=""></div>
<div class="rating">
<p>RATING: '.$Rating.'</p>
<div class="stars">
<div class="'.$StarGraphic.'"></div>
</div>
<span class="comments"></span></div>
</div>';
}
im using DOMPDF to make downloadable webpage.
but sometime it works, and Sometimes the page takes so long and finally displays "This site can not be reached, The connection was reset".
how to fix this?
its code error or its error on my webbrowser?
thanks :)
function __construct()
{
parent::__construct();
$this->load->model("Mproses");
}
public function download($db,$p,$id) {
// Load all views as normal
$data['hasil'] = $this->Mproses->selectWhere($db,$p,$id);
$this->load->view('hasil',$data);
// Get output html
$html = $this->output->get_output();
// Load library
$this->load->library('dompdf_gen');
$today = date('D-M-Y h:i:s');
// Convert to PDF
$this->dompdf->load_html($html);
$this->dompdf->render();
$this->dompdf->stream($today.".pdf",array('Attachment'=>1));
//or without preview in browser
//$this->dompdf->stream("welcome.pdf");
}
thats my controller for dompdf
HTML file im tryin to download :
<div class="row">
<div class="container">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Hasil Pengecekan! <p class="pull-right"><span class="fa fa-backward" aria-label="Kembali"></span> | <b>Kembali</b></p></h3>
</div>
<div class="panel-body">
<p style="color:black;">
<?php if(count($hasil)>0) { ?>
<?php foreach($hasil as $d) { ?>
<hr>
<br>
<center>
<h2 style="color:black;">Hasil Dari User : <?php echo $d->nama; ?></h2>
</center>
<br>
<hr>
<br>
<ul>
<li style="color:black;"><h5>Penyakit</h5><p style="font-size:20px;"><?php echo $d->penyakit;?></p></li>
<li style="color:black;"><h5>Pilihan</h5><p style="font-size:20px;">"<?php echo $d->pil;?>"</p></li>
<li style="color:black;"><h5>Nilai CF</h5><p style="font-size:20px;"><?php echo $d->nilaicf;?> || <?php echo $d->nilaicf*100;?>%</p></li>
</ul>
<?php } ?>
<?php } else { echo 'Maaf Data Yang Dicari Tidak Ada !'; } ?>
</p>
<br>
<hr>
<br>
<center><?php echo anchor(URL.'index.php/topdf/download/riwayat/id_riwayat/'.$d->id_riwayat,'Download',array('style' => 'color:black;font-size:14px;padding:14px;border:1px black solid;')); ?></center>
<br>
</div>
</div>
</div>
</div>
</div>
I am developing a simple project but encountered a problem which I can not find solution.
The follow php code:
<?php include "header.php"; ?>
<?php
$subtitle = "Os teus animes favoritos diariamente!";
$conn = mysqli_connect("$host","$dbuser","$dbpw","$db");
if (mysqli_connect_errno())
{
echo "Falha ao ligar à Base de Dados: " . mysqli_connect_error();
}
$result = mysqli_query($conn, "SELECT * FROM m_capitulos ORDER BY 'm_capitulos'.'id_cap' DESC LIMIT 30") or die(mysqli_error($conn));
mysqli_close($conn);
?>
<section class="mbr-section mbr-section--relative mbr-section--fixed-size mbr-after-navbar" id="features1-3" style="background-color: rgb(255, 255, 255);">
<div class="mbr-section__container container"><!-- "mbr-section__container--std-top-padding" para dar padding no top! -->
<div class="mbr-section__row row">
<?php while ($row = mysqli_fetch_array($result)){ ?>
<div class="mbr-section__col col-xs-12 col-sm-4">
<div class="mbr-section__container mbr-section__container--center mbr-section__container--middle">
<figure class="mbr-figure"><img class="mbr-figure__img" src="<?php echo $row['p_thumb']; ?>"></figure>
</div>
<div class="mbr-section__container mbr-section__container--middle">
<div class="mbr-header mbr-header--reduce mbr-header--center mbr-header--wysiwyg">
<h3 class="mbr-header__text"><?php echo $row['nombre_cap']; ?></h3>
</div>
</div>
<div class="mbr-section__container mbr-section__container--last">
<div class="mbr-buttons mbr-buttons--center">DOWNLOAD</div>
<br>
<div class="mbr-buttons mbr-buttons--center">DOWNLOAD</div>
<br>
<div class="mbr-buttons mbr-buttons--center">ASSISTIR</div>
</div>
</div>
<?php } ?>
</div>
</div>
</section>
<?php include "footer.php"; ?>
But when I remove the page css the empty space between the results disappears.
The Empty Space on the midle of my content box :
The result on the right just above the space is shorter, thus the next element goes below it instead of going to next row. I suggest you split elements into groups of 3 so that they can go into rows, or alternatively set the height for each result so that they all line up.
The example below adds a counter; every time you run through an element it checks if the element count divides by three, and if so, starts a new row. The same check is done at the end, except that it checks whether the element is the last in the row-of-three, and if so, ends the row tag.
<?php
$i = 0;
while ($row = mysqli_fetch_array($result)){ ?>
<?php if ($i % 3 == 0): ?><div class="row"><?php endif; ?>
<div class="mbr-section__col col-xs-12 col-sm-4">
<div class="mbr-section__container mbr-section__container--center mbr-section__container--middle">
<figure class="mbr-figure"><img class="mbr-figure__img" src="<?php echo $row['p_thumb']; ?>"></figure>
</div>
<div class="mbr-section__container mbr-section__container--middle">
<div class="mbr-header mbr-header--reduce mbr-header--center mbr-header--wysiwyg">
<h3 class="mbr-header__text"><?php echo $row['nombre_cap']; ?></h3>
</div>
</div>
<div class="mbr-section__container mbr-section__container--last">
<div class="mbr-buttons mbr-buttons--center">DOWNLOAD</div>
<br>
<div class="mbr-buttons mbr-buttons--center">DOWNLOAD</div>
<br>
<div class="mbr-buttons mbr-buttons--center">ASSISTIR</div>
</div>
</div>
<?php if ($i % 3 == 2): ?></div><?php endif;
$i++
?>
<?php } ?>
<?php session_start();
if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'])
{
header('Location: /admin');
}
include 'includes/header.inc'; ?>
<div class="main_content_wrapper">
<div class="main_content limit_main_content_width margin_center p20">
<div class="question_wrapper main_content_content homepage_section" style='margin-top: 20px'>
<div>Ask any cooking related doubts or learn from already answered quesetions.</div>
</div>
<div class="question_wrapper main_content_content homepage_section">
<div class='big_heading'>Ask your doubt</div>
<div class="question_wrapper_content question_div_wrapper mb10">
<div class="question_wrapper_content question_div_wrapper placeholder_text js_main_question_placeholder">Write your question here</div>
<div class='question_wrapper_content question_div_wrapper ask_question_box p20 subtle_border radius3 mb10 js_main_question_value js_main_question_input' contenteditable='true'></div>
<input type="email" class="p20 subtle_border question_wrapper_content email_input js_main_email_value" placeholder='Enter your email here'>
<div class="g-recaptcha mt10" data-sitekey="6LcIo9oSAAAAAPTdolZGu6RoMDybW0Q66-TLTkbV"></div>
</div>
<div class="everyOtherGreenButton inline_middle question_wrapper_content submit_main_question js_submit_main_question center_align">ASK ME NOW</div>
<div class="everyOtherGreenButton inline_middle question_wrapper_content sending_main_question js_sending_main_question center_align noafter">SENDING...</div>
<div class='inline_middle bold question_wrapper_content response_message question_sent_success js_question_sent_success'>Success! You will receive an email when Kavita answers the question. :D</div>
<div class='inline_middle bold question_wrapper_content response_message question_sent_error js_question_sent_error'>There was an unknown error :( Please try again or refresh the page.</div>
</div>
<div class="question_wrapper main_content_content homepage_section">
<div class='big_heading'>Recently answered questions</div>
<div class="recently_answered_wrapper">
<?php
include 'includes/database_login.inc';
$sql_query = "SELECT * FROM posts WHERE published = 1 and deleted = 0 and answered = 1 ORDER BY answered_on DESC LIMIT 5";
$result = mysqli_query($conn, $sql_query);
echo $result->num_rows;
$rowCount = '2';
echo $rowCount;
$p_index = 0;
while($row = mysqli_fetch_assoc($result)) {
?><a href='/post.php?id=<?php echo $row["id"]; ?>' class="recently_answered_wrapper_content recently_answered_question inline_middle subtle_border recent<?php echo $p_index%4; ?>">
<div class="title p10 bold">Q. <?php echo $row['title']; ?></div>
<div class="answer p10" style='padding-top: 0'><?php echo $row['answer']; ?></div>
</a><?php //$p_index++;
}
$conn->close(); ?><a href='/posts.php' class="recently_answered_wrapper_content recently_answered_question noborder view_all_answered_questions inline_middle center_align">
<div class="p10 bold" style="margin-top: 55px;">VIEW ALL ANSWERS</div>
</a>
</div>
</div>
</div>
This is a snippet of my php code. I have somehow figured that the error Unexpected end of file is happening here. But I don't see why.
UPDATE
When I comment out echo $rowCount, it doesnt show any errors.
I'm making a site with conrete5. It's the first one I might add. I have made myself a couple of custom blocks. Named News, Teammates and References.
Now News and Teammates are not editable anymore. I will paste the News -blocks sourcecode.
----------- FORM.php ---------------------
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>
<?php
$al = Loader::helper('concrete/asset_library');
echo $al->file('optional', 'fID', t('Valitse kuva'), $bf, $args);
?>
<div class="form-group">
<?php echo $form->label('otsikko', t('Otsikko'));?>
<?php echo $form->text('otsikko', $otsikko);?>
</div>
<div class="form-group">
<?php echo $form->label('teksti', t('Teksti'));?>
<?php echo $form->text('teksti', $teksti); ?>
</div>
<div class="form-group">
<?php echo $form->label('korkeus', t('Korkeus'));?>
<?php echo $form->select('korkeus', array("108px"=>t("Pieni"),"299px"=>t("Iso")), $korkeus); ?>
</div>
<div class="form-group">
<?php echo $form->label('koko', t('Leveys'));?>
<?php echo $form->select('koko', array("col-md-3"=>t("Pieni"),"col-md-6"=>t("Iso")), $koko); ?>
</div>
<div class="form-group">
<?php echo $form->label('link', t('Linkki'));?>
<?php echo $form->text('link', $link); ?>
</div>
<div class="form-group">
<?php $psh = Loader::helper('form/page_selector');
echo $psh->selectPage('targetCID', $targetCID); ?>
</div>
----------- view.php ---------------------
<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
$c = Page::getCurrentPage();
if($size=="col-md-3"){
$class='col-md-3';
$tag = $class;
}else{
$class="col-md-6";
$tag= $class;
}
if ($c->isEditMode()){
$class="editmode";
$editingStyle="padding: 15px; background: #ccc; color: #444; border: 1px solid #999;";
}
else {
$editingStyle = "";
}
$random = rand();
if($korkeus == "299px"){
$padding = '4px';
}else {
$padding = '5px';
}
$p = Page::getByID($targetCID);
$a = new GlobalArea('Header Navigation');
$blocks = $a->getAreaBlocksArray($c);
foreach ($blocks as $block){
if ($block->getBlockTypeHandle()=="autonav"){
$block->setCustomTemplate('cdrop.php'); // it's templates/cdrop.php -check the select option values when you set custom template manually at edit mode. I think you will need just "my_template"
$bv = new BlockView($block);
$bv->render('view');
}
}
?>
<?php $p = Page::getByID($targetCID); ?>
<a href="index.php">
<div class="pull-left <?= $koko;?>" style="padding:<?= $padding ?>;<?php echo $editingStyle;?>">
<div class="col-lg-12 alapalkki box" style="z-index:2;position:relative;">
<div class="image-big" style="background-color:transparent;text-align:center;position:relative;z-index:1;">
<!-- FiGuRe this shit out......... !-->
<?php
if($fID != 0){
$file = File::getByID($fID);
$filePath = $file->getVersion()->getRelativePath();
}
?>
<?php echo '<img src="' . $filePath . '" style="max-height:' . $korkeus . ';width:100%;"/>'; ?>
</div>
<div class="col-lg-12 " style="position:relative;z-index:255;padding:2px 0 0 15px;">
<div class="htitle">
<h4 style="color:white;"><b><?php echo $otsikko; ?></b></h4>
<p style="color:white;"><?php echo $teksti; ?></p>
</div>
</div>
</div>
</div>
</a>
Why is this not being an editable block? Why doesn't the concrete5 even recognize its existence when it is on the page? It just says at the area that it's empty.
$p = Page::getByID($targetCID);
$a = new GlobalArea('Header Navigation');
$blocks = $a->getAreaBlocksArray($c);
foreach ($blocks as $block){
if ($block->getBlockTypeHandle()=="autonav"){
$block->setCustomTemplate('cdrop.php'); // it's templates/cdrop.php -check the select option values when you set custom template manually at edit mode. I think you will need just "my_template"
$bv = new BlockView($block);
$bv->render('view');
}
}
?>
There's the problem. No idea what so ever what that is doing there..... Removed it. Worked like a charm.
-Kevin