0

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 1

1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Will check and let you know sir. Thanks for your reply
perfectly working sir. Thanks a lot. Now one more doubts here, how to generate multiple pages in jspdf
Happy to help you. I'll answer your question shortly. BTW I'm ma'am not sir.
Of no..Thank you so much mam...Eagerly waiting for your response. Happy coding..!!
for add page just use .addPage() method from jsPDF libreary

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.