I generate HTML content to export PDF file using JsPDF library. Now, i need how to pass exported PDF file to server using angular 6. Thanks in advance
1 Answer
Here is my way to do it.
//HTML code
<input type="file" name="File Upload" id="txtFileUpload" accept=".csv"
(change)="changeListener($event)" />
//Component.ts
You have to import StaffService here:
changeListener($event: any) {
this.data = $event.target.files;
this.postFile(this.data);
}
postFile(inputValue: any): void {
this.file = inputValue[0];
this.staffService.uploadCSV(this.file).subscribe(response => {
//Do your next redirection or operation here
}, error =>{});
}
//StaffService.ts
public uploadCSV(file): Observable<any> {
const formdata = new FormData();
formdata.append('files', file);
return this.http.post(environment.apiUrlIp + this.urls.uploadCSVUrl, formdata, {
reportProgress: true,
responseType: 'json'
});
}
Let me know if you find any issue to integrate this code. Happy to help.
5 Comments
saravanam cs
Will check and let you know sir. Thanks for your reply
saravanam cs
perfectly working sir. Thanks a lot. Now one more doubts here, how to generate multiple pages in jspdf
Pinki Dhakad
Happy to help you. I'll answer your question shortly. BTW I'm ma'am not sir.
saravanam cs
Of no..Thank you so much mam...Eagerly waiting for your response. Happy coding..!!
Marcos
for add page just use
.addPage() method from jsPDF libreary