import { ChangeDetectionStrategy, Component, computed, inject, input, ViewEncapsulation, } from '@angular/core'; import { EpdfDocument, 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 { EpdfPageEdit, withPageEdit } from '@embedpdf/angular/page-edit'; 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()) }; }; // Rotates the page you're on, in the file: the turn is kept when the document is downloaded. @Component({ selector: 'demo-rotate-toolbar', changeDetection: ChangeDetectionStrategy.OnPush, template: ` @if (page(); as page) {
Page {{ stage().currentPageIndex() + 1 }} · {{ page.rotation }}°
} `, }) export class RotateToolbar { readonly stage = input.required(); protected readonly pageEdit = inject(EpdfPageEdit); private readonly document = inject(EpdfDocument); protected readonly page = computed( () => this.document.pages()[this.stage().currentPageIndex()] ?? null, ); constructor() { // The first page starts a quarter turn clockwise. setRotation() sets the same rotation // however often it runs; rotateBy() would turn it again. void this.pageEdit.setRotation([0], 90); } protected everyPageUpright() { void this.pageEdit.setRotation( this.document.pages().map((each) => each.ref), 0, ); } } @Component({ selector: 'demo-root', imports: [EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, RotateToolbar], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: welcome }] }, withStage(), withRender(), withPageEdit(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './rotate.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}