I'm making a download of PDF with DOMPDF. Everything is working fine. The PDF is downloading and opens well in Adobe Reader. But at closing the window, Adobe Reader is asking me if I want to save the PDF file where I didn't change anything in. What is the possible problem that cause this problem?
$filename = $naam.' Factsheet.pdf';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
file_put_contents('pdf/'.$filename, $dompdf->output( array("compress" => 0) ));
if ( !headers_sent() ) {
$dompdf->stream($filename, $options);
}
Can please anybody help me with this problem?
Sorry for grave digging, but i had the same issue, however i fixed my code but i dont know how, here is the working code
$filename = $sm_number . "_" . date('Ymd') .'_OK_CALCOOLING.pdf';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->loadHtml($content);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$array = array(
"compress" => 0,
"Attachment" => 0
);
$dompdf->stream($filename, $array);
Make sure you add ob_get_clean() when declaring your $html variable.
$html = ob_get_clean(); //ADD THIS LINE WHEN DECLARING HTML VARIABLE
$html .= 'My content here';
$dompdf = new Dompdf();
$dompdf->getOptions()->setIsFontSubsettingEnabled(true);
$dompdf->loadHtml(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream("filename.pdf", array("compress" => 0, "Attachment" => false));
exit;
Related
I have been able to use dompdf to stream output but how can I make it send via email
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$image = "../img/logo2.png";
$html = '<h1>Hello World</h1>' ;
$dompdf->load_html($html);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
$dompdf->render();
$domdpf->stream();
how can I make it send via PHPMailer
Thanks
Change your last line to $pdf = $dompdf->output();
Then you can use the addStringAttachment function in PHPMailer (https://phpmailer.github.io/PHPMailer/classes/PHPMailer.PHPMailer.PHPMailer.html#method_addStringAttachment)
My s3 url is https://s3-us-west-2.amazonaws.com/bucket_name/test.png
its working fine on browser and showing image not found after including it on pdf file.
$pdf = new \DOMPDFModule\View\Model\PdfModel();
$pdf->setOption("filename", $filename);
$pdf->setOption("paperSize", "a4");
$pdf->setOption("paperOrientation", "landscape");
$dompdf = new \DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$pdfCode = $dompdf->output();
file_put_contents('path_to_pdf/test.pdf', $pdfCode);
If you use Laravel, you need to add this to your blade.
#php
use Illuminate\Support\Facades\Storage;
$content = Storage::get('vinylmaster.png');
$imageData = base64_encode($content);
$src = 'data:image/png;base64,' . $imageData;
#endphp
<img src="{{$src}}">
if you are not on Laravel, try Embedding images in a PDF file with PHP and DOMPDF
This code works but the resulting file is being opened like HTML for me not as a pdf or download pdf. How can I fix that?
<?php
require_once("dompdf/dompdf_config.inc.php");
//var_dump("dompdf/dompdf_config.inc.php");
$tiket = $_GET["tiket"];
$file = $this->load->view('admin/report/fm-it-01',$tiket);
$dompdf = new DOMPDF();
//var_dump($dompdf->load_html($file));
$dompdf->load_html_file($file);
$dompdf->render();
$dompdf->stream("sample.pdf"); ?>
Try $dompdf->load_html($file); instead of $dompdf->load_html_file($file);
We are trying to create html to pdf using DOMPDF. When we are saving this to our browser it is created correctly. For creation we are using this function
function createPDF($pdf_userid, $pdf_content, $pdf_For, $filename){
$path='dompdf/';
/*$rndNumber=rand();
$filename=$pdf_userid.date("Ymd").$rndNumber.'.pdf';*/
$dompdf=new DOMPDF();
$dompdf->load_html($pdf_content);
$dompdf->render();
$output = $dompdf->output();
file_put_contents($path.$filename, $output);
return $filename;
}
But when we are trying to show pdf in browser without saving on server its showing "Failed to load PDF".
for this we are using this code
try{
$dompdf=new DOMPDF();
$dompdf->load_html($pdf_content);
$dompdf->render();
//$output = $dompdf->output();
$dompdf->stream("dompdf_out.pdf", array("Attachment" => false));
exit(0);
}catch(exception $e){
print_r($e);}
Please tell us whats wrong in second code?
Try this and download the latest stable version of dompdf from github
<?php
// include autoloader
require_once 'dompdf/autoload.inc.php';
// reference the Dompdf namespace
use Dompdf\Dompdf;
use Dompdf\Options;
$options = new Options();
$options->set('isRemoteEnabled', TRUE);
// instantiate and use the dompdf class
$dompdf = new Dompdf($options);
$context = stream_context_create([
'ssl' => [
'verify_peer' => FALSE,
'verify_peer_name' => FALSE,
'allow_self_signed'=> TRUE
]
]);
$dompdf->setHttpContext($context);
$html = file_get_contents("html.html");
$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 to browser
$dompdf->stream();
// Output the generated PDF (1 = download and 0 = preview)
$dompdf->stream("codexworld",array("Attachment"=>0));
?>
I want to generate multiple pdf files in loop using dompdf. I am using dompdf_0-6-0_beta3. But only one file get generated each time wehn I execute the code. I am providing my code for reference as follows.
include 'dompdf_config.inc.php';
for($i=0; $i<5; $i++)
{
if ( get_magic_quotes_gpc() )
$old_limit = ini_set("memory_limit", "16M");
$dompdf = new DOMPDF();
$dompdf->load_html($i);
$dompdf->set_paper('a4', 'portrait');
$dompdf->render();
$dompdf->stream($i.".pdf");
}
So please help me in this question.
You'l have to save your all PDFs to server and then redirect User to download these PDFs.
include 'dompdf_config.inc.php';
$file_to_save = '/path/to/your/public_html/pdf/';
for($i=0; $i<5; $i++)
{
if ( get_magic_quotes_gpc() )
$old_limit = ini_set("memory_limit", "16M");
$dompdf = new DOMPDF();
$dompdf->load_html($i);
$dompdf->set_paper('a4', 'portrait');
$dompdf->render();
//Save PDF in server.
file_put_contents($file_to_save."file".$i.".pdf", $dompdf->output());
}
//open popup window to download all PDFs to client browser.
echo "<script type='text/javascript'>";
for($i=0;$i<5: $i++){
echo "window.open('/pdf/file{$i}.pdf');" ;
}
echo "</script>";