How to include image in html->pdf in php class - php

How can i include an image in an html->pdf class. Here is the code I'm currently working for:
<?php
session_start();
class PrintSomething
{
function requestPrintSomething()
{
ob_start();
$root = "../";
$content = "";
include $root."assets/library/html2pdf/html2pdf.class.php";
$content .= "<img source = ../assets/images/Some_logo.PNG>";
$content .= "<p>Something Date on " . $date . " at ".$time .":00 </p>";
$content .= "
<tr>
<td> ".$somethinga ."</td>
<td> ".$somethingb."</td>
</tr>
";
$content .= "
</table>
";
$html2pdf = new HTML2PDF('L');
$html2pdf->WriteHTML($content);
$html2pdf->Output('Something List '.date("Y-m-d").'.pdf');
exit;}}?>
some info regarding the library:/**
* HTML2PDF Librairy - main class
*
* HTML => PDF convertor
* distributed under the LGPL License
*
* #author Laurent MINGUET <webmaster#html2pdf.fr>
* #version 4.03
*/
I hope someone know how to include image because I can't figure it out. I already tried the image source in html but somehow I've got a fatal error. Thanks in advance!

That img tag is not valid, src is the correct attribute to use.
$content .= "<img src='http://your_full_path/assets/images/Some_logo.PNG'>";
Also use your full path to the image.

Related

Web scraping information from the site in PHP

I do PHP script, the script must copy the list of publications (from the homepage) and copy the information that is inside these publications.
I need to copy content from my previous site and add the content to the new site!
I have some success, my PHP script copies the list of publications on the home page. I need to make a script that pulled information inside each publication (title, photo, full text)!
For this, I wrote a function that extracts a link to each post.
Help me write a function that will copy information on a given link!
<?php
header('Content-type: text/html; charset=utf-8');
require 'phpQuery.php';
function print_arr($arr){
echo '<pre>' . print_r($arr, true) . '</pre>';
}
$url = 'http://goruzont.blogspot.com/';
$file = file_get_contents($url);
$doc = phpQuery::newDocument($file);
foreach($doc->find('.blog-posts .post-outer .post') as $article){
$article = pq($article);
$text = $article->find('.entry-title a')->html();
print_arr($text);
$texturl = $article->find('.entry-title a')->attr('href');
echo $texturl;
$text = $article->find('.date-header')->html();
print_arr($text);
$img = $article->find('.thumb a')->attr('style');
$img."<br>"; if (preg_match('!background:url.(.+). no!',$img,$match)) {
$imgurl = $match[1];
} else
{echo "<img src = http://goruzont.blogspot.com".$item.">";}
echo "<img src='$imgurl'>";
}
?>

Best Practice to Print Barcode In dompdf

I want to create a label sticker with barcode in PDF.
Please give me the suggestion to create this things.
Now , I use CI3 and dompdf.
I have tried googling a lot of time, but I am not found the best practice to realized this thing.
I followed your suggestion,
Now I have folder in vendor/Piqcer.
I try this into my view_report like this:
<tr>
<td class="solid" colspan="2">
<?= $value->NO_URUT ?>
<?php
$generator = new \Picqer\Barcode\BarcodeGeneratorPNG();
echo '<img src="data:image/png;base64,' . base64_encode($generator->getBarcode($value->NO_URUT, $generator::TYPE_CODE_128)) . '">';
?>
</td>
</tr>
But I got error :
Fatal error: Class 'Picqer\Barcode\BarcodeGeneratorPNG' not found
UPDATE
So, this library is on ci_folder\vendor\picqer\php-barcode-generator.
Now I create an autoload library like this :
class Barcode {
public function generate($id) {
require_once("./vendor/picqer/php-barcode-generator/src/BarcodeGeneratorJPG.php");
$generator = new Picqer\Barcode\BarcodeGeneratorJPG();
echo $generator->getBarcode($id, $generator::TYPE_CODE_128);
}
}
IN my controller :
$this->load->library('dompdfgenerator');
$this->load->library('barcode');
$data = array(
'result' => $result,
'container' => $containers
);
$html = $this->load->view('members/megumi/check_list_per_tanggal/v_laporan_sticker_pilihan', $data, true);
$this->dompdfgenerator->generate($html, "$identity");
Now in view :
<tr>
<td class="solid" colspan="2">
<?= $value->NO_URUT ?>
<?php
echo '<img src="data:image/png;base64,' . base64_encode($this->barcode->generate($value->NO_URUT)) . '">';
?>
</td>
</tr>
It still : Fatal error: Class 'Picqer\Barcode\BarcodeGenerator' not found
Please advise...
Have you tried using libraries, such as PHP Barcode Generator. It will generate a barcode for you and export it as an SVG, PNG or JPG or HTML. You should just insert the resulting barcode to the HTML you wil lbe exporting with DOMPDF.

How to Displaying an image with path stored in Database?

