DOM PDF renders on mac but not PC - php

I'm using DOM PDF to convert a simple html page to a PDF--everything works on mac, but on PC I get the message:
Is there a log I can check? What could make this work on mac (using preview) but not adobe on windows?
Edit
As bfavaretto suggested, I opened the PDF in textedit. Here's the error:
<p>Message: Function set_magic_quotes_runtime() is deprecated</p>
<p>Filename: lib/class.pdf.php</p>
<p>Line Number: 4332</p>
Here is my CI code:
function pdf($id)
{
// Setup fields
$this->load->helper('htm_to_pdf');
$data['data'] = $this->home_model->getReport(array('id'=>$id));
$html = $this->load->view('HTML2PDF/Code/index', $data, true);
pdf_create($html, 'filename');
}

set_magic_quotes_runtime is not used anymore in dompdf 0.6. I suggest you to download the latest version (0.6 beta 3) or to remove the set_magic_quotes_runtime call in lib/class.pdf.php.
It is a warning thrown by PHP because this function is deprecated.

Some wiki usage information
require_once("dompdf_config.inc.php");
$html_to_string = $this->load->view('', array(), true);
$dompdf = new DOMPDF();
$dompdf->load_html($html_to_string);
force_download('sample.pdf', file_get_contents($dompdf->render()));
-
Instead of force download you could use
$dompdf->stream("sample.pdf");

I've seen posts about similar issues (I had a bunch of issues with DOMPDF), it sounds like there is other text in the output stream that's causing specifically Acrobat to reject the PDF as corrupt.
Try adding setlocale(LC_NUMERIC, "C"); before you call DomPDF
Take a look at this thread for more info: http://code.google.com/p/dompdf/issues/detail?id=418

Related

Why can I not open my pdf made with a HTML 2 pdf converter?

I am trying to open a pdf on my pc that I made with an HTML 2 pdf converter, but I get the error:
The document contains content that is not tagged in the code.
I can't open the pdf in Google Chrome either. But in Firefox, I can open it and the content is correct. If I send it to someone with a mac, than he can also open the pdf without any problems and the content is correct.
Operating system on which the code runs: Cent OS 7.
Composer package: spiritix/php-chrome-html2pdf.
Code:
<?php
use Spiritix\Html2Pdf\Converter;
use Spiritix\Html2Pdf\Input\UrlInput;
use Spiritix\Html2Pdf\Output\DownloadOutput;
$input = new UrlInput();
$input->setUrl('https://www.google.com');
$converter = new Converter($input, new DownloadOutput());
$converter->setOption('landscape', true);
$converter->setOptions([
'printBackground' => true,
'displayHeaderFooter' => true,
'headerTemplate' => '<p>I am a header</p>',
]);
$output = $converter->convert();
$output->download('google.pdf');
Any idea what can be causing this? Is this a Chromium issue, library issue or a system issue?

Unable to use PDFLib Adapter with latest dompdf 0.7.0

I am using DomPDF with PDFLib as backend.
Recently I am trying to upgrade my application to use dompdf from 0.6.0 to 0.7.0.
But it is giving exception in following file :
https://github.com/dompdf/dompdf/tree/master/src/Adapter/PDFLib.php#L213
$families = $dompdf->getFontMetrics->getFontFamilies();
Exception :
[Dompdf\Exception, 0]
Invalid property: getFontMetrics
Can anyone let me know what is this error about ?
Below is the sample php script that I am trying to run :
<?php
require_once('dompdf/autoload.inc.php');
// reference the Dompdf namespace
use Dompdf\Dompdf;
use Dompdf\Options;
$options = new Options();
$options->set(array(
'pdfBackend'=>'PDFLib',
'defaultMediaType'=>'print',
'defaultPaperSize'=>'A4',
'defaultFont'=>'arial',
'enable_html5_parser'=>true,
'enable_font_subsetting'=>true
));
// instantiate and use the dompdf class
$dompdf = new Dompdf($options);
$dompdf->loadHtml('hello world');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
There are some bugs in 0.7.0 with regard to PDFLib. The next release should address those issues (commit 3fd379b addresses this particular issue). No release date is currently set, though I would expect to see it by this fall.
Relevant discussion is in issue #1222.

Dompdf error "No block-level parent found. Not good."

