import { ChangeDetectionStrategy, Component, inject, signal, ViewEncapsulation, } from '@angular/core'; import { EpdfDocumentGate, provideEmbedPdf } from '@embedpdf/angular/runtime'; import type { OpenInput } from '@embedpdf/angular/runtime'; import { EpdfPageTemplate, EpdfStage, withStage } from '@embedpdf/angular/stage'; import { EpdfRenderLayer, withRender } from '@embedpdf/angular/render'; import { withInteraction } from '@embedpdf/angular/interaction'; import { EpdfForm, EpdfFormLayer, toFieldRef, withForm } from '@embedpdf/angular/form'; import { cloudEngine } from '@cloudpdf/engine'; const forms: OpenInput = { kind: 'grant', grant: 'shr_eBRW5E3MpolzD8G36Alp30EF' }; /** One field of each kind, with `setValue()` in the shape each one takes. */ async function fillIn(form: EpdfForm) { await form.setValue(toFieldRef('name'), { value: 'Ada Lovelace' }); // text await form.setValue(toFieldRef('updates'), { checked: true }); // checkbox await form.setValue(toFieldRef('plan'), { value: 'yearly' }); // radio group: a button's value await form.setValue(toFieldRef('framework'), { value: 'React' }); // dropdown: an option's value return form.setValue(toFieldRef('topics'), { selectedValues: ['Forms', 'Signatures'] }); // list } @Component({ selector: 'demo-root', imports: [EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfFormLayer], providers: [ provideEmbedPdf( { engine: () => cloudEngine(), initialDocuments: [{ source: forms }] }, withStage(), withRender(), withInteraction(), withForm(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './fill.css', encapsulation: ViewEncapsulation.None, template: `
@if (result()) { {{ result() }} }

Loading…

`, }) export class App { private readonly form = inject(EpdfForm); protected readonly result = signal(''); protected async fillIn() { const { status } = await fillIn(this.form); this.result.set(`Filled in: ${status}`); } protected async fillFromBackend() { // Plain values by full name, as your backend would send them. const { applied, skipped } = await this.form.importValues({ name: 'Grace Hopper', framework: 'Vue', updates: false, topics: ['Annotations'], phone: '555-0100', }); this.result.set(`${applied.length} filled, ${skipped.length} skipped`); } protected async reset() { const { fields } = await this.form.reset(); this.result.set(`${fields.length} fields reset`); } }