How to apply css style when using ng-print inAngular JS


Tags: html,css,angularjs

Problem :

I have created PHP page using angular JS. Now, I want to print that page as well as. I have added ngPrint in my app.js and also assign id to the main div. on page preview data are showing perfectly but without css property. I also added ngPrint.css and ngPrint.js .

my code in header section :-

<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="js/angular.min.js"></script>   
<script src="app/app.js"></script>
<!-- ng-print -->
<link rel="stylesheet" type="text/css" href="css/ngPrint.css">
<script src="js/ngPrint.js"></script>
<!--/ ng-print -->  

on app.js :-

var mainApp = angular.module("IncomeBenefit", ['ngPrint']);

on display page:-

    <div class="main" id="printSectionId" ng-app="IncomeBenefit">
    <h1 class="main_h1_calc">Calculator</h1>    
        <div class="col-main-w-12" ng-controller="displayController">
            <div class="col-main-w-5">
                <div class="form-header-main" ng-repeat="X in names">

                                    <!-- form section -->                           
                                    <div class="form-header">
                                        <div class="form-header-l">Client Age</div>     
                                        <div class="form-header-r">{{X.client_age}}</div>       
                                    </div>                              
                                    <!--/ form section -->      
                </div>
            </div>
<button class="btn btn-primary" ng-print print-element-id="printSectionId"><i class="fa fa-print"></i> Print</button>
                </div>
            </div>

I don't have any idea. How to add css property to my printable data. I have also tried inline css but can't succeeded . What can I do ?



Solution :

In your style.cssfile try adding the following and see what happends:

@media print {
  body { border: 15px solid black; }
}

You have to use @media print to apply print styles and include evertyhing inside it but please remember that css support is somewhat limited when printing.

A good tutorial to get started with


    CSS Howto..

    How can I add CSS to grandchild pages in an unordered list on Wordpress?

    How to perform arithmetic operations in CSS?

    How can I get the
    div to properly wrap my two buttons?

    How can I set different gradients as background, each time user refreshes?

    How to indent text like in a table, but without a table?

    how to replace a link name text

    How to put a picture on top of other without using Positioning, Divs or Backgrounds?

    How to disable mask on selected image in the f/ckeditor in webkit, opera browsers?

    How to draw the following shape using CSS3 [duplicate]

    Jquery datepicker only year and month how to set CSS to hide calendar when there are severals datepickers?

    How to line up items of varied length in a resizable space in CSS?

    How can i use the visibility attribute in css to make my submenu appear and reappear?

    How to remove unnecessary margin on top?

    How to achieve navigation mouseover effect like in screenshot [closed]

    How to align right-to-left the elements of css menu

    How to add hover effect to menu using jQuery

    How to stretch a background-image with css

    How will I change CSS based on classes and id using jQuery

    Pure CSS3 show/hide full height div with transition

    How to inspect precompiled minified SASS code

    Both DIV Popups Shown Instead of One

    How to remove this head css styling with javascript?

    Show a box on top of an image in an HTML page

    How to use sprite css [duplicate]

    JQuery function to show element dependent on the value of hidden HTML input element

    how to align vertically a dynamic-height div inside another fixed height div

    How to reuse styles?

    Can't figure out how to make a box with multiple images with CSS/HTML

    How to add threshhold onclick() jQuery?

    CSS how to vertically center image and text without changing style of image