require_once("function/dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
foreach($modules as $module){
$output = "Hello " .$module['name'];
$dompdf->load_html($output);
$dompdf->render();
$output_pdf = $dompdf->output();
file_put_contents($dir . $name_modulo . ".pdf", $output_pdf);
}
Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'No block-level parent found. Not good.'
Late to this thread, but based on the post at https://github.com/dompdf/dompdf/issues/902, I was able to fix this issue by removing spaces between <html><head>, </head><body>, and </body></html>
So, instead of having properly formated html code like this:
<html>
<head>
...
</head>
<body>
...
</body>
</html>
I deleted all the new lines or spaces between the tags, now it looks like this :
<html><head>
...
</head><body>
...
</body></html>
And everything is hunky-dory again
dompdf folder > dompdf_config.custom.inc.php file > try to uncomment the line
define("DOMPDF_ENABLE_HTML5PARSER", true);
Also replace unsupported html5 tags & attributes with supported one, clear html errors for better result
Just define
$dompdf->set_option('enable_html5_parser', TRUE);
I think it will fix the issue.
Or can edit the dompdf/dompdf_config.inc.php file
go to line no 322
change
def("DOMPDF_ENABLE_HTML5PARSER", false);
to
def("DOMPDF_ENABLE_HTML5PARSER", true);
go to configuration file dompdf_config.custom.inc.php and uncomment define("DOMPDF_ENABLE_HTML5PARSER", true); and check, basically it requires html5 parser enabled in your configuration file.
Just uncomment define("DOMPDF_ENABLE_HTML5PARSER", true); this line from dompdf_config.custom.inc.php this file.
You can find this file for codeigniter in vendor/dompdf/dompdf this directory.
If you have installed dompdf using composer require then defining the enable_html5_parser option using the set_option method works well if you don't want to modify the vendor folder
So add the following to each document that is creating an error
$dompdf->set_option('enable_html5_parser', TRUE);
For newer versions of Dompdf you can use this to enable the HTML5 parser:
use Dompdf\Options;
$options = new Options();
$options->set('isHtml5ParserEnabled', true);
$dompdf = new Dompdf($options);
I don't know why the answer regarding ("DOMPDF_ENABLE_HTML5PARSER", true) was voted down either. Because I spent over 30 hours trying to figure out why this was happening in my website, until I came across this solution. So I enabled the "DOMPDF_ENABLE_HTML5PARSER" by setting it to "TRUE" as noted above. And immediately the error regarding "No block-level parent found" was resolved and my scripts worked. Maybe the 2nd answer was voted down because it duplicated a previous answer (but cut a guy a break, why don't you? Maybe he didn't see it..). Or maybe the "downvoter" has an attitude problem.
I had the same problem with domPDF 0.8.3 on PHP 5.6 and I couldn't find neither dompdf_config.custom.inc.php nor dompdf_config.inc.php and didnĀ“t work either; to solve my problem, I added body {display:block;} to my CSS and had not further problem.
I tried locating the white space or other spaces. didn't succeed, so
I just Minimized the HTML file that is a PDF template
it removed all the spaces, white spaces, etc
worked for me
You can enable the HTML5 parser as mentioned above or you can update the dompdf library. I found updating the dompdf library from 6.2 to 8.2 got past this error BUT if you are using Drupal like I am there's a little bit of trickery you have to do to get Drupal to recognize the newer version of the library (see here: https://www.drupal.org/project/print/issues/3010637 )
In my case, it is a bit different.
The pdf creation code was in the loop but the dom pdf object creation was above the loop. So when it is trying to create the pdf for the second time, I had seen the above error. To resolve it, each and every time I am creating a new object and it worked as expected.
Example:
(Code not working)
//Reference of Dompdf namespace
use Dompdf\Dompdf;
use Dompdf\Options;
//instantiate and use the Options class
$options = new Options();
$options->set('enable_html5_parser', true);
$dompdf = new Dompdf($options);
for($i = 0; $i < $count; $i++) {
//Create PDF
$dompdf->loadHtml($form_data);
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$output = $dompdf->output();
file_put_contents($pdf_file_name, $output);
}
Working Code:
//Reference of Dompdf namespace
use Dompdf\Dompdf;
use Dompdf\Options;
//instantiate and use the Options class
$options = new Options();
$options->set('enable_html5_parser', true);
for($i = 0; $i < $count; $i++) {
$dompdf = new Dompdf($options);
//Create PDF
$dompdf->loadHtml($form_data);
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$output = $dompdf->output();
file_put_contents($pdf_file_name, $output);
}

wkhtmltopdf: how to use it?

I want to be able to generate and save a PDF version of a PHP page. I found out, on Stackoverflow, that the most recommended is wkhtmltopdf: http://code.google.com/p/wkhtmltopdf/
However, I don't have any Shell or binary knowledge; I only know HTML and PHP.
Could anyone CLEARLY guide me on how to get a php page generate a PDF document using wkhtmltopdf (using only FTP and PHP)?
Did you read wiki section of the project homepage? It has IntegrationWithPhp page. Hope that thelps.
Read comments to see how to use the class thats found in the wiki:
$html = file_get_contents("http://www.google.com");
//echo $html;
$pdf = new WKPDF();
$pdf->set_html($html);
$pdf->render();
$pdf->output(WKPDF::$PDF_EMBEDDED,'sample.pdf');

How to insert Image in pdf using PHP (Generating a PDF)?

I want to generate a PDF that will contain an image.
so i already tried this line of codes:
$pdf->Image('b.png',10,8,33);
the other is:
$pdf->Image('Project_ITCPH\images.jpg', 1, 10, 5.8, 1.5);
the problem here is this Error:
"Deprecated: Function set_magic_quotes_runtime() is deprecated in C:\xampp\htdocs\Project_ITCPH\reports\fpdf.php on line 931
FPDF error: Alpha channel not supported: b.png"
is there a problem with the fpdf.php? i only use it as include.
You have my regards.
This error simply means that FPDF is using a function call that is deprecated and outdated. This is shown because your PHP displays errors and warnings and deprecation notes. You should try turning off errors before generating the PDF or writing # before function calls (like here) when using FPDF.
By the way, I highly recommend you use mPDF for PDF generation with PDF, it's better supported in my opinion.
Upgrade your FPDF to 1.7. It now supports alpha channel in PNGs.
Check out this class it lets you add images to PDF's with PHP it has a lot of demo's
https://github.com/dompdf/dompdf
Try
$pdf->Image('..\Project_ITCPH\images.jpg', 1, 10, 5.8, 1.5);
this is some time happen cause server could not find the folder path hope this work for u
also try this
require('fpdf.php');

Categories