Viewed   1.4k times

I am trying to convert html into pdf using mpdf. Problem is that i am unable to apply css to pdf file..

Here is my code of php:


    $html = $divPrint;
    $mpdf=new mPDF();
    $stylesheet = file_get_contents('pdf.css');


What it is doing is taking html through ajax on my this php page. But the output it gives doesn't come with css which i've written for it..

Please tell me that to do now?



$html = $divPrint;

include('mpdf.php'); // including mpdf.php
$mpdf=new mPDF();
$stylesheet = file_get_contents('pdf.css'); // external css


1st assign your html in $html then include mpdf.php file.

Monday, October 10, 2022



immediately before


Without this mpdf sometimes includes the website page HTML and not just the HTML that you want in the PDF, probably because headers have already been sent elsewhere in the code. That can mess up your PDF so Adobe won't open it.

Monday, December 12, 2022

PHP is server-side, it can't do anything in the browser, only deliver content.

To add a div, you use Javascript in the page, e.g.

var el = document.getElementById('idoftarget');
el.innerHTML += '<div>new stuff</div>

... I think. I always use jQuery:

$('#idoftarget').append('<div>new stuff</div>');
Wednesday, August 10, 2022
  1. You must create the css file in this route: /module_name/static/src/css/module_name.css. Example of file:
.openerp .classname{
    margin: 12px 0px 12px 0px;
  1. Create the file /module_name/views/module_name.xml with this content:
<?xml version="1.0"?>
        <template id="assets_backend" name="module_name assets" inherit_id="web.assets_backend">
            <xpath expr="." position="inside">
                <link rel="stylesheet" href="/module_name/static/src/css/module_name.css"/>
  1. Add the xml file to your __openerp.__py
'data': [
  1. Add the class to the elements in the view
<div class="classname">                            
    <field name="field_name" class="other_class"/>
Wednesday, October 12, 2022

You cannot directly import CSS or any other static files into typescript using only the typescript compiler, but you can with the help of some build tools...

For example using webpack, you can set up the css-loader and style-loader to search your source code for require('./whatever.css') and add it to the build before safely compiling your typescript. If you also have webpack generate your HTML then your CSS will be automatically injected as a stylesheet.

Wednesday, October 5, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :