Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use external css in tcpdf pdf generation

Tags:

css

php

tcpdf

I am trying to create a pdf of a web page with tcpdf. But it's not working. The page is a php with external css and javascript files.

Can anyone help me with this.

Thanks,

like image 244
user1559230 Avatar asked Sep 25 '13 10:09

user1559230


People also ask

How do you add external CSS while generating a PDF?

response. setContentType("application/force-download"); response. setHeader("Content-Disposition", "attachment;filename=reports. pdf"); Document document = new Document(); document.

How do I insert an external CSS?

External CSS With an external style sheet, you can change the look of an entire website by changing just one file! Each HTML page must include a reference to the external style sheet file inside the <link> element, inside the head section.


1 Answers

To include external CSS file, you can do as below before you add your HTML content

$html .= '<style>'.file_get_contents(_BASE_PATH.'stylesheet.css').'</style>';

By this, while you pass $html to generate pdf it will include those styles.

As far I am aware, there is no need for including Javascript into a PDF. The purpose of a PDF is to display a non-interactive static content, which can be achieved by HTML and CSS

like image 90
Saravanan Avatar answered Oct 18 '22 19:10

Saravanan