I have stored images path in database and images in project folder. Now i am trying to view all IMAGES with their PRODUCTS in my HTML template. I have written the following code and its given me an empty images box in the output and when i open that image box in the new tab, it opens the following URL.
http://localhost/cms/1
Kindly tell me the way of referring images in 'img src ' tag.
include 'connect.php';
$image_query = "select * from product_images";
$image_query_run = mysql_query($image_query);
$image_query_fetch = mysql_fetch_array($image_query_run);
if (!$query=mysql_query ("select product_id,name from products")) {
echo mysql_error();
} else {
while ($query_array = mysql_fetch_array($query)) {
echo '</br><pre>';
$product_id = $query_array['product_id'];
echo "<a href='single_product.php?product_id=$product_id' >";
print_r ($query_array['name']);
echo "</a>";
echo "<img src=". $image_query_fetch
['images'] ." alt=\"\" />";
echo '</pre>';
}
}
} else {
echo "You need to Log in to visit this Page";
}
Add your local image path before source
example
echo "<img src='http://localhost/cms/1/". $image_query_fetch['images'] .'" alt=\"\" />";
*Use PHP *
<?php echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>
You can use the HTML base tag to set a base URL that relative URLs will be resolved from.
See -> http://www.w3schools.com/tags/tag_base.asp

Adding embedded images within mail body phpmailer class

Im trying to embed an image within my message body but it ends up as an attachment
$mailer->Subject = APP_NAME . " - " . $name . " send you and Ad : " . $row['name'];
$mailer->IsHTML(true);
$mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDimes.png');
//footer
$footer = "Regards<br/><br/>";
$footer .= '<table style="width: 95%">';
$footer .= '<tr>';
$footer .= '<td>';
$footer .= "<strong><span style='font-size: 15px'>NamDimes Team</span></strong><br/>
NamDimes<br/>
Contact Number: " . APP_CONTACT . "<br/>
Email: " . APP_EMAIL . "<br/>
Website: " . APP_WEBSITE . "<br/>";
$footer .= '</td>';
$footer .= '<td style="text-align:right">';
$footer .= '<img src=\"cid:logoimg\" />';
$footer .= '</td>';
$footer .= '</tr>';
$footer .= '</table>';
$mailer->Body = $body . $footer;
$mailer->AltBody="This is text only alternative body.";
$mailer->AddAttachment('../' . $row['image_path'], $row['name'] . ".jpg");
i have set everything else, including the addresses, the mail gets send out, logo image that I want embed in the body gets attached as an attachment, anyone know why?
Don't use $mailer->AddEmbeddedImage, but directly add
<img src="http://.../images/namDiams.png" /> instead.
The mail length should be lighter... And it works.
EDIT
I don't know if it will help you but there is a little mistake here :
$mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDimes.png');
Should be
$mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDiames.png');//the last param the second 'a' was missing...
Another topic here
I can confirm that user2189925's answer does work. However, I use the absolute path since the location of the calling script is more likely to change than the location of the image.
e.g.
<img src="C:\folder\images\namDiames.png" />
Faced the same problem, then I decided to replace the following
<img src="img/example.jpg"
with
<img src= "https://mysitename.com/img/example.jpg">
and it worked.
just give path of your image to the mail body eg: (img src="../images/cat.jpeg) it will definately work

Pulling wiki to html using php and javascript

I would like to change wiki syntax to html using these techniques mentioned here.
http://www.ladyada.net/library/software/wiki.html
Here is the source code of my php page which seems to work fine. You may try yourself like this:
http://temelelektronik.net/wiki/show.php?id=test
<?
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__)).'/');
require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC.'inc/common.php');
require_once(DOKU_INC.'inc/events.php');
require_once(DOKU_INC.'inc/pageutils.php');
require_once(DOKU_INC.'inc/html.php');
require_once(DOKU_INC.'inc/auth.php');
require_once(DOKU_INC.'inc/actions.php');
//import variables
$QUERY = trim($_REQUEST['id']);
$ID = getID();
$REV = $_REQUEST['rev'];
$HIGH = $_REQUEST['s'];
if(empty($HIGH)) $HIGH = getGoogleQuery();
//sanitize revision
$REV = preg_replace('/[^0-9]/','',$REV);
$html = p_wiki_xhtml($ID,$REV,true);
$html = addslashes($html);
$html = ereg_replace("\n", '\n'."\\\n", $html);
$html = str_replace("</a>", "</a> ", $html);
echo ('var zoomy = "'.$html.'";');
echo ("document.write(zoomy);");
$url = "http://www.temelelektronik.net/wiki/" . str_replace(':', '/', $_REQUEST['id']);
$footer = '<hr /><br /><em>This page was autogenerated from
' . $url . ' <br />Please edit the wiki to contribute any updates or corrections.</em>';
$footer = '"' . $footer . '"';
echo ('document.write('. $footer . ')');
?>
But when I add this Javascript code to a blank html page I see nothing. Here is the HTML file.
<html>
<head>
<script language="Javascript" src="/show.php?id=test"></script>
</head>
<body>
</body>
</html>
As you'd see it shows nothing.
http://temelelektronik.net/wiki/test.html
How can I solve this issue? Any help you can give will be greatly appreciated. Thanks..
Because you supplied the wrong URL?
http://temelelektronik.net/wiki/show.php?id=test
vs.
<script language="Javascript" src="/show.php?id=test"></script>
Apparently it should be /wiki/show.php?id=test

Categories