Added jsPDF library and a simple service to create browser-side pdfs

This commit is contained in:
Nikolaos Laskaris 2017-11-29 12:20:17 +02:00
parent f558910905
commit 5626204bbc
5 changed files with 70 additions and 3 deletions

View File

@ -324,6 +324,11 @@
} }
} }
}, },
"adler32cs": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/adler32cs/-/adler32cs-0.0.1.tgz",
"integrity": "sha1-ninNgIdWTXBVIJztEgaljSLneOs="
},
"adm-zip": { "adm-zip": {
"version": "0.4.7", "version": "0.4.7",
"resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.4.7.tgz", "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.4.7.tgz",
@ -1545,6 +1550,11 @@
} }
} }
}, },
"cf-blob.js": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/cf-blob.js/-/cf-blob.js-0.0.1.tgz",
"integrity": "sha1-9at+EueYyvCMz4KMaaug8GPYP5k="
},
"chainsaw": { "chainsaw": {
"version": "0.1.0", "version": "0.1.0",
"resolved": "https://registry.npmjs.org/chainsaw/-/chainsaw-0.1.0.tgz", "resolved": "https://registry.npmjs.org/chainsaw/-/chainsaw-0.1.0.tgz",
@ -3234,6 +3244,11 @@
"loader-utils": "1.1.0" "loader-utils": "1.1.0"
} }
}, },
"file-saver": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/file-saver/-/file-saver-1.3.3.tgz",
"integrity": "sha1-zdTETTqiZOrC9o7BZbx5HDSvEjI="
},
"filename-regex": { "filename-regex": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz", "resolved": "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz",
@ -4813,6 +4828,16 @@
"integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=", "integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=",
"dev": true "dev": true
}, },
"jspdf": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/jspdf/-/jspdf-1.3.5.tgz",
"integrity": "sha512-g5xVq2XzDNcKyP67j1QPXpDjHeUz56vHD6Kg/bKR7SCX2/p1BusU4txV9hvY2EkmX1JqfQ9d96890/4u85kWaw==",
"requires": {
"adler32cs": "0.0.1",
"cf-blob.js": "0.0.1",
"file-saver": "1.3.3"
}
},
"jsprim": { "jsprim": {
"version": "1.4.1", "version": "1.4.1",
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",

View File

@ -33,6 +33,7 @@
"core-js": "^2.4.1", "core-js": "^2.4.1",
"flat": "^4.0.0", "flat": "^4.0.0",
"jquery": "^3.2.1", "jquery": "^3.2.1",
"jspdf": "^1.3.5",
"moment": "^2.19.1", "moment": "^2.19.1",
"ng-sidebar": "^6.0.4", "ng-sidebar": "^6.0.4",
"ng2-datepicker": "^2.1.3", "ng2-datepicker": "^2.1.3",

View File

@ -41,7 +41,7 @@ import { ConfirmationComponent } from './widgets/confirmation/confirmation.compo
import { PaginationService } from './services/pagination.service'; import { PaginationService } from './services/pagination.service';
import { EestoreService } from './services/eestore.service'; import { EestoreService } from './services/eestore.service';
import { GlobalInterceptor } from './services/interceptor'; import { GlobalInterceptor } from './services/interceptor';
import { PDFService } from './services/transformers/pdf.service';
import { TabModule } from './tabs/tab.module'; import { TabModule } from './tabs/tab.module';
import { AngularDraggableModule } from 'angular2-draggable'; import { AngularDraggableModule } from 'angular2-draggable';
@ -139,7 +139,7 @@ import { ProjectDetailedComponent } from './viewers/project-detailed/project-det
useClass: GlobalInterceptor, useClass: GlobalInterceptor,
multi: true, multi: true,
}, },
ServerService, VisibilityRulesService, GlobalVariables, AuthGuard, PaginationService, TokenService, LocalStorageService, RestBase, EestoreService, NativeLoginService ServerService, VisibilityRulesService, GlobalVariables, AuthGuard, PaginationService, TokenService, LocalStorageService, RestBase, EestoreService, NativeLoginService, PDFService
], ],
bootstrap: [AppComponent] bootstrap: [AppComponent]
}) })

View File

@ -23,6 +23,8 @@ import { AngularDraggableModule } from 'angular2-draggable';
import {MenuItem} from 'primeng/primeng'; import {MenuItem} from 'primeng/primeng';
import {PDFService} from '../services/transformers/pdf.service';
import './../../assets/xml2json.min.js'; import './../../assets/xml2json.min.js';
declare var X2JS: any; declare var X2JS: any;
@ -71,7 +73,7 @@ export class DynamicFormComponent implements OnInit {
expandedToc : boolean = true; expandedToc : boolean = true;
constructor(private qcs: FieldControlService, private serverService: ServerService, private router: Router, constructor(private qcs: FieldControlService, private serverService: ServerService, private router: Router, private pdfService : PDFService,
private _location: Location, private route: ActivatedRoute, private pagerService: PaginationService, private tokenService: TokenService,private visibilityRulesService:VisibilityRulesService) { private _location: Location, private route: ActivatedRoute, private pagerService: PaginationService, private tokenService: TokenService,private visibilityRulesService:VisibilityRulesService) {
this.form = this.qcs.toFormGroup(new Array(), new Array()); this.form = this.qcs.toFormGroup(new Array(), new Array());
this.xml2jsonOBJ = new X2JS(); this.xml2jsonOBJ = new X2JS();
@ -194,4 +196,11 @@ export class DynamicFormComponent implements OnInit {
this.expandedToc = !this.expandedToc; this.expandedToc = !this.expandedToc;
} }
*/ */
createPDF(elementID : string, pdffilename : string){
debugger;
this.pdfService.toPDF(elementID, pdffilename);
}
} }

View File

@ -0,0 +1,32 @@
import {Injectable} from '@angular/core';
declare var $ :any;
import * as jsPDF from '../../../../node_modules/jspdf/dist/jspdf.min';
@Injectable()
export class PDFService {
constructor() {
}
toPDF(elementID : string, filename : string){
var pdf = new jsPDF();
pdf.fromHTML($('#'+elementID).html(), 15, 15, {
'width': 270
//,'elementHandlers': specialElementHandlers
});
pdf.save(filename);
}
}