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 { cloudEngine } from '@cloudpdf/engine';
const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' };
// 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) {
}
`,
})
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: () => cloudEngine(), initialDocuments: [{ source: welcome }] },
withStage(),
withRender(),
withPageEdit(),
),
],
changeDetection: ChangeDetectionStrategy.OnPush,
styleUrl: './rotate.css',
encapsulation: ViewEncapsulation.None,
template: `
Loading…
`,
})
export class App {}