I have a problem with DOMPDF integration into Wordpress.
Here are the steps done:
Installed DOMPDF 0.6.1
into the themedir/dompdf/
Created path /dompdf/lib/php-font-lib/classes where php lib is to be
imported
Imported the "FontLib" folder contents
(version 0.4) into the
/dompdf/lib/php-font-lib/classes
Here is the code:
require_once(echo get_template_directory_uri()."/dompdf/dompdf_config.inc.php");
$html =
'<html><body>'.
'<p>Put your html here, or generate it with your favourite '.
'templating system.</p>'.
'</body></html>';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream(echo get_template_directory_uri()."/dompdf/testpdf.pdf");
Outputs nothing, I have also tried stream("testpdf.pdf"); as the last line but no success.
Any ideas? Thank you.
Try this
include get_template_directory() . '/dompdf/dompdf_config.inc.php';
$html =
'<html><body>'.
'<p>Put your html here, or generate it with your favourite '.
'templating system.</p>'.
'</body></html>';
$dompdf = new DOMPDF();
$dompdf->load_html( $html );
$dompdf->render();
file_put_contents( get_template_directory() . "/dompdf/testpdf.pdf");
Related
Below is my current code I want to store the pdf inmy files without view it . is it possible ? when user store the data for $bus object on db. I want to store below pdf on my local.
$user = Festivals::where('id', $bus->id)->first();
$pdf = PDF::loadView('user.view', compact('user'));
$name = 'Ref_no' . $user->ref_no . '_' . date('m-d-Y') . '.pdf';
return $pdf->download($name);
if $pdf is a DomPDF object, use its output() method to get pdf content as a string and simply put it in a file;
$content = $pdf->output();
file_put_contents('/path/to/your/file', $content);
You can just do Storage::put($filename, $pdf->output()) if you need.
UPDATE1:
Works pretty well on Ubuntu but not on CentOS.
I have a issue with the DOMPDF on CentOS Linux VPS,
I output an HTML with css on my WAMPP and works pretty well:
But when i upload the same code, the same html it shows as this:
I tried everything like check encoding, inline css, enabling remote but still no way to get this running, here is my code:
require_once(APP . 'vendors' . DS . 'dompdf' . DS . 'dompdf_config.inc.php');
spl_autoload_register('DOMPDF_autoload');
$dompdf = new Dompdf();
def("DOMPDF_ENABLE_REMOTE", true);
$_GET['print'] = 1;
$dompdf->set_paper("A4", "portrait");
$this->output = '';
$this->layout = 'none';
$old_output = $this->output;
$this->render('innobra_pdf');
$new_output = $this->output;
$dompdf->load_html($new_output);
// $dompdf->load_html( utf8_decode($new_output), Configure::read('App.encoding') );
$dompdf->render();
$output = $dompdf->output();
header('Content-type: application/pdf');
echo $output; die();
What i'm doing wrong ?
Thanks
If you have copied to another server, try deleting the file
dompdf/lib/fonts/dompdf_font_family_cache.php
I try to show image as follows:
function part_profile_record_pdf_form()
{
$sql = "SELECT * FROM part_profile WHERE part_id=" . arg(2);
$query = db_query($sql);
$dataFormDb = db_fetch_object($query);
$url = '../../../' . $dataFormDb->image;
$css_file = drupal_get_path('module', 'part_profile') . '/css/part_profile_pdf.css';
$output = "<style>" . file_get_contents($css_file) . "</style>";
$output .= "<html><body ><div id=\"wrapper\">";
$output.= '<img height="156" width="128" id="img_profile" src="'.$url.'">';
$output.="</div></body></html>";
return $output;
}
I can see the image by the following function:
function part_profile_make_pdf() {
$css_file = drupal_get_path('module', 'part_profile') . '/css/part_profile_pdf.css';
$output= part_profile_record_pdf_form();
print $output;
}
But when I try to make pdf as follows , no image is shown giving 'x' and 'image not readable or empty':
function part_profile_make_pdf() {
$css_file = drupal_get_path('module', 'part_profile') . '/css/part_profile_pdf.css';
$output= part_profile_record_pdf_form();
// print $output;
require_once(realpath(".") . "/sites/all/libraries/dompdf/dompdf_config.inc.php");
spl_autoload_register('DOMPDF_autoload');
if (isset($_SESSION['indv_report_file_name']) && !empty($_SESSION['indv_report_file_name'])) {
$filename = $_SESSION['indv_report_file_name'];
} else {
$rand_val = rand(0, 1000);
$filename = "eureka_" . $rand_val . ".pdf";
$_SESSION['indv_report_file_name'] = $filename;
}
$dompdf = new DOMPDF();
$dompdf->load_html($output);
// $dompdf->set_paper(DEFAULT_PDF_PAPER_SIZE, 'a4');
// "a4" => array(0,0,595.28,841.89),
$dompdf->set_paper(array(0, 0, 595.28, 420), "portrait"); // 12" x 12"
$dompdf->render();
$dompdf->stream("participant-profile.pdf", array("Attachment" => false));
exit(0);
}
I already set DOMPDF_ENABLE_REMOTE to true in my config dompdf_config.inc.php. have any idea. Thanks in advance.
After a little testing in my own DOMPDF environment, I reckon this will be due to the relative path to your image. Currently you're using
$url = '../../../' . $dataFormDb->image;
Which is fine for the preview in HTML, the browser can find the image.
But when DOMPDF tries to process the HTML and find the image, it's doing so from a system perspective, like PHP would if you were doing a file_exists(). So you need to add the full path:
$url = $_SERVER['DOCUMENT_ROOT'] . '/path/to/dir/' . $dataFormDb->image;
or just hardcode it
$url = '/home/username/sitename/public_html/images/' . $dataFormDb->image;
So you might need some logic to say: am I doing a preview? Then use relative path. Or am I doing a PDF render? Then use full path. But I'll leave that to you!
Path : Vendor/dompdf
I am getting Fatal error: Class 'DOMPDF' not found in C:\wamp\www\sms_app\app\Controller\SentMessagesController.php on line 313.
Why i am getting error? This is my code:
function example()
{
//App::import('Vendor','dompdf',array('file'=>'dompdf'.DS.'dompdf_config.inc.php'));
require_once(APP . 'Vendor' . DS . 'dompdf' . DS . 'dompdf_config.inc.php');
$html =
'<html><body>'.
'<p>Put your html here, or generate it with your favourite '.
'templating system.</p>'.
'</body></html>';
try{
$this->dompdf = new DOMPDF();
}
catch (Exception $e)
{
echo $e;
}
$papersize = "legal";
$orientation = 'landscape';
$this->dompdf->load_html($html);
$this->dompdf->set_paper($papersize, $orientation);
$this->dompdf->render();
$output = $this->dompdf->output();
file_put_contents('Brochure.pdf', $output);
}
The error message pretty clearly tells you what is wrong. Check the file(s) you include if the class exists in that file, I doubt it is there. If not figure out in which file the class is and load that file. Check how Dompdf is loading its files.
This error clear says you missing a class so please check how actually importing class in your code.
I am trying to merge files together into one pdf. The files could be pdf, png or jpg files. Images work fine, its only when I try to export the pdf files that I get an error. The error is show below.
Message: fseek(): stream does not support seeking
I thought I found a solution from various forums relating to the path of the file. However, if I change the path it shows this error
mPDF error: Cannot open http://192.168.2.35/marine/certificate_files/a025ad3d40b22ac760ba7af7b6bb259d.pdf
My controller code is below
include('mpdf/mpdf.php');
$mpdf=new mPDF();
$mpdf->SetImportUse();
$mpdf->SetFooter($personnel_data->firstname . ' ' . $personnel_data->lastname . '|{PAGENO}|' . $personnel_data->ID_number );
foreach($certificate_data as $certificates)
{
$certificate_extension['type'] = explode('.',$certificates->certificate_name);
if($certificate_extension['type'][1]==='pdf')
{
$pagecount = #$mpdf->SetSourceFile('http://192.168.2.35/marine/certificate_files/' . $certificates->certificate_name);
$tplId = $mpdf->ImportPage($pagecount);
$mpdf->UseTemplate($tplId);
$mpdf->WriteHTML('<pagebreak>');
}
if($certificate_extension['type'][1]!=='pdf')
{
$mpdf->WriteHTML('<p><img src="' . $this->config->base_url('assets/images/header-logo.png') . ' "></p>');
$mpdf->WriteHTML('<style>body {font-family: arial;}</style>');
$mpdf->WriteHTML('<p> ' . $certificates->certificate . ' - ' . $certificates->expiry_dates . '</p>');
$mpdf->WriteHTML('<p><img src="' . $this->config->base_url('certificate_files/' . $certificates->certificate_name) . ' "></p>');
$mpdf->WriteHTML('<pagebreak>');
}
else
{
$mpdf->WriteHTML('');
}
}
$mpdf->Output();
exit;
If any help or guidance could slide my way form anyone I would be forever grateful! Thanks!
as far as i know mpdf is based on fpdf (fpdi)... from the FPDI website: http://www.setasign.de/products/pdf-php-solutions/fpdi-pdf-parser/
By default FPDI can "only" handle PDF documents up to PDF version 1.4.
Beginning with PDF version 1.5 there were new compression features
introduced which involve internal structure changes how a PDF document
can be created.
Please try it with an PDF Version <= 1.4 for testing...
in my case it was the reason and I bought a developer license for the commercial pfdi pdf parser for 100€