HTML2PDF and api.qrserver.com ERROR number 6 - php

I'm trying to output a pdf with a qrCode image in it.
I'm using api.qrserver.com to create the image and HTML2PDF to create the pdf.
This is my PHP code :
$pre_path = 'http://m.website.fr/';
$path = $pre_path . drupal_lookup_path('alias', "node/" . $_GET['nid']);
require(drupal_get_path('module', 'pdfcreator') . '/libs/html2pdf_v4.03/html2pdf.class.php');
ob_clean();
ob_start();
require(drupal_get_path('module', 'qrcode') . '/templates/pdf.tpl.php');
$content = ob_get_clean();
try {
$html2pdf = new HTML2PDF('P', 'A4', 'fr');
// $html2pdf->setTestIsImage(false);
$html2pdf->WriteHTML($content);
$html2pdf->Output($fields['ref'] . date('ymd') . '.pdf', 'D');
} catch (HTML2PDF_exception $e) {
echo $e;
exit;
}
my template pdf.tpl.php contains
<table>
<tr>
<td><img src="https://api.qrserver.com/v1/create-qr-code/?format=gif&data=<?php echo urlencode($path) ?>"/></td>
</tr>
</table>
Without using html2pdf the image is generating just fine. But when I use HTML2PDF I received
Error 6 : unable to load image https://api.qrserver.com/v1/create-qr-code/?format=gif&data=http%3A%2F%2Fm.website.fr%2Ffoo%2Fstuff
What can be wrong ?

The problem was the "s" in https://

Related

html2pdf class, convert and redirect to a page doesn't works

I'm trying to redirect after html to pdf conversion but it doesn't works. I even tried to use a JavaScript readirect via window.load, still not working. This is the code...
<?php
session_start();
include('../includes/connection.php');
include('../includes/verify.php');
$id = $_GET['id'];
$_SESSION['id_accettazione'] = $id;
$query = "SELECT * FROM ((lavori INNER JOIN mezzi ON lavori.id_mezzo = mezzi.id_mezzo) INNER JOIN clienti ON mezzi.id_proprietario = clienti.id_cliente) WHERE id_lavorazione = $id";
$mezzo = $mysqli->query($query);
$info = mysqli_fetch_array($mezzo, MYSQLI_ASSOC);
$data = $info['data_accettazione'];
// var_dump($info);
// die();
$filename = $info['nome'] . ' ' . $info['cognome'] . ' - ' . $info['marca'] . ' ' . $info['modello'] . ' - ' . $data . '.pdf';
// Carico HTML
ob_start();
include(dirname(__FILE__).'/template/foglio_lavorazione.php');
$content = ob_get_clean();
// Conversione in PDF
require_once(dirname(__FILE__).'/html2pdf.class.php');
try
{
$nomefile = $filename;
$html2pdf = new HTML2PDF('P', 'A4', 'it', true, 'UTF-8', array(10,10,10,10));
$html2pdf->setDefaultFont('Arial');
$html2pdf->writeHTML($content);
$html2pdf->Output($nomefile, 'D');
header('location:../page.php');
}
catch(HTML2PDF_exception $e) {
echo $e;
exit;
}
?>
According to the documentation, it seems that there is a mistake in your header(). It’s
header('Location: ../page.php');
not
header('location:../page.php');
Mind the case (and maybe also the space after ':'), I guess. It should at least solve one problem.

mPDF not generating PDF in firefox

I am using mPDF library for creating PDF using html data.it works fine in google chrome,but in firefox it displays nothing.No files downloaded and no errors in console.
Here is my code :
require_once( $destination_path."/mpdf/mpdf.php");
$target_path = $destination_path . '/uploads/reports/';
$htmlData='<span>Sample Html Content</span>';
try {
$pdf= new mPDF();
$pdf->debug = true;
$pdf->SetFooter("MyApp" . '|{PAGENO}|' . date(DATE_RFC822));
$pdf->WriteHTML($htmlData);
$pdf->Output($fileOutputPath, 'F');
}catch (Exception $e) {
echo 'Caught exception: ', $e, "\n";
}
i am tried ob_clean() and headers for solve the issue,but it remains same .
Anyone knows how to solve this issue?

Image is being shown as HTML but no image is shown for DOMPDF()

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!

strange symbol in RecursiveIteratorIterator

Hello I have Problem While I Listing Files in folder named upload, When There's arabic file It show ��� ����� ������
$target = "upload";
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($target));
while($it->valid()) {
if (!$it->isDot()) {
$nom=$nom+1;
echo $it->getSubPathName();
echo '<tr align="center"><td> Play </td><td>' . $it->getSubPathName() . '</td><td>' . $nom . '</td></tr>'; } }
First, convert the text to UTF-8:
iconv('CP1256', 'UTF-8', $it->getSubPathName());
Then, ensure that the web browser properly decodes the page as UTF-8. Put this as the top of your PHP file:
<?php
header("Content-Type: text/html; charset=UTF-8");
// The rest of the code

HTML to PDF Creation in Cakephp

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.

Categories