Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import {PDFDocument, PDFForm} from "pdf-lib";
- import {HttpClient, HttpHeaders} from "@angular/common/http";
- @Component({
- selector: 'app-pdf-form',
- templateUrl: './pdf-form.component.html',
- styleUrls: ['./pdf-form.component.css']
- })
- export class PdfFormComponent implements OnInit {
- formFields = [];
- private form: PDFForm;
- constructor(
- private http: HttpClient
- ) { }
- ngOnInit(): void {
- this.loadForm();
- }
- async loadForm(){
- // Fetch the PDF with form fields
- const formUrl = '../../assets/modello_autodichiarazione_editabile_ottobre_2020.pdf';
- const formPdfBytes = await this.http.get(formUrl, {responseType: "arraybuffer"}).toPromise();
- // const formPdfBytes = await fetch(formUrl).then(res => res.arrayBuffer());
- // Load a PDF with form fields
- const pdfDoc = await PDFDocument.load(formPdfBytes);
- // Get the form containing all the fields
- this.form = pdfDoc.getForm();
- const fields = this.form.getFields()
- fields.forEach(field => {
- const type = field.constructor.name
- const name = field.getName()
- this.formFields.push({type: type, name: name});
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement