Я пытаюсь сделать сайт электронной коммерции, где пользователь нажмет на ссылку, и он сделает счет-фактуру и должен загрузить на стороне клиента pdf файл счета-фактуры, который я создал в html, вещь я использовал этот код, и он работал с ms word как.doc, но я хочу сделать то же самое с pdf, не работающим, код, вставленный ниже //the code to download invoice as word document, it working <?php header('Content-type: application/vnd.ms-word'); header('Content-Disposition: attachment;Filename='.$result->tracking_number.'.doc');?> <!DOCTYPE html> <html> <head>
//the code to download invoice as word document, it working <?php header('Content-type: application/vnd.ms-word'); header('Content-Disposition: attachment;Filename='.$result->tracking_number.'.doc');?> <!DOCTYPE html> <html> <head>
но то же самое с этим кодом не работает для pdf :(
<?php
header('Content-type: application/pdf');
header('Content-Disposition: attachment;Filename='.$result->tracking_number.'.pdf');
?>
<!DOCTYPE html>
<html>
<head>
загруженный pdf говорит, что формат поврежден, что делать, я должен закончить это как можно скорее: ((
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function pdf_create($html, $filename='', $stream=TRUE)
{
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
if ($stream) {
$dompdf->stream($filename.".pdf");
} else {
return $dompdf->output();
}
}
?>
4) use it in your controllers like this
<?php
function pdf()
{
$this->load->helper(array('dompdf', 'file'));
// page info here, db calls, etc.
$html = $this->load->view('controller/viewfile', $data, true);
pdf_create($html, 'filename');
or
$data = pdf_create($html, '', false);
write_file('name', $data);
//if you want to write it to disk and/or send it as an attachment
}
?>
https://github.com/EllisLab/CodeIgniter/wiki/PDF-generation-using-dompdf