Can not set font for html2pdf in Laravel app - laravel

In laravel 5.7 app I work with spipu/html2pdf 5.2 to generate piece of html/bootstrap code
into pdf file and I have a problem with font definition
My pages use Roboto font, but if I make :
$html2pdf = new HTML2PDF('P','A4','en', true, 'UTF-8');
$html2pdf->addFont('Roboto', '', public_path('/fonts/roboto/Roboto_regular.ttf'));
I have font in my app /fonts/roboto/Roboto_regular.ttf
and I can preview it : https://prnt.sc/tgcgjq
$html2pdf->WriteHTML(htmlspecialchars_decode($pdf_content));
$html2pdf->Output($save_to_file,'F');
But I got error :
TCPDF ERROR: The font definition file has a bad format: /mnt/_work_sdb8/wwwroot/lar/the-box-booking/public/fonts/roboto/Roboto_regular.ttf
The difference in path is that I use links :
ln -s /mnt/_work_sdb8/wwwroot /_wwwroot
If I try to use times font(which I want to use for generated pdf file) as
$html2pdf->addFont('times');
I got error :
TCPDF ERROR: Could not include font definition file: &#039
looks like in last case fontname is not set , but I do not know how have I to set it ?
I have times set in my OS, I suppose I do not to put it under /public/fonts/?
Thanks!

Related

I cant make a dynamic image path in pdf

I've been trying to display an image in a fpdf file, it only works when I specify the exact location of the image. Can I make it dynamic?
Heres sample line of code:
$this->Image('fpdf/img/logo1.png',10,6,30);
and it works when I turn this way:
D:\Installed Apps\New
folder\XAMPP\htdocs\votingsystem\application\views\admin\senior\fpdf\img\logo1.png',10,6,30);
I want to transfer it to another laptop, I'm afraid it wont work.
I always get this error:
Message: fopen(fpdf/img/logo1.png): failed to open stream: No such
file or directory
I use code igniter as framework.
You can use multicell option in fpdf. I use this below code in php to it working.
`
define('ASSETS_URL','Your url or path to image file');
$yaxix = $pdf->GetY();
$xaxix = $pdf->GetX();
$pdf->MultiCell(50,10.5,$pdf->Image(ASSETS_URL.'/img/your-image-name.jpg',$xaxix,$yaxix+5,50)."\nAuthorised Signatory",1,'C',FALSE);
`
In this case you only have to change constants.

Compass/Middleman image-url isn't working

I'm currently working with Middleman to build up a new page, but now the image-url helper doesn't seem to be working.
In my config.rb I have:
#Use relative URLs
activate :relative_assets
set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'
In my applications.css.sass I have this:
body
background: image_url("background.png")
The background image is in images/background but Middleman doesn't find/load that image. It just puts this out:
body {
background: url("../images/background.png");
}
Does anyone know what I'm doing wrong?
#Use relative URLs
activate :relative_assets
I believe this is within the "build" configurations so it won't have any effect on your working file that you are viewing in middleman local server.
for me using this works "/images/hp/wmn.png"
I guess you just need to figure out the write path to your asset, as a temporary solution you can use an absolute link starting with your local server address
//0.0.0.0:4567/ for mac or
//localhost:4567/ for windows
body {
background: url("/images/background.png");
}

Can't find variable: StageWebViewBridge

I use the development tools:Adobe Flash Builder 4.6;
When I move the 'ExampleCallBackFuncions?.html' to an online server and try to load it using:
webView.loadURL("http://192.168.1.101/MapTest/ExampleBasic.html");
The html page appears but when I press the callAS3Function button I get the following error:
ReferenceError?: Can't find variable: StageWebViewBridge? callAs3Funciton at http://www.myserver.com/ExampleCallBackFuncions.html : 14
onclick at http://www.myserver.com/ExampleCallBackFuncions.html : 27
Create flex mobile project is how to interact with , and I can not always interact?
Thanks;
You need to include the project:
http://code.google.com/p/stagewebviewbridge/
It seems the file StageWebViewBridge.js is missing.
When we use stagewebviewbridge, we should include StageWebViewBridge.js file in our .html file, because, though the .js file we can make communication between as3 and js. So you could include the .js file location in your .html file.
You better to have the .js file as part of your [ MapTest ] directory, or refer .js from http://code.google.com/p/stagewebviewbridge/

how to install gmagick extension of php on windows vista

