import { ChangeDetectionStrategy, Component, computed, 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 { EpdfShell, withShell } from '@embedpdf/angular/shell'; import type { ShellSnapshot } from '@embedpdf/angular/shell'; import { localEngine } from '@embedpdf/engine'; const welcome = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/welcome.pdf'); return { kind: 'bytes', id: 'welcome', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // The browser may refuse storage, in a private window: then nothing is remembered. const loadLayout = (): ShellSnapshot | null => { try { return JSON.parse(localStorage.getItem('panels') ?? 'null') as ShellSnapshot | null; } catch { return null; } }; const saveLayout = (snapshot: ShellSnapshot) => { try { localStorage.setItem('panels', JSON.stringify(snapshot)); } catch { // Not remembered this time. } }; const TIPS = [ 'Ctrl or ⌘ and scroll to zoom', 'Pinch to zoom on a touch screen', 'Drag between pages to scroll', ]; @Component({ selector: 'demo-workspace', imports: [EpdfStage, EpdfPageTemplate, EpdfRenderLayer], changeDetection: ChangeDetectionStrategy.OnPush, template: `

Open: {{ open() || 'no panels' }}

@if (tips.isOpen()) { } @if (notes.isOpen()) { }
`, }) export class Workspace { private readonly shell = inject(EpdfShell); protected readonly tips = this.shell.surface('tips'); protected readonly notes = this.shell.surface('notes'); protected readonly tipList = TIPS; protected readonly saved = signal(loadLayout()); protected readonly open = computed(() => this.shell .openSurfaces() .map((surface) => surface.id) .join(', '), ); constructor() { // The layout saved last time, or the tips the first time. const layout = loadLayout(); if (layout) this.shell.applySnapshot(layout); else this.shell.open('tips', { exclusive: 'left' }); } protected save() { const layout = this.shell.getSnapshot(); saveLayout(layout); this.saved.set(layout); } protected restore() { const saved = this.saved(); if (saved) this.shell.applySnapshot(saved); } } @Component({ selector: 'demo-root', imports: [EpdfDocumentGate, Workspace], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: welcome }] }, withStage(), withRender(), withShell(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './remember.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}