How to put an image in a table created by FPDF? - php

I have following code:
$pdf->SetFont('Arial','B',12);
$pdf->Cell(60,65, $enteredText ,1,0,'C');
$pdf->Cell(60,65,$enteredText2,1,0,'C');
$pdf->Cell(60,65,$enteredText3,1,1,'C');
I would love to put an image as the background of my created Cells (of my table). For each cell, a own image.
I can't find any good information to this online. I only found how to change colour in the background from this source:
http://www.fpdf.org/en/doc/setfillcolor.htm
SetFillColor(int r [, int g, int b])
But I can't really put an image in the background with the method SetFillColor. Does anyone know how I could do this? I aprecciate your help!

Related

Full image instead of thumbnail

We have a shop page on this website.
I will explain my problem using the very first image in the top left as example, although it applies to all of them.
If you hover over the first image (Gentes Deluxified English) you see an incomplete picture like this:
src= ".../Gentes-board-DLX-20180123-200x267.jpg"
This image actually cuts of parts of the images to the left and right. The full image is like this:
src= " .../Gentes-board-DLX-20180123.jpg"
So we want to change the thumbnail image to the full image, or keep the original ratio of the image. This needs to work for all images and the ones added in the future.
Is this fixable with css?
I already spent a lot of time looking at the source code of woocommerce to find the file that creates the page that uses the thumbnail images. I can't find that file. Where should I look for the source code files? And what should I change in these source files?
I looked at the source code of Woo commerce and found the parameter for cropping thumbnails for you.
https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-regenerate-images.php
Add this
$crop = false;
after line 318:
private static function get_image( $fullsizepath, $thumbnail_width, $thumbnail_height, $crop ) {

Background Color inside a cell is not changing in fpdf

Im using fpdf to generate a pdf file for my reports and Im new to this.
I want to change the fill color inside a cell but whenever I reloaded the page, nothing
hapeens, It still the same white fill color. Here is my code :
<?php
require("fpdf/fpdf.php");
$pdf = new FPDF('P','pt','Letter');
$pdf->SetFillColor(230,230,230);
$pdf->SetTitle("Title Here");
$pdf -> AddPage();
$pdf -> SetFont('Arial','',12);
?>
What is wrong with my code? I followed the proper way of setting the fill color but nothing happens? Can anyone help me fix it? Thanks
Tyr something like:
$pdf->setFillColor(230,230,230);
$pdf->Cell(0,10,$text,0,1,'L',1); //your cell
Defines the color used for all filling operations (filled rectangles and cell backgrounds). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.
Take a look to the FPDF manual
mpdf->SetFillColor('RED');
Just set the seventh parameter equal to TRUE
$mpdf->WriteCell(38, 10, 'HELLO', 1, 0, 'C', TRUE);

HTML2PDF - The content of a TD tag does not fit on only one page

Php produces pdf without issue when does not span, nested tables are not in use, and
HTML2PDF::$_subobj->pdf->getPage();
doesn't seem to address the bug/issue. Anyone run into this ERROR n°7?
Add the following in your function to solve the error
html2pdf->setTestTdInOnePage(false);
If you have a long picture (in table td) , example 1200px you can get this error.
I fixed my picture to 600px and problem solved.
Example: My photo is 3000x2000 (width:height)
I resized photo to 600x400.

Border arround image in report created in PHP with FPDF

i have added an image in a pdf generated in PHP with FPDF, the problem occurs when i insert an image the image gets inserted at the right location but with an ugly border around it whereas in the actual image there is no border. Another important thing that need to be mentioned here is that i have re-sized it with the FPDF Image() method parameters my code is:
$this->Image('report_footer.jpg',10,280,190,8);
The border appears only on the top and left side of the image as shown below:
Any idea to get rid of the border arround my image?
You can try providing the image type alongwith other parameters. You can also try editing the image to the required dimensions and then give it a try. If that doesn't work you can try using TCPDF with html write and image with border 0 attribute.

Print stylish text on image in php

Is it possible to print html div tag with style on image in PHP?. if not, then what is the alternative way?
Some hosts have ImageMagick for PHP. To add text to your image, take a look at the syntax of the commands here. The example given on that page should help some - it's pretty easy to get text on an image.
The benefits of using ImageMagick over a fixed image is that you can vary the content of the text, which is what you might want (you didn't mention needing a static text; for this, I'd use an image with a transparent background). For more comprehensive font commands, take a look here.
To put a transparent image on top of your base image, take a look at this very nicely designed site.
I'll also give the code presented on that site here:
$photo = imagecreatefromjpeg("original.jpg");
$watermark = imagecreatefrompng("watermark.png");
// This is the key. Without ImageAlphaBlending on, the PNG won't render correctly.
imagealphablending($photo, true);
// Copy the watermark onto the master, $offset px from the bottom right corner.
$offset = 10;
imagecopy($photo, $watermark, imagesx($photo) - imagesx($watermark) - $offset, imagesy($photo) - imagesy($watermark) - $offset, 0, 0, imagesx($watermark), imagesy($watermark));
// Output to the browser
header("Content-Type: image/jpeg");
imagejpeg($photo);
To output the image to a file, please Google that and replace the last two lines of the example given above.
For ImageMagick stuff, take a look here
I hope this helps :-)
James
You can set the image as the background graphic of any div using CSS. Then the text within that div will appear on top of the image.
(CSS)
.mydiv {
background:url(/path/to/image.gif);
width:100px; /* set to width of the image */
height:100px; /* set to height of the image */
}
(HTML)
<div class='mydiv'>Some text here</div>
There is no easy way to print text on images using html/css on server side, because php can't parse html, so you'd better find another solution like php GD.

Categories