jdaily / angular-save2pdf

jsPDF wrapper for AngularJS to save HTML as a PDF
MIT License
2 stars 1 forks source link

AngularJS Sample #1

Open carloslema opened 8 years ago

carloslema commented 8 years ago

Thank you so much for the jsPDF wrapper.

Do you have a quick plunker to show it working in an AngularJS project?

This is what I tried to do... but no luck.

// index.html angular.js plus other libraries here

App.js angular.module('ready2tri', ['save2pdf']

And added it to my controller .controller('SettingsCtrl', ['$scope', 'save2pdf', function($scope, save2pdf){ ...

After that I got stuck, could not find a way to convert a page to a PDF. My ultimate goal is to email a page as a PDF attachment using the cordova-plugin-email-composer.

Thanks in advance for all your help.

best \ carlos

DevQueen commented 8 years ago

Do you EVER get a response? I'm having the same problem. There is no explanation on how to use it.

joshuapowell commented 8 years ago

After installing the module, I followed these steps to get a PDF saving out of my page.

Step 1: Include the save2pdf directive into your application

angular.module('myApp', [
    `save2pdf`
]);

Step 2: Add the save2pdf directive to the HTML block you wish to convert:

<div save2pdf>
    <h1>Convert me</h1>
    <p>All the stuff you want to convert ...</p>
</div>

Step 3: Add a button or other click event to your page that $scope.$emit's the directive:

Add this to your controller:

$scope.savePdf = function() {
    $scope.$emit('saveToPdf');
};

And this to your HTML:

<a data-ng-click="savePdf()">Save to PDF</a>
DevQueen commented 8 years ago

Unfortunately, this still doesn't work for me.

My app code:

var app = angular.module('myModule', ['ui.bootstrap', 'checklist-model', 'ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.pagination', 'ui.grid.selection', 'ui.grid.exporter', 'ui.grid.autoResize', 'ui.router', 'cgBusy', 'ui.mask','save2pdf']);

my html:
<div save2pdf>
dkfjjdf;jadf;
</div>
<div><button type="button" class="btn btn-primary" ng-click="savePdf()">Save to PDF</button></div>

my Angular controller:

$scope.savePdf = function () {
    $scope.$emit('saveToPdf');
};

Nothing happens.