Avinash Sharma
Avinash Sharma

Reputation: 45

jsPDF not printing as it is

my HTML page
my PDF

I want to print the details on HTML page exactly on PDF.
I am using jsPDF to print the details onto the PDF.
Here is my code:

var pdf = new jsPDF('p', 'pt', 'a4');
var source = $('#mymy')[0];
var specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#bypassme': function(element, renderer){
    // true = "handled elsewhere, bypass text extraction"
    return true
  }
}

var margins = {
   top: 80,
   bottom: 60,
   left: 40,
   width: 522
};


pdf.fromHTML(source, margins.left, margins.top, {
    'width': margins.width // max width of content on PDF
    , 'elementHandlers': specialElementHandlers
},
function (dispose) {
  // dispose: object with X, Y of the last line add to the PDF 
  //          this allow the insertion of new lines after html
  pdf.save('Test.pdf');
},
margins
)

Html code:

 <div class="form-group" id="mymy">
                <ul ng-repeat="sec in abc" class="media-list tab-pane fade in active" style="border-style: solid;">

                    <ul ng-repeat="k in sec.usertype" ng-if="secs(k._id)">
                        <div class="panel panel-primary">
                        <div class="panel-heading">{{k.sec_name}}</div> 
                            <div class="panel-body">

                            <ul ng-repeat="l in k.keywords">                           

                            <div class="row" name="options" id="{{k._id}}" ng-if="check(l._id)">
                           <div class="col-sm-5"> <img src="/client/app/images/t.png" width="20" height="15"><b>{{l.keyword}}</b></div>
                             <div class="col-sm-5"> <p>{{l.description}}</p></div>                                                              
                            </div>                            

                        </ul>
                                </div>
                        </div>
                    </ul>                       

                </ul>       
                </div>

I want exact page to be printed on PDF.
I am not familiar with jsPDF.

Upvotes: 1

Views: 1912

Answers (1)

user9239742
user9239742

Reputation:

I know its an old one but ng-if is breaking up the Dom therefore you'll have to build the pdf in your script instead of using pdf.fromHtml e.g. the dom elements.

Upvotes: 1

Related Questions