PHP mPDF base64 image error - could not find image file () - php

According documentation I would like to use mpdf with base64 image to preview img tag in document. Everything should be ok, if I show the base64 image in html page it wortks fine. But mpdf throws me an error:
Could not find image file ()
The code looks like this and as I said in html it works but not in mpdf:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG8AAA....."
Can somebody tell me please what is wrong? Documentation is simple. Why mpdf does not recognize base64 data? Thanks for any help.

Related

Storing Images In a PHP File

I have been trying to change the images in the WampServer Index.php File... When I looked at the Index.php File I saw something Interesting. The File its self was containing the Image in the RAW format. Latter in the Code the PHP Script Calls the Image using the URL like http://localhost/index.php?img=pngFolder called a Image file stored RAW in the PHP file as a png.
Here is a link to a website that has the index.php code...
Link
I would Like to know how to replicate this same process to work for other images. Granted the File will be larger but its a Price to pay for what I am doing for a project. The Reason I want some help with this is so I can do it correctly. I have Tried 2 times already. I managed to get it to call one image correctly but not some of the others. I'm not sure if the image is just a different encoding or what..... Any Help would be Appreciated.
They are using BASE64 to encode the images into text. You can google for a base64 encoder that will convert your images to text. You can then put the text directly in an <img src="..base64 text.." />
Here's one..
https://www.base64-image.de/
As far as getting the image from the url index.php?img=pngfolder..
You could put this at the top of the file
if(isset($_GET['img'])){
echo "...base64 string.."; exit;
}
Then you can use the index url as the src for your image and it will simply retrieve the base64 image

How to view the uploaded(.doc) file in a div?

I uploaded the .doc file using php code and saved it in a folder ,the path is stored in database.
When i tried to make a view of the doc file in a div ...a dialog box appears asking whether to save or openwith ..
I'm using wampserver ....I just tried like this
<iframe name="awindow" frameborder=2 width=580 height=440 src="www/siva_example/pdf/1_siva.doc"></iframe>
Any help regarding..
Is it possible to view .doc file in browser or i have to convert it to pdf format...
It's not possible to display a .doc[x] in HTML. You can try to convert the .doc[x] to HTML or to an image.
you can view doc file by adding this to your header at request time
<?php
header('Content-disposition: inline');
header('Content-type: application/msword');
// not sure if this is the correct MIME type
readfile('MyWordDocument.doc');
exit;
You could try using google docs for this, use the below code, it works perfectly for ppts, have not been able to test it for a doc yet
<iframe src="http://docs.google.com/gview?url=http://yourdomain.com/document.doc&embedded=true" style="width:550px; height:450px;" frameborder="0"></iframe>
Ofcourse you would have to update the url as per your program using PHP

Picture display with PHP

I've a problem with some lines of code. I try to generate a picture with php and the gd2 librarie.
<?php
header('Content-type: image/jpeg');
$im = imagecreatefromjpeg('profil.jpg');
imagejpeg($im);
imagedestroy($im);?>
This code doesn't work. There's no image displayed, just a message : "this image can't be displayed because there's error" displayed in white on grey background.
The picture is well loaded and "$im" is a resource created with "imagecreatefromjpeg"...
If i remove all lines except header('Content-type: image/jpeg');, I've got the same problem.
Who can give me the right way ??
Thanks by advance !
Mickael
Nmae that php file image.php and call it as source of image tag in another php file. Then that will show the image.
<img src="image.php" height="250px" width="162px">
Click Here To Download Example From Google
Working good after creating a new php file where I pasted my code.
I think that my file was corrupt.
I just tried your code.
The only error I get is when profil.jpg is not present in the same directory.
is profil.jpg in the same directory as your .php file ?

php image save to dir and save to pdf

Im using http://www.ashberg.de/php-barcode/ scripts to generate a barcode. I now need to import the barcode into a PDF from html. (Im using html2pdf_v4.03 for html -> pdf)
<div style=" display:inline;"><img id='barcode' alt='barcode' src="scripts/barcode/barcode.php?mode=jpg" /></div>
works, but when I import it to PDF it errors. So I decided to try generate the barcode and save it to a dir as an img and refrence it in the html I then convert to PDF.
So I tried
file_put_contents('scripts/barcode.jpg', file_get_contents('scripts/barcode/barcode.php?mode=jpg'));
and I get failed to open stream: error
if i try
file_put_contents('scripts/barcode.jpg', file_get_contents('scripts/barcode/barcode.php'));
It runs but the image file it creates is not readable/ broken.
Please assist?
Write full url (http://domain.com/scripts/barcode/barcode.php) instead of scripts/barcode/barcode.php. Probably its opens local php file when you use file_get_contents()

php-jquery-pdf load a pdf on a div

I'm trying to display by jquery load() a dynamically generated PDF created by PHP with FPDFlib on a div but what I get is a jam of chars. Is there a way to resolve it?
thanks in advance
I've tried to correct my code in this way but continue to display jam
$.post("./php/stampa_login.php",
{piatta:'<? echo $_POST["piatta"] ?>'},
function(data){
$("#stampa_content").load("./temp/login.pdf")
});
ciao
h.
That seems to be correct. jQuery's load() fetches an URL through AJAX; if that URL is PDF, it appears as "jam of chars" to the browser, as PDF and HTML aren't compatible at all, the formats are completely different.
What you probably want is to open the PDF as an <object>, but then you're hoping that the user has some PDF plugin installed in their browser. Let's take a step back: what are you trying to achieve here, by displaying a PDF?
You can create a blank embed tag and give src attribute as link. in your call back function. This will load the pdf file perfectly.
$("#embed_tag_id").attr("src", "./temp/login.pdf");
Instead of using $("#whatever").load();
You'll want something like this:
$("#stampa_content").html ($("<object>", {
data : "./temp/login.pdf",
type : "application/pdf",
width : 800,
height : 600
}));
What that will do is instead of trying to load the contents of the PDF into a DIV, it will create an <object> block that will start up your PDF reader (such as Adobe Reader) which will then load the PDF itself and display it.
ya, seems to be an output issue. Have you tried header function to output it correctly ? try for proper output or instead of opening the pdf in div, just update the pdf's link there

Categories