UNPKG

@progress/kendo-angular-scheduler

Version:

Kendo UI Scheduler Angular - Outlook or Google-style angular scheduler calendar. Full-featured and customizable embedded scheduling from the creator developers trust for professional UI components.

242 lines (241 loc) 8.6 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Component, NgZone, Input } from '@angular/core'; import { PDFService } from './pdf.service'; import { drawDOM, exportPDF } from '@progress/kendo-drawing'; import { saveAs } from '@progress/kendo-file-saver'; import * as i0 from "@angular/core"; import * as i1 from "./pdf.service"; const createElement = (tagName, className) => { const element = document.createElement(tagName); if (className) { element.className = className; } return element; }; const createDiv = (className) => createElement('div', className); /** * Configures the settings for exporting the Scheduler to PDF * ([see example](slug:pdfexport_scheduler)). * * @example * ```html * <kendo-scheduler > * <kendo-scheduler-pdf fileName="Scheduler.pdf"> </kendo-scheduler-pdf> * </kendo-scheduler> * ``` */ export class PDFComponent { pdfService; ngZone; /** * The author (metadata) of the PDF document. */ author; /** * A flag that indicates whether to produce actual hyperlinks in the exported PDF file. * It is also possible to set a CSS selector. All matching links will be ignored. */ avoidLinks; /** * Sets the creator of the PDF document. * * @default 'Kendo UI PDF Generator' */ creator = 'Kendo UI PDF Generator'; /** * Sets the date when the PDF document is created. * * @default 'new Date()' */ date; /** * Sets the forced resolution of the images in the exported PDF document. * By default, the images are exported at their full resolution. */ imageResolution; /** * Specifies the name of the exported PDF file. */ fileName; /** * If set to `true`, the content is forwarded to `proxyURL` even if the * browser supports local saving of files. */ forceProxy; /** * The keywords (metadata) of the PDF document. */ keywords; /** * Specifies the margins of the page. * @default 'pt' */ margin; /** * Sets the scale factor for the output in PDF. Use this option when the text size on the screen is too big for printing. * * @default 1 */ scale; /** * A key/value dictionary of form values which will be sent to the proxy. * Can be used to submit Anti-Forgery tokens and other metadata. */ proxyData; /** * The URL of the server-side proxy which streams the file to the end user. You need to use a proxy if * the browser is not capable of saving files locally&mdash;for example, Internet Explorer 9 and Safari. * It is your responsibility to implement the server-side proxy. The proxy returns the decoded file with * the `"Content-Disposition"` header set to `attachment; filename="<fileName.pdf>"`. * * In the request body, the proxy receives a POST request with the following parameters: * - `"contentType"`&mdash;The MIME type of the file. * - `"base64"`&mdash;The base-64 encoded file content. * - `"fileName"`&mdash;The file name, as requested by the caller. * */ proxyURL; /** * Sets the name or keyword that indicates where to display the document returned from the proxy. * * To display the document in a new window or iframe, the proxy has to have the * `"Content-Disposition"` header set to `inline; filename="<fileName.pdf>"`. * * @default '_self' */ proxyTarget; /** * The producer (metadata) of the PDF document. */ producer; /** * The subject (metadata) of the PDF document. */ subject; /** * The title (metadata) of the PDF document. */ title; subscriptions; container; constructor(pdfService, ngZone) { this.pdfService = pdfService; this.ngZone = ngZone; this.subscriptions = this.pdfService.elementReady.subscribe(this.createElement.bind(this)); this.saveDataUri = this.saveDataUri.bind(this); this.exportGroup = this.exportGroup.bind(this); this.done = this.done.bind(this); } ngOnDestroy() { this.subscriptions.unsubscribe(); } get drawOptions() { return { _destructive: true, avoidLinks: this.avoidLinks, margin: this.margin, scale: this.scale }; } get pdfOptions() { return { author: this.author, creator: this.creator, date: this.date, imgDPI: this.imageResolution, keywords: this.keywords, margin: this.margin, producer: this.producer, subject: this.subject, title: this.title }; } get saveOptions() { return { forceProxy: this.forceProxy, proxyData: this.proxyData, proxyTarget: this.proxyTarget, proxyURL: this.proxyURL }; } createElement(args) { this.ngZone.runOutsideAngular(() => { const container = this.container = createDiv(); container.style.top = container.style.left = '-10000px'; container.style.position = 'absolute'; const wrapper = createDiv('k-scheduler'); wrapper.style.position = 'relative'; wrapper.appendChild(args.element); container.appendChild(wrapper); document.body.appendChild(container); this.save(wrapper); }); } save(element) { this.drawElement(element, this.drawOptions) .then(this.exportGroup) .then(this.saveDataUri) .then(this.done, this.done); } drawElement(element, options) { return drawDOM(element, options); } exportGroup(group) { return exportPDF(group, this.pdfOptions); } saveDataUri(dataUri) { saveAs(dataUri, this.fileName, this.saveOptions); } done() { if (this.container) { document.body.removeChild(this.container); this.container = null; } this.pdfService.done.emit(); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: PDFComponent, deps: [{ token: i1.PDFService }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.14", type: PDFComponent, isStandalone: true, selector: "kendo-scheduler-pdf", inputs: { author: "author", avoidLinks: "avoidLinks", creator: "creator", date: "date", imageResolution: "imageResolution", fileName: "fileName", forceProxy: "forceProxy", keywords: "keywords", margin: "margin", scale: "scale", proxyData: "proxyData", proxyURL: "proxyURL", proxyTarget: "proxyTarget", producer: "producer", subject: "subject", title: "title" }, ngImport: i0, template: '', isInline: true }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: PDFComponent, decorators: [{ type: Component, args: [{ selector: 'kendo-scheduler-pdf', template: '', standalone: true }] }], ctorParameters: () => [{ type: i1.PDFService }, { type: i0.NgZone }], propDecorators: { author: [{ type: Input }], avoidLinks: [{ type: Input }], creator: [{ type: Input }], date: [{ type: Input }], imageResolution: [{ type: Input }], fileName: [{ type: Input }], forceProxy: [{ type: Input }], keywords: [{ type: Input }], margin: [{ type: Input }], scale: [{ type: Input }], proxyData: [{ type: Input }], proxyURL: [{ type: Input }], proxyTarget: [{ type: Input }], producer: [{ type: Input }], subject: [{ type: Input }], title: [{ type: Input }] } });