gmagick is newer version of imagemagick with more set of features it is less resource intensive and fast but the problem is there is very few discussion about this wonderful tool on web i recently came across this on
http://devzone.zend.com/1559/manipulating-images-with-php-and-graphicsmagick/
but i could not install it on windows machines cos phpize did not work so i tried some other way and some how managed to get on phpinfo page but i could not make it work further i colud not even open a single image with gmagick
this is code i used
<?php
$path="gallery/img1.jpg";
// initialize object
$image = new Gmagick($path);
echo $image;
// read image file
$file = 'gallery/img1.jpg';
$image->readImage($file);
echo '<img src="' . $file . '" width="200" height="150" /> <br/>';
?>
i used this code to instanstiate gmagick class and open image but i am geeting very big error as follows
Fatal error: Uncaught exception 'GmagickException' with message 'Unable to open file (gallery/img1.jpg)' in C:\xampp\htdocs\junk\imgproc\imgproc1.php:4 Stack trace: #0 C:\xampp\htdocs\junk\imgproc\imgproc1.php(4): Gmagick->__construct('gallery/img1.jp...') #1 {main} thrown in C:\xampp\htdocs\junk\imgproc\imgproc1.php on line 4
A) To answer the question in your headline (that might lead other readers here):
Windows builds of the GraphicsMagick extension for PHP can be obtained here:
http://valokuva.org/builds/
Check whether you need the thread-safe version or not by looking at a phpinfo(); output of your webserver. Look for the entry Thread Safety. In the entry PHP Extension Build you should also find the VC version that you need, e.g. API20090626,TS,VC9 for VC9.
Download the latest build that matches your conditions, put it into your PHP/ext directory and add it to your php.ini like this:
extension=php_gmagick_ts.dll
Remember to correct the name of the dll if you use the non-TS version.
Restart Apache and check phpinfo();. There should be a gmagick block now..
B) To correct the problem with your code:
The Gmagick constructor does not expect a path as a parameter, but a full image filename (may include a path). Most often it is better to leave it empty and provide the file in the readImage() call.
Try a full $path (starting at root) and use it in readImage() and writeImage():
Here is an example of a working piece of code:
<?php
// assuming this is the path to your code and to your image files
$path = 'C:\xampp\htdocs\junk\imgproc\';
$image = new Gmagick();
$file = 'img1.jpg';
$image->readImage($path.$file);
// The rest of your code does not make any use of the GM instance,
// so I add something functional here: create a grayscale version and show it
$fileOut= 'img1_GRAY.jpg';
$image->setImageType(Gmagick::IMGTYPE_GRAYSCALE);
$image->writeImage($path.$fileOut);
$image->destroy();
echo "<img src='$fileOut' >";
?>
It should show a grayscale version of your image file.

Missing xml tag SVG file (using Graphviz dot.exe)

My config is:
- Windows Vista
- XAMPP 1.7.1
- Media Wiki + Semantic MW
- an extension that uses Graphviz to create a SVG
- Graphviz 2.26.3 (install dir c:\graphviz.....)
Everything works fine but the problem is: the xml tag
'image xlink:href="some_image.png"....'
is missing from the SVG file created using a Media Wiki php page.
This is done by:
$cmdlinesvg = wfEscapeShellArg($cmd).' -T svg '.wfEscapeShellArg($src).' -o '.wfEscapeShellArg($svg);
$WshShell = new COM("WScript.Shell");
$WshShell->Exec($cmdlinesvg);
I've created a batch file that executes the same command line:
c:\graphviz2.26.3\bin\dot.exe -T svg filename.dot -o filename.svg
and if I run it manually it works, and the xml tag appears.
Anyone knows what is the problem? thanks in advance.
SOLVED
The problem is related to the image path that is in the .DOT file.
If you run the command line manually, the image path doesn't need to be a full path.
You can have only: shapefile="some_image.png"
If you run the command inside php code, the image path HAS to be a full path.
So you must have: shapefile="C:\xampp......\some_image.png"
Another problem arises: the resulting .SVG file doesn't show the images.
If you right-click and open the .SVG file with the browser (ie Firefox), the images are ok.
But, again, through a php page, the images are lost.
Solution: edit the .SVG file (this is XML) to change the paths.
On the original .SVG file we have:
On the modified .SVG file we must have:
PS: I'm doing my master thesis, so this is for a particular problem, but still I hope it helps someone.

Resources