node-html-pdf icon indicating copy to clipboard operation
node-html-pdf copied to clipboard

Bootstrap with Grid System is not working with node-html-pdf.

Open sanjuleadcap opened this issue 9 years ago • 8 comments

The bootstrap is working fine but the grid system isn't. I have checked the HTML file on the browser, it shows fine, but the generated pdf is not showing the divs in columns.

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="https://bootswatch.com/sandstone/bootstrap.min.css">
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-6 col-md-4">.col-6 .col-md-4</div>
            <div class="col-6 col-md-4">.col-6 .col-md-4</div>
            <div class="col-6 col-md-4">.col-6 .col-md-4</div>
        </div>
    </div>
</body>
</html>

sanjuleadcap avatar May 07 '17 11:05 sanjuleadcap

Having similar behavior. Any word on a fix/workaround?

JakenHerman avatar May 22 '17 17:05 JakenHerman

@sanjumathew use .col-xs-n instead of .col-md or others. This fixed it for me.

JakenHerman avatar May 22 '17 22:05 JakenHerman

Upgrading the boostrap fixes the issue - https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css

Sunil6591 avatar Aug 14 '17 17:08 Sunil6591

Similar issue... using Bootstrap 4 if I have 2 columns each using col-xs-6 then the columns stack, but when I switch to using col-6 the columns are side by side.

This is fine for 2 simple columns, but doesn't really give me the ability to showcase the responsiveness at various breakpoints.

Looks like the PDF generates the XS version of the page :-\ ... can't figure out how to tell PhantomJS I want the HTML rendered at 1200px (or whatever). (To be fair, I've never used PhantonJS & I've only been looking at this for about an hour. Looking into seeing if I can set it using arguments).

Setting the options like this (see below) doesn't give me the proper CSS breakpoints.

var options = {
  width: '900px', // 100% didn't work either
  height : '2000px',
  zoomFactor : .5 // tested with and without
};

jiggy1com avatar Sep 07 '17 05:09 jiggy1com

You can fixit replacing every col-md-6 to col-xs-6. That's it!

Thanks to Alex Johnson -> https://stackoverflow.com/questions/34182550/phantomjs-external-css-is-ignored-in-rendered-pdf

pekpon avatar Dec 16 '17 10:12 pekpon

.col-xs-n didn't work out for me. The hint "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" from @Sunil6591 helped me out. Downgrading bootstrap to 3.3.7 display my rows and columns at least correctly in the pdf-file.

Best regards and an awesome time for you guys Denis

rekDen avatar Jul 30 '18 13:07 rekDen

.col-xs-n didn't work out for me.

Bootstrap 4 uses .col-n instead of .col-xs-n

farmbotgianpaolo avatar Nov 16 '18 04:11 farmbotgianpaolo

To solve the problem, downgrade Bootstrap-4 to Bootstrap-3 and use .col-xs-n ( n = 4,6,12,etc ) . So, doing this will provide proper functionality while using grid system. But another problem that might be there is "no-color problem", i.e. even after specifying the colors and various styles, the pdf wont respond to those styles. In order to tackle the above mentioned problem, save bootstrap.css or bootstrap.min.css locally and remove all the @ media print classes. These classes have rules that prevent you to display styles. Now use the edited bootstrap.

himangshushekharjha avatar Jul 26 '20 08:07 himangshushekharjha