This is an archived forum post. The information may be outdated. Contact us if you have any questions.

Image Size

spyke01 wrote on 2010-10-18:
What is the best way to force an image to be the correct size, it seems when I have an image it gets enlarged, I tried the width and height attributes on the img tag and also within the style attributes but neither seem to work.
support wrote on 2010-10-18:
Set the width and height attributes on the img tag to 75% of the image dimensions.

Please, find the explanation in this thread:
https://pdfcrowd.com/forum/archive/read/?3,115,115#msg-115
spyke01 wrote on 2010-10-18:
That did it thanks!
santi900 wrote on 2010-10-19:
Hi again,

i have readed all threads about it, but i can not try !!. I am generating a html with dynamics graphics. The graphs for this are gif of 1 pixel width and with a value as parameter i make this size wider.

The container column width is fixed and the pdf respects it, but the img, I am aplying the factor you explain in this thread and they always has the same size and oversize in the pdf.

<tr ><td width="50" align="right" class="pregunta">1144</td><td width="200" class="pregunta">	
	<img src="./img/verde.gif"  height="10" width="173"></td></tr>
<tr ><td width="50" align="right" class="pregunta">1153</td><td width="200" class="pregunta">	
	<img src="./img/verde.gif"  height="10" width="176"></td></tr>


Any ideas? Thanks, best regards
support wrote on 2010-10-19:
Please, could you either send your html code to support@pdfcrowd.com, or post an URL if it is publicly available?
santi900 wrote on 2010-10-19:
It is a intranet that requires auth, but if can show you all the necesary.

A php page calls a function that draw a graphic. It passes the param nota (it means score):

echo "<td width=\"200\" class=\"arean\">";
				grafico($nota);
				echo "</td>";



The function grafico is this. Depending on valor it draws a red, yellow or red img and the width:

function grafico ($valor) {

	if ($valor<=2) {
		$color="rojo.gif";
	} elseif ($valor>3) {
		$color="verde.gif";
	} else  {
		$color="amarillo.gif";
	}
	
	if ($valor!="")  {
		$ancho= $valor;
		$ancho=number_format($ancho,0);
	?>
	
	<img alt="grf" src="./img/<?php echo $color;?>"  height="10" width="<?php echo $ancho;?>">
	<?php 
	}
}


In this link you can see an image sample:

http://www.sulpank.com/scores.jpg

Note that the origin images have a width of 1 px and via code i modify this width.

Well, it builds the pages, but at same time i save the result as html

At the begin of script:

ob_start();



At the end of script

$HtmlCode= ob_get_contents();
if (isset($_SESSION['htmlpdf'])) {
	$_SESSION['htmlpdf']=($HtmlCode);
}
ob_end_flush();



It caches the result in a session variable.

I make the print via link a php script:

<a class="param" href="pdfprint.php">PDF</a>


And the pdfrpint.php is this:

<?php
session_start();
require 'pdfcrowd.php';
if (isset($_SESSION['htmlpdf'])) {
	$html=$_SESSION['htmlpdf'];
	//i save the result of the buffered document in a file
	file_put_contents("pdf.html", $html);
	$client = new Pdfcrowd("my", "mine");
	$client->setPageWidth('8.25in');
	$client->setPageHeight('11.7in');
	$client->enableHyperlinks(FALSE);
	//$client->enableImages(TRUE);
	//$client->usePrintMedia();
	try
	{
		header('Content-type: application/pdf');
        	header('Content-Disposition: attachment; filename="impresion.pdf"');
		echo $client->convertURI('http://mysite.com/pdf.html');
	}
	catch(PdfcrowdException $e)
	{
	    echo $e->getMessage();
	}
}
?>


Thats all, it works fine, i have not problem about authentiifcate to a external site (yours)... but the graphics overflows, as showed in this link and does not respect width:

http://www.sulpank.com/score2.png

I hope you have all necessary information.

Thank you very much.

Santi
support wrote on 2010-10-19:
Thanks for the info. We tried to replicate your issue, but with no luck.

It would be best if you could save that page in a browser and send us the generated html (plus that one-pixel image) so we can look at it.
support wrote on 2010-10-21:
It should be fixed now. Can you check please?
santi900 wrote on 2010-10-21:
It works perfectly. Thank you. regards