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

How to include images and external CSS?

neo2504 wrote on 2014-07-25:
Hi,
I just tried to generate a pdf using API for php.

I'm using this code to generate the pdf:
require 'pdfcrowd.php';
try
                    {   
                        // create an API client instance
                        $client = new Pdfcrowd("neo2504", "############################");
                        
                       // $docoded contains the html code
                        $pdf = $client->convertHtml($decoded);
                                                    
                        // set HTTP response headers
                        header("Content-Type: application/pdf");
                        header("Cache-Control: max-age=0");
                        header("Accept-Ranges: none");
                        header("Content-Disposition: attachment; filename=\"options.pdf\"");
                        // send the generated PDF 
                        echo $pdf;
                    }
                catch(PdfcrowdException $why)
                    {
                        echo "Pdfcrowd Error: " . $why;
                    }


In the html code I have included my external css file like this:
<head><link rel="stylesheet" type="text/css" href="http://vladradu.altervista.org/style.css" media="print"></head>



The Problem is that my html looks like this:

While the generated PDF looks like this:
support wrote on 2014-07-27:
Hello,

Your CSS is not applied because Pdfcrowd uses the screen @media type but your CSS is specified with media="print". Either delete the media attribute or call the following API function before convertHtml():
$client->usePrintMedia(True)
eweSOFT wrote on 2014-11-15:
Hi all, my image is not displayed on the pdf. every other thing works fine kindly assist.

<img src="images/sign.jpg" width="151" height="85" />
support wrote on 2014-11-17:
Hello,

If you use convertHtml() or convertFile() you need to do one of the following:

1/ You can zip the images together with the HTML document and send the .zip file to the API using the convertFile() function.

2/ If the images are accessible on the public Internet, you can refer to them using an absolute URL. An example:
<img src="http://example.com/images/sign.jpg" />

3/ An alternative to the previous option is to use a relative URL in combination with the <base> element (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base)
venky_kvr wrote on 2015-05-26:
please explain indetails. i can't understand.

How to insert images.