-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
111 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Inject, Injectable, PLATFORM_ID } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { DOCUMENT, isPlatformBrowser } from '@angular/common'; | ||
import { ConfigInitService } from '@init/config-init.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class PdfService { | ||
baseUrl: string; | ||
|
||
constructor( | ||
private http: HttpClient, | ||
@Inject(DOCUMENT) private document: Document, | ||
private configService: ConfigInitService, | ||
@Inject(PLATFORM_ID) private platformId: any | ||
) { | ||
this.baseUrl = configService.getConfig()['BACKEND_URL'] + '/api/pdf'; | ||
} | ||
|
||
public split(file: File): void { | ||
if (isPlatformBrowser(this.platformId)) { | ||
let formData = new FormData(); | ||
formData.append('pdf', file); | ||
this.http | ||
.post(`${this.baseUrl}/split`, formData, { | ||
observe: 'response', | ||
responseType: 'blob' as 'json', | ||
}) | ||
.subscribe((response: any) => { | ||
let body = response.body; | ||
let dataType = body.type; | ||
let headers = response.headers; | ||
let filename = headers.get('content-disposition').split(';')[1].split('=')[1].replace(/"/g, ''); | ||
let binaryData = []; | ||
binaryData.push(body); | ||
let downloadLink = this.document.createElement('a'); | ||
downloadLink.href = URL.createObjectURL(new Blob(binaryData, { type: dataType })); | ||
downloadLink.setAttribute('download', filename); | ||
this.document.body.appendChild(downloadLink); | ||
downloadLink.click(); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/app/features/administrative-document/split-pdf/split-pdf.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<ng-container> | ||
<div class="modal-header" *ngIf="activeModal"> | ||
<span class="modal-title text-break">Split PDF</span> | ||
<button type="button" class="btn-close" aria-label="Close" (click)="activeModal?.dismiss('Cross click')"></button> | ||
</div> | ||
<div class="modal-body"> | ||
<div class="input-group mb-2 "> | ||
<input type="file" class="form-control" id="inputGroupFile02" (change)="loadFile($event)" accept=".pdf"/> | ||
<div class="input-group-append"> | ||
<button class="input-group-text ms-1" id="" (click)="split()" [disabled]="!file"> | ||
<fa-icon icon="arrows-split-up-and-left"></fa-icon> | ||
Split | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</ng-container> | ||
|
Empty file.
23 changes: 23 additions & 0 deletions
23
src/app/features/administrative-document/split-pdf/split-pdf.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Component, OnInit, Optional } from '@angular/core'; | ||
import { PdfService } from '@core/service/pdf.service'; | ||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
@Component({ | ||
selector: 'app-split-pdf', | ||
templateUrl: './split-pdf.component.html', | ||
styleUrls: ['./split-pdf.component.scss'], | ||
}) | ||
export class SplitPdfComponent implements OnInit { | ||
file: File; | ||
|
||
constructor(@Optional() public activeModal: NgbActiveModal, private pdfService: PdfService) {} | ||
ngOnInit(): void {} | ||
|
||
loadFile($event) { | ||
this.file = $event.target.files[0]; | ||
} | ||
|
||
split(){ | ||
this.pdfService.split(this.file); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters