Print INR symbol in PDF using DomPDF - laravel

I want to print INR (Indian rupee) symbol in PDF but failed, when PDF got generated it shows ? instead on ₹.
"barryvdh/laravel-dompdf": "^0.8.3"
I have generated PDF like :
use Barryvdh\DomPDF\Facade as PDF;
$pdf = PDF::loadView('report-test')->setPaper('a4');
return $pdf->stream('payslip.pdf');
PDF Html :
<p>Price ₹ 9500 = ₹ 9500</p>
<p>Price ₹ 5500 = ₹ 5500</p>
<p>Price ₨ 500 = ₨ 500</p>
<p>Price ₨ 2000 = ₨ 2000</p>
<p>Price ₹ 2000 = ₹ 2000</p>
<p style="font-family: dejavusans !important;">Price र rupee </p>
<p>I will display ₹</p>
<p>I will display ₹</p>
Also i have added <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> in header, still no luck.
Anything i am missing?
Thanks in Advance

Related

How can I make selenium calls in Laravel 9 from selenium docker container?

I want to make selenium web requests to real websites.
I managed to get php-webdriver work with a local installation of chromedriver. However, this has caused many problems for me, as having a compatible version of Chromedriver and Chrome is tricky and I run into a lot of session and timeout-exceptions.
This is how it works with the local chromedriver.
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
// This is where Selenium server 2/3 listens by default. For Selenium 4, Chromedriver or Geckodriver, use http://localhost:4444/
$host = 'http://localhost:4444';
$capabilities = DesiredCapabilities::chrome();
$driver = RemoteWebDriver::create($host, $capabilities);
$url = "https://stackoverflow.com/questions/70976750/adjusting-shape-of-a-data-array-to-perform-optimization-in-scipy";
$driver->get($url);
I wonder now, can I use the selenium docker image that ships with Laravel 9 to make selenium web requests in my Laravel application without local installation of the chromedirver? If so, what do I have to specify for host in the above code?
If I leave the code unchanged, I get
Failed to connect to localhost port 4444: Connection refused
although the image "selenium/standalone-chrome" has "4444/tcp" as port.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
756f331870b4 sail-8.1/app "start-container" 2 hours ago Up 2 hours 8000/tcp, 0.0.0.0:8011->80/tcp, :::8011->80/tcp laravel-flathunter_laravel.test_1
fa84b628f814 selenium/standalone-chrome "/opt/bin/entry_poin…" 2 hours ago Up 2 hours 4444/tcp laravel-flathunter_selenium_1
0457fa502c43 redis:alpine "docker-entrypoint.s…" 2 hours ago Up 2 hours (healthy) 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp laravel-flathunter_redis_1
d122fd0f4bcd mysql/mysql-server:8.0 "/entrypoint.sh mysq…" 2 hours ago Up 2 hours (healthy) 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060-33061/tcp laravel-flathunter_mysql_1
aef91bbba6ca mailhog/mailhog:latest "MailHog" 2 hours ago Up 2 hours 0.0.0.0:1025->1025/tcp, :::1025->1025/tcp, 0.0.0.0:8025->8025/tcp, :::8025->8025/tcp laravel-flathunter_mailhog_1
f0267f810dec getmeili/meilisearch:latest "tini -- /bin/sh -c …" 2 hours ago Up 2 hours (healthy) 0.0.0.0:7700->7700/tcp, :::7700->7700/tcp laravel-flathunter_meilisearch_1
Edit: If I use selenium:4444 then RemoteWebDriver::create fails with the following:
Facebook\WebDriver\Exception\WebDriverException
JSON decoding of remote response failed.
Error code: 4
The response: '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="/assets/displayhelpservlet.css" media="all"/>
<link href="/assets/favicon.ico" rel="icon" type="image/x-icon" />
<script src="/assets/jquery-3.1.1.min.js" type="text/javascript"></script>
<script src="/assets/displayhelpservlet.js" type="text/javascript"></script>
<script type="text/javascript">
var json = Object.freeze('{"consoleLink": "\u002fwd\u002fhub","type": "Standalone","class": "org.openqa.grid.web.servlet.DisplayHelpHandler$DisplayHelpServletConfig","version": "3.141.59"}');
</script>
</head>
<body>
<div id="content">
<div id="help-heading">
<h1><span id="logo"></span></h1>
<h2>Selenium <span class="se-type"></span> v.<span class="se-version"></span></h2>
</div>
<div id="content-body">
<p>
Whoops! The URL specified routes to this help page.
</p>
<p>
For more information about Selenium <span class="se-type"></span> please see the
<a class="se-docs">docs</a> and/or visit the <a class="se-wiki">wiki</a>.
<span id="console-item">
Or perhaps you are looking for the Selenium <span class="se-type"></span> <a class="se-console">console</a>.
</span>
</p>
<p>
Happy Testing!
</p>
</div>
<div>
<footer id="help-footer">
Selenium is made possible through the efforts of our open source community, contributions from
these people, and our
sponsors.
</footer>
</div>
</div>
</body>
</html>'
at vendor/php-webdriver/webdriver/lib/Remote/HttpCommandExecutor.php:339
335▕
336▕ $results = json_decode($raw_results, true);
337▕
338▕ if ($results === null && json_last_error() !== JSON_ERROR_NONE) {
➜ 339▕ throw new WebDriverException(
340▕ sprintf(
341▕ "JSON decoding of remote response failed.\n" .
342▕ "Error code: %d\n" .
343▕ "The response: '%s'\n",
+1 vendor frames
2 app/Console/Commands/TestSelenium.php:37
Facebook\WebDriver\Remote\RemoteWebDriver::create()
+13 vendor frames
16 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
ERROR: 1

Outlook Redemption unwrappedRdoMail adds 'B' character to empty HTML paragraph

We are seeing a change to the HTML body of a mail item when unwrapping the RDOMail from the unwrapped RDOStore.
We have tried with the latest Redemption code (5.23)
The code we are using follows:
RDOStores rdoStores;
RDOStore rdoStore, unwrappedRdoStore;
RDOFolder rdoFolder;
RDOMail unwrappedRdoMail;
using (_comObjectHelper.GetMonitor(rdoFolder = mail.Parent))
using (_comObjectHelper.GetMonitor(rdoStore = rdoFolder.Store))
using (_comObjectHelper.GetMonitor(rdoStores = rdoSession.Stores))
using (_comObjectHelper.GetMonitor(unwrappedRdoStore = rdoStores.UnwrapStore(rdoStore)))
using (_comObjectHelper.GetMonitor(unwrappedRdoMail = unwrappedRdoStore.GetMessageFromID(mail.EntryID)))
{
rdoMailAction?.Invoke(unwrappedRdoMail);
unwrappedRdoMail.Save();
}
IRDOMail item HTMLBody from rdoSession.GetRDOObjectFromOutlookObject(_MailItem) (correct):
<html>
<head>
<meta name=\"Generator\" content=\"Microsoft Word 15 (filtered medium)\" />
<style>
<!--\r\n/* Font Definitions */\r\n#font-face\r\n\t{font-family:\"Cambria Math\";\r\n\tpanose-1:2 4 5 3 5 4 6 3 2 4;}\r\n#font-face\r\n\t{font-family:Calibri;\r\n\tpanose-1:2 15 5 2 2 2 4 3 2 4;}\r\n/* Style Definitions */\r\np.MsoNormal, li.MsoNormal, div.MsoNormal\r\n\t{margin:0in;\r\n\tmargin-bottom:.0001pt;\r\n\tfont-size:11.0pt;\r\n\tfont-family:\"Calibri\",sans-serif;}\r\nspan.EmailStyle17\r\n\t{mso-style-type:personal-compose;\r\n\tfont-family:\"Calibri\",sans-serif;\r\n\tcolor:windowtext;}\r\n.MsoChpDefault\r\n\t{mso-style-type:export-only;\r\n\tfont-family:\"Calibri\",sans-serif;}\r\n#page WordSection1\r\n\t{size:8.5in 11.0in;\r\n\tmargin:1.0in 1.0in 1.0in 1.0in;}\r\ndiv.WordSection1\r\n\t{page:WordSection1;}\r\n-->
</style>
</head>
<body lang=\"EN-US\" link=\"#0563C1\" vlink=\"#954F72\">
<div class=\"WordSection1\">
<p class=\"MsoNormal\">test </p>
<p class=\"MsoNormal\"> </p>
<p class=\"MsoNormal\">test </p>
<p class=\"MsoNormal\"> </p>
<p class=\"MsoNormal\">test</p>
<p class=\"MsoNormal\"> </p>
<p class=\"MsoNormal\">test test</p>
</div>
<span/>
</body>
</html>\r\n
RDOMail unwrappedRdoMail item HTMLBody (incorrect - extra 'B' characters on blank paragraphs):
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=us-ascii\">
<meta name=\"Generator\" content=\"Microsoft Word 15 (filtered medium)\">
<style>
<!--\r\n/* Font Definitions */\r\n#font-face\r\n\t{font-family:\"Cambria Math\";\r\n\tpanose-1:2 4 5 3 5 4 6 3 2 4;}\r\n#font-face\r\n\t{font-family:Calibri;\r\n\tpanose-1:2 15 5 2 2 2 4 3 2 4;}\r\n/* Style Definitions */\r\np.MsoNormal, li.MsoNormal, div.MsoNormal\r\n\t{margin:0in;\r\n\tmargin-bottom:.0001pt;\r\n\tfont-size:11.0pt;\r\n\tfont-family:\"Calibri\",sans-serif;}\r\nspan.EmailStyle17\r\n\t{mso-style-type:personal-compose;\r\n\tfont-family:\"Calibri\",sans-serif;\r\n\tcolor:windowtext;}\r\n.MsoChpDefault\r\n\t{mso-style-type:export-only;\r\n\tfont-family:\"Calibri\",sans-serif;}\r\n#page WordSection1\r\n\t{size:8.5in 11.0in;\r\n\tmargin:1.0in 1.0in 1.0in 1.0in;}\r\ndiv.WordSection1\r\n\t{page:WordSection1;}\r\n-->
</style>
</head>
<body lang=\"EN-US\" link=\"#0563C1\" vlink=\"#954F72\">
<div class=\"WordSection1\">
<p class=\"MsoNormal\">test </p>
<p class=\"MsoNormal\">B </p>
<p class=\"MsoNormal\">test </p>
<p class=\"MsoNormal\">B </p>
<p class=\"MsoNormal\">test</p>
<p class=\"MsoNormal\"> </p>
<p class=\"MsoNormal\">test test</p>
</div>
<span/>
</body>
</html>\r\n
Has anyone seen this behaviour? Any ideas on how to solve this problem?
Turned out there was some funny characters  and a0 in the received email, which points to incompatibilities between the 2 different mail servers (GSuite and IMAP).
Nothing could be done in this case.

The code is sending 2 times without proper image

I tried this code from the post, but this code is sending two emails on a single run of file.
Email file is sending email two times using php mail function
Let me know what i am doing wrong -
<?php
function mytextoverimage( $mytext ) {
$headurl = 'http://dummyimage.com/600x400/ffffee/00d5ff.jpg';
header('Content-type: image/jpeg');
$jpg_image = imagecreatefromjpeg($headurl);
$black = imagecolorallocate($jpg_image, 1, 1, 1);
$font_path = 'myfont/arial.ttf';
$text = $mytext;
imagettftext($jpg_image, 24, 0, 175, 85, $black, $font_path, $text);
imagejpeg($jpg_image);
imagedestroy($jpg_image);
}
$to = "myemail#gmail.com";
$subject = "This is a image conversion from Developer Zone";
$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= 'From: developer#phpdev.com' . "\r\n" .
'Reply-To: testabc#testabc.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Title</title>
</head>
<body>
<table width="100%" cellspacing="5" cellpadding="0" border="0" bgcolor="#f0f0f0" style="color:666666;text-align:left; font:12px Verdana, Geneva, sans-serif">
<tr>
<td >'.mytextoverimage('Developer').'</td></tr></table></body></html>';
mail($to,$subject,$message,$headers); die;
Let me know what i am doing wrong, is this the correct method I am using this --
<img src="'.mytextoverimage('Developer').'" />
I followed this URL but hard to crack any help from this page- http://php.net/manual/en/function.imagejpeg.php
I even tried keeping that method mytextoverimage() in another file but still no help, email sending twice :(
Your mytextoverimage() function doesn't return anything - it just sends a jpeg image to the browser.
I've reworked your code to send the same image via email - note that just the image is sent, no HMTL.
If you want to send an image as part of an HTML document, you need to go a step further and create a multipart message - check out How to attach and show image in mail using php?
This works for Gmail on Iceweasel 10.0.11.
<?php
function mytextoverimage( $mytext )
{
$headurl = 'http://dummyimage.com/600x400/ffffee/00d5ff.jpg';
$jpg_image = imagecreatefromjpeg($headurl);
$black = imagecolorallocate($jpg_image, 1, 1, 1);
$font_path = 'myfont/arial.ttf';
$text = $mytext;
imagettftext($jpg_image, 24, 0, 175, 85, $black, $font_path, $text);
ob_start(); //Get the image data from the output buffer
imagejpeg($jpg_image);
imagedestroy($jpg_image);
return chunk_split(base64_encode(ob_get_clean())); //return the image data, encoded for email transfer
}
$to = "myemail#gmail.com";
$subject = "This is a image conversion from Developer Zone";
// --- Note the change from text/html to image/jpeg ---
$headers = "Content-type: image/jpeg;\r\n";
//$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= 'From: developer#phpdev.com' . "\r\n" .
'Reply-To: testabc#testabc.com' . "\r\n" .
'Content-Transfer-Encoding: base64' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = mytextoverimage('Developer');
mail($to,$subject,$message,$headers); die;
Yes you are doing it wrong. Imagejpg function returns and image, but you need a url to put it inside a tag. What you should do is use SWIFT mailer and send that image you created as ann attachment to the email.
you can read on it here:
http://swiftmailer.org/docs/messages.html
It would belike this:
//Create the message
$img = $message->embed(Swift_Image::fromPath('body1.jpg'));
//Set the body
$message->setBody(
'<html>' .
' <head></head>' .
' <body>' .
" <img src='$img'/>"
' </body>' .
'</html>',
'text/html' //Mark the content-type as HTML
);
As per as my question was concerned I solved it, like in this way -
<?php
function myimagecreate( $name )
{
$headurl = 'http://dummyimage.com/600x300/f5ebf5/f2f2f7.jpg';
header('Content-type: image/jpeg');
$text = $name;
$name =$name.".jpg";
$filepath = 'http://MY_SITE_URL.com/'."myfont";
$jpg_image = imagecreatefromjpeg($headurl);
$black = imagecolorallocate($jpg_image, 1, 1, 1);
$font_path = 'myfont/Ayuma2yk.ttf';
imagettftext($jpg_image, 24, 0, 175, 85, $black, $font_path, $text);
imagejpeg($jpg_image,$name);
imagedestroy($jpg_image);
return $name;
}
$to = 'YOUREMAIL#gmail.com';
$subject = 'Swapnesh Sinha - For PHP GD Library';
$message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Swapnesh Sinha</title>
</head>
<body>
<table width="600px" bgcolor="#f0f0f0" style="color:666666;text-align:left; font:12px Verdana, Geneva, sans-serif">
<tr>
<td>
<img src="http://MY_SITE_URL.com/'.myimagecreate('Swapnesh').'" style="display:block" />
</td>
</tr>
</table>
</body>
</html>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Swapnesh Sinha <MyMAIL#gmail.com>'. "\r\n";
$bool = mail($to,$subject,$message,$headers);
if($bool)
echo "Email is sent successfully";
else
echo "Something is missing in the code, please check the code properly!!";
?>
Just save the code in any root file "Yourfile.php" and run.
This will create an image and save to root location(you can force to save it another location also).
Follow these two links as well -
LINK 1
LINK 2

Email file is sending email two times using php mail function

My three concerns, tried different combos with no result, googled but little or no help --
I received two times the email,change myemail#emailserver.com to the email id to see the result.
While executing this file I am getting image, however I want to have text "Email Sent".
Full HTML content with tag is passed instead of HTML rendering in email.
My Working Code -->
<?php
header('Content-type: image/jpeg');
$jpg_image = imagecreatefromjpeg('http://dummyimage.com/600x400/f5f5f5/fff.jpg');
$black = imagecolorallocate($jpg_image, 1, 1, 1);
$font_path = 'myfont/arial.ttf';
$text = "Swapnesh Sinha!";
imagettftext($jpg_image, 24, 0, 175, 85, $black, $font_path, $text);
$tip = imagejpeg($jpg_image);
$imageData = base64_encode($tip);
//$src = 'data: '.mime_content_type($jpg_image).';base64,'.$imageData;
imagedestroy($jpg_image);
?>
<html>
<head></head>
<body>
<p>
<?php
$to = 'myemail#emailserver.com';
$subject = "Thisa is a email test to find image work";
$message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MY SITE TITLE</title>
</head><body><table><tr><td>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</td></tr><tr><img src="'.'http://mysiteurl/addtext.php'.'" /></tr></table></body></html>';
$headers = 'From: myemail#emailserver.com' . "\r\n" .
'Reply-To: myemail#emailserver.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$bool = mail($to, $subject, $message, $headers);
if($bool)
echo "Email Sent";
else
echo "Email Not Sent";
?>
</body>
</html>
NOTE - In <img src="'.'http://mysiteurl/addtext.php'.'" />
http://mysiteurl/addtext.php is the same where we have all this above content.
First thing I'd do is check your apache/IIS logs to ensure that the URL isn't being called twice (just a sanity check).
If the PHP page you've added to your OP is http://mysiteurl/addtext.php, then it would be called twice, once renderering the HTML, then the browser would call it again when rendering the <img ...> tag.
To fix this you need to either split it into two PHP files (recommended), or pass a GET parameter to toggle the image processing.
You'll also need to add $headers .= "Content-type: text/html\r\n"; so that the email is rendered as html and not plain text.

Decoding Outlook's "J" smilies into text

Outlook by default transforms ":)" into "J". Googling has revealed that J is the Wingdings character for the smilie, so they appear like normal smilies to Outlook users.
I want to transform these "J" smilies into the UTF-8 smiley characters so the rest of us can see them too. But when looking at the source of an email, the "J" smilie lines look like this:
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">J<o:p></o:p></span></p>
That is, just like normal Outlook formatting that you see on every other line. No font-family other than Calibri and Times New Roman is even mentioned anywhere in the source. So just how is Outlook decoding these J's back into smilies? How do I?
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
#font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
#font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Balloon Text Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.dp-replycode
{mso-style-name:dp-replycode;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.BalloonTextChar
{mso-style-name:"Balloon Text Char";
mso-style-priority:99;
mso-style-link:"Balloon Text";
font-family:"Tahoma","sans-serif";}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
#page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Some message
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">J<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<div>
....
I'm just an idiot. I was using client data as a source of Outlook emails since I didn't readily have an Outlook client available. After setting it up and testing for myself, the family:Wingdings is indeed in the source. Turns out the client was just signing his emails with "J"!
Now it's simple enough looking for font-family:Wingdings and converting them into UTF-8 smilies.

Resources