I have an app php mvc run 'OK' in xammp with apache2. But now i need to move to debian server 11 with apache2, php 8.1.
with the page that generates the report in pdf i had the Uncaught Error: Class "DOMImplementation" in log of apache2.
I searched for this error on google, but the answers didn't work for me.
My code generate a html page, i test it by echo and is ok but dont to generate pdf.
My code to call dompdf is some like this:
class xyz
{
use Exception;
use PDO;
use Dompdf\Dompdf;
use Dompdf\Options;
public function montaPDF($inform)
{
$options = new Options();
$options->isFontSubsettingEnabled(false);
$options->isRemoteEnabled(true);
$pdf = new Dompdf($options);
$html = '<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head><body>';
$html .= '</body></html>';
$pdf->loadHtml($html); **//the error occur in this part**
$pdf->render();
$pdf->stream("dompdf_out.pdf", array("Attachment" => false));
}
}
thank you all in advance, for read and try to help!!
Thanks for all!Specialy aynber! Solved!
sudo apt-get install php8.1-xml : Worked.
Related
In my laravel project I have the following myview.blade.php content:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ __('menu.title') }}</title>
</head>
<body>
{{__('content') }}
</body>
But instead of rendering it into a http response, I want to be able to generate a pdf file out of it. Do you know How I can do this?
You will need to use a HTML to PDF library such as DOMPDF to do the actual conversion of HTML -> PDF
https://github.com/dompdf/dompdf
To get HTML from a blade view, you can do:
$html = view('path/to/view', ['vars' => 'hello'])->render();
I used many solutions, including DOMPDF, but on average the output generated by WKHTMLTOPDF is far better than DOMPDF.
WKHTMLTOPDF follow CSS rules more precisely.
Well, wkhtmltopdf is a command line program that accepts an html file as parameter, so you just have to install it and you are ready to go. It has package for Linux and Windows.
To the code
Generate the desired html from your view, like this:
$html = view('my_view', $arr);
Write the HTML to a temporary file:
$temp_file = tempnam(sys_get_temp_dir(), 'pdf_');
file_put_contents($temp_file, $html);
Run exec() on wkhtmltopdf:
$pdf_file = $temp_file . '.pdf';
exec('wkhtmltopdf ' . $temp_file . ' ' . $pdf_file);
Download your $pdf_file.
Be happy.
I am attempting to turn some data into a QR on a webpage. To do this I am using 'php qrcode'.
Sourceforge Home Page of library: http://phpqrcode.sourceforge.net/
I am unable to generate the QR code using the library. Am I missing a PHP extension.
Thinking I was missing the GD2 extension, I did:
brew install gd
Current Code:
include( '../phpqrcode/qrlib.php' );
QRcode::png( 'PHP QR Code : )' );
Current Output:
�PNG IHDRWWKK/PLTE���U��~�IDAT8��ұ � PG.�N�t�tـ,V��H,pe�����4Ĵq�k�� ��j���'^l�����p�h�Sn�8D>3T-�%�����:\��z���4{oL��!C�-����_o�r���r��m��x+��,}��ő��|i����ʚt{oZ6\,i�{�5몏{���Ϫ����/MIEND�B`�
Edit:
I have tried changing the html header to image/png. Same results.
<meta http-equiv="content-type" content="image/png" charset="UTF-8">
Edit: Full Sample Code, Same results, no QR code.
<?php header('Content-type: image/png'); ?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta http-equiv="content-type" content="image/png" charset="utf-8">
<title></title>
</head>
<body>
<?php
include( '../phpqrcode/qrlib.php' );
QRcode::png( 'PHP QR Code : )' );
?>
</body>
</html>
Edit: The following shows same results
<?php
header('Content-type: image/png');
include( '../phpqrcode/qrlib.php' );
QRcode::png( 'PHP QR Code : )' );
?>
Edit:
Using laravel framework
Try this:
<?php
header('Content-Type: image/png');
include( '../phpqrcode/qrlib.php' );
QRcode::png( 'PHP QR Code : )' );
?>
When outputting an image, you don't need HTML tags. Alternatively, you could use img tag with data:... source. For an example, see here.
You can use the phpqrcode library for use, please visit this page
I am trying to learn HTML DOM parsing at my localhost. But I crash right in the beggining.
1) I have made a new project
2) I have downloaded files from simplehtmldom.sourceforge.net
3) I have put this code inside my HTML project
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
// put your code here
$html = file_get_html('http://www.google.com/');
?>
</body>
</html>
4) I get this error, when I run the script:
Fatal error: Uncaught Error: Call to undefined function file_get_html() in C:\xampp\htdocs\PhpProject1\index.php:15 Stack trace: #0 {main} thrown in C:\xampp\htdocs\PhpProject1\index.php on line 15
Am I misunderstanding something here?
I think PHP DOM Parser Library No Longer Support to PHP latest Version so, You Need to Use cURL for that It will help you.
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.google.co.in");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
print $result;
?>
Try this..!
file_get_html does not belong to php.
To use it you need to download and include PHP Simple HTML DOM Parser.
Then you can use it like this
include_once('simple_html_dom.php');
$html = file_get_html('http://www.google.co.in');
You need to include the DOM parser PHP library file in your HTML code using PHP include function.
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
include_once('domparser.php');// use your file location
// put your code here
$html = file_get_html('http://www.google.com/');
?>
</body>
</html>
I'm not able to get my PDF printed if I add a logo in my template_header.php file.
If I enable include_once("template_header.php") it's not generating any PDF, and it reports this error message:
PHP Fatal error: Call to undefined function imagecreatetruecolor()
If I disable my header (i.e. above the include_once line) it's generating a PDF without a logo and containing text only.
I tried enabling below, but the same problem persists:
define("DOMPDF_ENABLE_REMOTE", true);
My dompdf ver. is dompdf_0-6-0_beta3.
Can anyone help me on this?
Below is the updated code
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$html = '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>booking</title>
<link rel="stylesheet" href="style/style.css" type="text\css" media="screen" />
</head>
<body>
<div align="center" id="mainwrap">
<?php include_once("template_header.php")?>
</div>
</body>
</html>';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");
Please check your GD library installation in php.
Run <?php phpinfo(); ?> in a php file and check for GD library then
Update -
Check your php.ini and look for extension=php_gd2.dll
If ; [commented] then un comment it and restart the services then.
I am working on creating a PHP script to convert my HTML/CSS/PHP pages into a PDF. I have come across the class domPDF and I have uploaded all files to my server. I am trying to wrap my head around this and I have wrote this sample script to see if I could get it to work. The script is:
ob_start() ;
require_once("dompdf_config.inc.php");
$file= file_get_contents('http://www.yahoo.com');
$dompdf = new DOMPDF();
$dompdf->load_html_file($file);
$dompdf->render();
$dompdf->stream("sample.pdf");
And I am getting this error:
"Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'Permission denied on <!DOCTYPE html> <html lang="en-US" class="y-fp-bg y-fp-pg-grad bkt701" style=""> <!-- m2 template --> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Yahoo!</title> <meta http-equiv="X-UA-Compatible" content="chrome=1"> <meta name="description" content="Welcome to Yahoo!, the world's most visited home page. Quickly find what you're searching for, get in touch with friends and stay in-the-know with the latest news and information."> <meta name="keywords" content="yahoo, yahoo home page, yahoo homepage, yahoo search, yahoo mail, yahoo messenger, yahoo games, news, finance, sport, entertainment"> <script type="text/javascript"> //Roundtrip rtTop = Number(new Date()); document.documentElement.className += ' jsenabled'; </script> <script type="text/javascript"> (function () { //refresh check var d=document,c=";\ in /home/public_html/Sandbox/include/dompdf.cls.php on line 329"
I think you want to use:
$dompdf->load_html($file);
rather than
$dompdf->load_html_file($file);
I'm not familiar with domPDF, but judging by the error message and the function's name, I assume load_html_file() expects a filename but you're giving it the contents of a HTML file. Try $dompdf->load_html_file( 'http://www.yahoo.com' ) or find a function that accepts a HTML string as a parameter.