I am trying to generate PDF from Excel, but I get the following error:
TCPDF ERROR: [Image] Unable to get image:./var/www/projects/.../0401b0ca555959f391752bb1b0ea9ba1.jpg
Looking though Excel, I can find /var/www/projects/.../0401b0ca555959f391752bb1b0ea9ba1.jpg, but without the . before it.
Can the dot be a reason that failed converting?
./var/www/projects/.../0401b0ca555959f391752bb1b0ea9ba1.jpg
The '.' before that means that it will be looking in current directory for a folder called var.
You will need to remove this . in order to begin at the root. Which is correct.
This is how it should look '/var/www/projects/.../0401b0ca555959f391752bb1b0ea9ba1.jpg'
It looks like you are trying to use cURL to get the image, so i suggest you should try and change the image to be a URL such as http://URL of project folder/../0401b0ca555959f391752bb1b0ea9ba1.jpg
Other than that suggestion its hard to know what is happeneing but i suspect the TCPDF is not playing nicely.
Related
I am using DOMPDF library to convert HTML to PDF at runtime. However, I am facing an issue related to images. System displays images when I render HTML code but when I convert it into PDF, it replace all images by "broken_image.png". I have placed complete url (given below) of images, its still not working for me :/ . Below is the example image url:
<img src='http://img.uksoccershop.com/images/man-utd-gk-away-shirt-2012-13.jpg'/>
Can anyone please tell me how can I resolve the issue. Thanks in advance.
To enable remote images for DOMPDF u have to alter the config dompdf_config.inc.php
Look near line 284 :
def("DOMPDF_ENABLE_REMOTE", false);
This should be set to true. Also be sure that the temp directory defined near line 103 is writeable :
def("DOMPDF_TEMP_DIR", sys_get_temp_dir());
DOMPDF is not a browser, it won't download images or any other assets, it simply converts HTML/CSS into a PDF representation.
You'll need something like wkhtmltopdf to achieve this.
I'm using fpdf class file to generate pdf in my php program. I want to use true type font named tahoma. Generated .z,.afm,.ttf,.php files from a website.
I've included makefont.php in my program and used a function makefont(). But it shows me an error "Can't write to file tahoma.z". I've done everything as per tutorial I read. I couldn't figure it out what mistake I've done. Please somebody help me out.
require('pdf/makefont/makefont.php');
MakeFont("pdf/font/tahoma.ttf","cp1252","true");
I've checked availability of all the file and spelling too.
I found what had I done wrong. No need for make any fonts since I have .php and .z files. I simply put on font directory and used "AddFont()" function. that's it.
I have a DB system built in PHP/MySql. I'm fairly new at this. The system allows the user to upload an invoice. Others give permission to pay the invoice. The accounting person uploads the check. After check is uploaded, it generates a PDF as a cover, then uses PDFTK (using Ben Squire's PDFTK-PHP-Library) to combine all of the files together and present the user with a single PDF to download.
Some users upload PDF files which cause PDFTK to hang indefinitely when it tries to combine the PDF with others (but most of the time it works fine). No returned error, just hangs. In order to get back onto the sytem, user must clear cache and re-log in. There are no error messages logged by the server, it just freezes. The only difference I can find in the files that do or do not work in looking at them with Acrobat is that the bad files are legal sized (8.5 x 14) ... but if I create my own legal sized file and try that, it works fine.
Using Putty I've gone to command line and replicated the same problem, PDFTK can't read the file, it hangs on the command line as well. I tried using PDFMerge which uses FPDF to combine the files and get an error with the file as well (The error I get back from this is: FPDF error: Unable to find object (4, 0) at expected location). On the command line I was able to use ImageMagick to convert PDF to JPG, but it gives me an error: "Warning: File has an invalid xref entry: 2. Rebuilding xref table." and then it converts it to a jpg but gives a few other less helpful warnings.
If I could get PHP to check the PDF file to determine if is valid without hanging the system, I could use ImageMagick to convert the file and then convert it back to a PDF, but I don't want to do this to all files. How can I get it to check the validity of the file when uploaded to see if it needs to be converted without causing the system to hang?
Here is a link to a file that is causing problems: http://www.cssc-testing.org/accounting/school_9/20130604-a1atransportation-1.pdf
Thanks in advance for any guidance you can offer!
My Code (which I'm guessing is not very clean, as I'm new):
$pdftk = new pdftk();
if($create_cover) { $pdftk->setInputFile(array("filename" => $cover_page['server'])); }
// Load a list of attachments
$sql = "SELECT * FROM actg_attachments WHERE trans_id = {$trans_id}";
$attachments = Attachment::find_by_sql($sql);
foreach($attachments as $attachment) {
// Check if the file exists from the attachments
$attachment->set_variables();
$file = $attachment->abs_path . DS . $attachment->filename;
if(file_exists($file)){
// Use the pdftk tool to attach the documents to this PDF
$pdftk->setInputFile(array("filename" => $file));
}
}
$pdftk->setOutputFile($save_file);
$pdftk->_renderPdf();
the $pdftk class it is calling is from: https://github.com/bensquire/php-pdtfk-toolkit
You could possibly use Ghostscript using exec() to check the file.
The non-accepted answer here may help:
How can you find a problem with a programmatically generated PDF?
I wont say this is an appropriate/best fix, but it may resolve your problem,
In: pdf_parser.php, comment out the line:
$this->error("Unable to find object ({$obj_spec[1]}, {$obj_spec[2]}) at expected location");
It should be near line 544.
You'll also likely need to replace:
if (!is_array($kids))
$this->error('Cannot find /Kids in current /Page-Dictionary');
with:
if (!is_array($kids)){
// $this->error('Cannot find /Kids in current /Page-Dictionary');
return;
}
in the fpdi_pdf_parser.php file
Hope that helps. It worked for me.
i have this message error:
Unsupported image type:imagePath was not found on this server.
I want to create pdf with jpg images taken from the iphone. Unfortunately this does not work. The image path is just seen that I can access it from my browser. When I change the way the path is erroneous.
A exemple of the code
$pdf->Image('../firstParthPath/'.$_SESSION['environment'].'/secondParthPath'.$ImageName,null,$heigth,40,50);
$ImageName are /image404-120404.jpg for exemple. I have tested variable name. It has /image404-120404.jpg
$heigth is a variable that is also handled automatically. It always has the desired content.
I tried to replace null with 0
I tried to add the option 'JPG'. Without success.
a exemple of image
http://imageshack.us/photo/my-images/72/image398120404.jpg/
It could be that PHP is not understanding the location via the relative path starting with '../'. You could try explicitly prepending the script path before it to make sure PHP is looking in the correct place:
(dirname(__FILE__) . '/../firstParthPath/'.$_SESSION['environment'].'/secondParthPath'.$ImageName,null,$heigth,40,50);
It's resolved. It was a verification error in the next picture. Now the problem's are resolved
http://babymoments.co/preview/highres%20preview/5_357/
According to the FPDF documentation here: http://www.fpdf.org/en/doc/image.htm
You are supposed to be able to use an Image from a dynamic source.. however, as per the first link, i'm getting an fopen error.
Any suggestions?
Code Snippet:
// Overlay Text & Images
$pdf->Image($conf['rbase'].'page_maker/image_hr.php?id=5&side=1&bg=cover_pink&lo=0_1&imgtxt=0|0|u5_1310329746.jpg##1|1|Elina\'s Puppies 9/2/2010|15|arial_bi.ttf|db0ddb|fedfe4&applet_type=cover',$sx,$sh,(0-$dpi), 0, 'png');
You are trying to open a local php file with get parameters - try instead to open the image file as a url. For example :
http://domain.com/image.php?id=5
Or in your case...
http://babymoments.co/preview/page_maker/image_hr.php?id=5&side=1&bg=cover_pink&lo=0_1&imgtxt=0|0|u5_1310329746.jpg##1|1|Elina's%20Puppies%209/2/2010|15|arial_bi.ttf|db0ddb|fedfe4&applet_type=cover
I wouldn't fetch the preview over HTTP but would include the required code and generate the image in the same script that generates the PDF. That way there is no problems with setups that have disabled fopen()-usage with URLs.
I was implementing a barcode for a label printer. So I was using the 'barcodegen' library and 'fpdf' library for this project, but I was having problems including dynamically the image generated with barcodegen, giving me the following error:
FPDF error: Not a PNG file: ./misc/barcodegen/mostrar-codigo-bcgcode39.php
Afeter that, I use one of the answers described here, and I solved the problem using the full URL of the image, like this:
$pdf->Image("http://localhost/caaf/misc/barcodegen/mostrar-codigo-bcgcode39.php",0,0,20,0,'PNG');
And it worked for me.