import { NgTemplateOutlet } from '@angular/common'; import { ChangeDetectionStrategy, Component, inject, 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 { EpdfFieldControlTemplate, EpdfForm, EpdfFormLayer, withForm, } from '@embedpdf/angular/form'; import type { EpdfFieldControlTemplateContext, FormWidgetItem } from '@embedpdf/angular/form'; import { localEngine } from '@embedpdf/engine'; // [!doc-source forms] const forms = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/forms.pdf'); return { kind: 'bytes', id: 'forms', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] @Component({ selector: 'demo-root', imports: [ NgTemplateOutlet, EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfFormLayer, EpdfFieldControlTemplate, ], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: forms }] }, withStage(), withRender(), withInteraction(), withForm(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './clear-button.css', encapsulation: ViewEncapsulation.None, template: `
@if (widget.control === 'text' && !widget.disabled && widget.value !== '') { }

Loading…

`, }) export class App { private readonly form = inject(EpdfForm); protected readonly isTextBox = (widget: FormWidgetItem) => widget.control === 'text' && !widget.multiline; /** Empty the box, then put the cursor back in it, ready for the new value. */ protected clear(widget: FormWidgetItem, setValue: EpdfFieldControlTemplateContext['setValue']) { void setValue({ value: '' }).then(() => this.form.focus(widget.fieldRef)); } protected fillIn() { void this.form.importValues({ name: 'Ada Lovelace', email: 'ada@example.com', company: 'Lanternfield', }); } }