From 9be38e0f7e60cc7cb0c9537909bee81082b936c4 Mon Sep 17 00:00:00 2001 From: SF4524LogeshKumar Date: Wed, 30 Jul 2025 14:44:17 +0530 Subject: [PATCH] 932899: Updated Sample on How to Add date time in HandWrittenSignature --- .../.editorconfig | 16 ++ .../.gitignore | 42 ++++ .../README.md | 27 +++ .../angular.json | 101 ++++++++++ .../package.json | 40 ++++ .../src/app/app.component.css | 0 .../src/app/app.component.html | 11 ++ .../src/app/app.component.spec.ts | 31 +++ .../src/app/app.component.ts | 185 ++++++++++++++++++ .../src/app/app.module.ts | 48 +++++ .../src/assets/.gitkeep | 0 .../src/favicon.ico | Bin 0 -> 948 bytes .../src/index.html | 13 ++ .../src/main.ts | 7 + .../src/styles.css | 10 + .../tsconfig.app.json | 14 ++ .../tsconfig.json | 33 ++++ .../tsconfig.spec.json | 14 ++ 18 files changed, 592 insertions(+) create mode 100644 How to/Add datetime in HandWrittenSignature/.editorconfig create mode 100644 How to/Add datetime in HandWrittenSignature/.gitignore create mode 100644 How to/Add datetime in HandWrittenSignature/README.md create mode 100644 How to/Add datetime in HandWrittenSignature/angular.json create mode 100644 How to/Add datetime in HandWrittenSignature/package.json create mode 100644 How to/Add datetime in HandWrittenSignature/src/app/app.component.css create mode 100644 How to/Add datetime in HandWrittenSignature/src/app/app.component.html create mode 100644 How to/Add datetime in HandWrittenSignature/src/app/app.component.spec.ts create mode 100644 How to/Add datetime in HandWrittenSignature/src/app/app.component.ts create mode 100644 How to/Add datetime in HandWrittenSignature/src/app/app.module.ts create mode 100644 How to/Add datetime in HandWrittenSignature/src/assets/.gitkeep create mode 100644 How to/Add datetime in HandWrittenSignature/src/favicon.ico create mode 100644 How to/Add datetime in HandWrittenSignature/src/index.html create mode 100644 How to/Add datetime in HandWrittenSignature/src/main.ts create mode 100644 How to/Add datetime in HandWrittenSignature/src/styles.css create mode 100644 How to/Add datetime in HandWrittenSignature/tsconfig.app.json create mode 100644 How to/Add datetime in HandWrittenSignature/tsconfig.json create mode 100644 How to/Add datetime in HandWrittenSignature/tsconfig.spec.json diff --git a/How to/Add datetime in HandWrittenSignature/.editorconfig b/How to/Add datetime in HandWrittenSignature/.editorconfig new file mode 100644 index 0000000..59d9a3a --- /dev/null +++ b/How to/Add datetime in HandWrittenSignature/.editorconfig @@ -0,0 +1,16 @@ +# Editor configuration, see https://editorconfig.org +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.ts] +quote_type = single + +[*.md] +max_line_length = off +trim_trailing_whitespace = false diff --git a/How to/Add datetime in HandWrittenSignature/.gitignore b/How to/Add datetime in HandWrittenSignature/.gitignore new file mode 100644 index 0000000..0711527 --- /dev/null +++ b/How to/Add datetime in HandWrittenSignature/.gitignore @@ -0,0 +1,42 @@ +# See http://help.github.com/ignore-files/ for more about ignoring files. + +# Compiled output +/dist +/tmp +/out-tsc +/bazel-out + +# Node +/node_modules +npm-debug.log +yarn-error.log + +# IDEs and editors +.idea/ +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# Visual Studio Code +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +.history/* + +# Miscellaneous +/.angular/cache +.sass-cache/ +/connect.lock +/coverage +/libpeerconnection.log +testem.log +/typings + +# System files +.DS_Store +Thumbs.db diff --git a/How to/Add datetime in HandWrittenSignature/README.md b/How to/Add datetime in HandWrittenSignature/README.md new file mode 100644 index 0000000..b2cbbe3 --- /dev/null +++ b/How to/Add datetime in HandWrittenSignature/README.md @@ -0,0 +1,27 @@ +# Getting started + +This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 15.0.4. + +## Development server + +Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files. + +## Code scaffolding + +Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. + +## Build + +Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. + +## Running unit tests + +Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). + +## Running end-to-end tests + +Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities. + +## Further help + +To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. diff --git a/How to/Add datetime in HandWrittenSignature/angular.json b/How to/Add datetime in HandWrittenSignature/angular.json new file mode 100644 index 0000000..419ea66 --- /dev/null +++ b/How to/Add datetime in HandWrittenSignature/angular.json @@ -0,0 +1,101 @@ +{ + "$schema": "./node_modules/@angular/cli/lib/config/schema.json", + "version": 1, + "newProjectRoot": "projects", + "projects": { + "my-app": { + "projectType": "application", + "schematics": {}, + "root": "", + "sourceRoot": "src", + "prefix": "app", + "architect": { + "build": { + "builder": "@angular-devkit/build-angular:browser", + "options": { + "outputPath": "dist/my-app", + "index": "src/index.html", + "main": "src/main.ts", + "polyfills": [ + "zone.js" + ], + "tsConfig": "tsconfig.app.json", + "assets": [ + "src/favicon.ico", + "src/assets" + ], + "styles": [ + "src/styles.css" + ], + "scripts": [] + }, + "configurations": { + "production": { + "budgets": [ + { + "type": "initial", + "maximumWarning": "500kb", + "maximumError": "1mb" + }, + { + "type": "anyComponentStyle", + "maximumWarning": "2kb", + "maximumError": "4kb" + } + ], + "outputHashing": "all" + }, + "development": { + "buildOptimizer": false, + "optimization": false, + "vendorChunk": true, + "extractLicenses": false, + "sourceMap": true, + "namedChunks": true + } + }, + "defaultConfiguration": "production" + }, + "serve": { + "builder": "@angular-devkit/build-angular:dev-server", + "configurations": { + "production": { + "browserTarget": "my-app:build:production" + }, + "development": { + "browserTarget": "my-app:build:development" + } + }, + "defaultConfiguration": "development" + }, + "extract-i18n": { + "builder": "@angular-devkit/build-angular:extract-i18n", + "options": { + "browserTarget": "my-app:build" + } + }, + "test": { + "builder": "@angular-devkit/build-angular:karma", + "options": { + "polyfills": [ + "zone.js", + "zone.js/testing" + ], + "tsConfig": "tsconfig.spec.json", + "assets": [ + "src/favicon.ico", + "src/assets" + ], + "styles": [ + "src/styles.css" + ], + "scripts": [] + } + } + } + } + }, + "cli": { + "analytics": "8d9c65e2-01c9-4a66-bc68-685c535cc647" + } +} diff --git a/How to/Add datetime in HandWrittenSignature/package.json b/How to/Add datetime in HandWrittenSignature/package.json new file mode 100644 index 0000000..07570b4 --- /dev/null +++ b/How to/Add datetime in HandWrittenSignature/package.json @@ -0,0 +1,40 @@ +{ + "name": "my-app", + "version": "0.0.0", + "scripts": { + "ng": "ng", + "start": "ng serve", + "build": "ng build", + "watch": "ng build --watch --configuration development", + "test": "ng test" + }, + "private": true, + "dependencies": { + "@angular/animations": "^15.0.0", + "@angular/common": "^15.0.0", + "@angular/compiler": "^15.0.0", + "@angular/core": "^15.0.0", + "@angular/forms": "^15.0.0", + "@angular/platform-browser": "^15.0.0", + "@angular/platform-browser-dynamic": "^15.0.0", + "@angular/router": "^15.0.0", + "@syncfusion/ej2-angular-buttons": "^30.1.37", + "@syncfusion/ej2-angular-pdfviewer": "*", + "rxjs": "~7.5.0", + "tslib": "^2.3.0", + "zone.js": "~0.12.0" + }, + "devDependencies": { + "@angular-devkit/build-angular": "^15.0.4", + "@angular/cli": "~15.0.4", + "@angular/compiler-cli": "^15.0.0", + "@types/jasmine": "~4.3.0", + "jasmine-core": "~4.5.0", + "karma": "~6.4.0", + "karma-chrome-launcher": "~3.1.0", + "karma-coverage": "~2.2.0", + "karma-jasmine": "~5.1.0", + "karma-jasmine-html-reporter": "~2.0.0", + "typescript": "~4.8.2" + } +} diff --git a/How to/Add datetime in HandWrittenSignature/src/app/app.component.css b/How to/Add datetime in HandWrittenSignature/src/app/app.component.css new file mode 100644 index 0000000..e69de29 diff --git a/How to/Add datetime in HandWrittenSignature/src/app/app.component.html b/How to/Add datetime in HandWrittenSignature/src/app/app.component.html new file mode 100644 index 0000000..82bc587 --- /dev/null +++ b/How to/Add datetime in HandWrittenSignature/src/app/app.component.html @@ -0,0 +1,11 @@ + +
+
+ +
+
diff --git a/How to/Add datetime in HandWrittenSignature/src/app/app.component.spec.ts b/How to/Add datetime in HandWrittenSignature/src/app/app.component.spec.ts new file mode 100644 index 0000000..03e0fd7 --- /dev/null +++ b/How to/Add datetime in HandWrittenSignature/src/app/app.component.spec.ts @@ -0,0 +1,31 @@ +import { TestBed } from '@angular/core/testing'; +import { AppComponent } from './app.component'; + +describe('AppComponent', () => { + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ + AppComponent + ], + }).compileComponents(); + }); + + it('should create the app', () => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.componentInstance; + expect(app).toBeTruthy(); + }); + + it(`should have as title 'my-app'`, () => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.componentInstance; + expect(app.title).toEqual('my-app'); + }); + + it('should render title', () => { + const fixture = TestBed.createComponent(AppComponent); + fixture.detectChanges(); + const compiled = fixture.nativeElement as HTMLElement; + expect(compiled.querySelector('.content span')?.textContent).toContain('my-app app is running!'); + }); +}); diff --git a/How to/Add datetime in HandWrittenSignature/src/app/app.component.ts b/How to/Add datetime in HandWrittenSignature/src/app/app.component.ts new file mode 100644 index 0000000..e5838df --- /dev/null +++ b/How to/Add datetime in HandWrittenSignature/src/app/app.component.ts @@ -0,0 +1,185 @@ +import { Component, ViewEncapsulation, ViewChild } from '@angular/core'; +import { + PdfViewerComponent, + LinkAnnotationService, + BookmarkViewService, + MagnificationService, + ThumbnailViewService, + ToolbarService, + NavigationService, + TextSearchService, + TextSelectionService, + PrintService, + AnnotationService, + FormFieldsService, + FormDesignerService, + PageOrganizerService, + AddSignatureEventArgs, + HandWrittenSignatureSettings, + DisplayMode, +} from '@syncfusion/ej2-angular-pdfviewer'; +import { SwitchComponent } from '@syncfusion/ej2-angular-buttons'; + +/** + * Default PdfViewer Controller + */ +@Component({ + selector: 'app-root', + templateUrl: 'app.component.html', + encapsulation: ViewEncapsulation.None, + providers: [ + LinkAnnotationService, + BookmarkViewService, + MagnificationService, + ThumbnailViewService, + ToolbarService, + NavigationService, + TextSearchService, + TextSelectionService, + PrintService, + AnnotationService, + FormFieldsService, + FormDesignerService, + PageOrganizerService, + ], + styleUrls: ['app.component.css'] +}) +export class AppComponent { + @ViewChild('pdfviewer') + public pdfviewerControl: PdfViewerComponent | undefined; + @ViewChild('switch') + public switch: SwitchComponent | undefined; + + public document: string = + 'https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf'; + public resource: string = + 'https://cdn.syncfusion.com/ej2/23.2.6/dist/ej2-pdfviewer-lib'; + + // Flag to track if signature has been added + private signatureAddedFlag: boolean = false; + + ngOnInit(): void { + // ngOnInit function + } + + public SignatureAdded(args: AddSignatureEventArgs): void { + if (this.signatureAddedFlag) { + this.signatureAddedFlag = false; + return; // Exit if signature has already been added + } + + let id = ''; + let proxy = this; + console.log(args); + if (id !== args.id) { + id = args.id; + } + + if ( + args.type === 'HandWrittenSignature' || + args.type === 'SignatureImage' + ) { + // Set the flag to true, indicating that a signature is being added + this.signatureAddedFlag = true; + var c: any = document.createElement('canvas'); + c.width = 300; + c.height = 150; + var ctx = c.getContext('2d'); + + // Load the signature image + var image = new Image(); + image.onload = function () { + ctx.drawImage(image, 0, 0, 300, 150); + var date = new Date().toLocaleDateString(); + ctx.font = 'italic 18px Arial'; + ctx.fillStyle = 'blue'; + ctx.fillText(date, 10, 140); + var imagedata = c.toDataURL('image/png'); + console.log(imagedata); + var signatureCollections: any = + proxy.pdfviewerControl?.signatureCollection; + for (var x = 0; x < signatureCollections.length; x++) { + if (signatureCollections[x].annotationId === args.id) { + var left = args.bounds.left; + var top = args.bounds.top; + var width = args.bounds.width; + var height = args.bounds.height; + + signatureCollections[x].signatureType = 'Image'; + signatureCollections[x].value = imagedata; + proxy.pdfviewerControl?.annotation.deleteAnnotationById(args.id); + proxy.pdfviewerControl?.annotation.addAnnotation( + 'HandWrittenSignature', + { + offset: { x: left, y: top }, + pageNumber: 1, + width: width, + height: height, + signatureItem: ['Signature'], + signatureDialogSettings: { + displayMode: DisplayMode.Upload, + hideSaveSignature: false, + }, + canSave: false, + path: imagedata, + } as HandWrittenSignatureSettings + ); + } + } + }; + if (args.data) { + image.src = args.data; // Set the image source with null check + } else { + console.error('Signature data is undefined'); + } + } else if (args.type === 'SignatureText') { + this.signatureAddedFlag = true; + var signatureCollections: any = + proxy.pdfviewerControl?.signatureCollection; + for (var x = 0; x < signatureCollections.length; x++) { + if (signatureCollections[x].annotationId === args.id) { + const signatureText = args.data; + const date = new Date().toLocaleDateString(); + const updatedValue = signatureText + '\n' + date; + signatureCollections[x].signatureType = 'Text'; + signatureCollections[x].value = updatedValue; + var left = args.bounds.left; + var top = args.bounds.top; + var width = args.bounds.width; + var height = args.bounds.height; + var canvas: any = document.createElement('canvas'); + canvas.width = width; + canvas.height = height; + var ctx = canvas.getContext('2d'); + ctx.font = 'normal 16px Arial'; + ctx.fillStyle = 'black'; + ctx.textAlign = 'left'; + ctx.fillText(signatureText, 10, 30); + ctx.font = 'italic 14px Arial'; + ctx.fillStyle = 'blue'; + ctx.fillText(date, 10, 60); + var imageData = canvas.toDataURL('image/png'); + proxy.pdfviewerControl?.annotation.deleteAnnotationById(args.id); + proxy.pdfviewerControl?.annotation.addAnnotation( + 'HandWrittenSignature', + { + offset: { x: left, y: top }, + pageNumber: 1, + width: width, + height: height, + signatureItem: ['Signature'], + signatureDialogSettings: { + displayMode: DisplayMode.Upload, + hideSaveSignature: false, + }, + canSave: false, + path: imageData, + } as HandWrittenSignatureSettings + ); + } + } + } else { + id = ''; + } + } +} \ No newline at end of file diff --git a/How to/Add datetime in HandWrittenSignature/src/app/app.module.ts b/How to/Add datetime in HandWrittenSignature/src/app/app.module.ts new file mode 100644 index 0000000..9d9b28a --- /dev/null +++ b/How to/Add datetime in HandWrittenSignature/src/app/app.module.ts @@ -0,0 +1,48 @@ +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; +import { AppComponent } from './app.component'; +import { + PdfViewerModule, + LinkAnnotationService, + BookmarkViewService, + MagnificationService, + ThumbnailViewService, + ToolbarService, + NavigationService, + TextSearchService, + TextSelectionService, + PrintService, + AnnotationService, + FormFieldsService, + FormDesignerService, + PageOrganizerService +} from '@syncfusion/ej2-angular-pdfviewer'; +import { SwitchModule } from '@syncfusion/ej2-angular-buttons'; + +@NgModule({ + declarations: [ + AppComponent + ], + imports: [ + BrowserModule, + PdfViewerModule, + SwitchModule + ], + providers: [ + LinkAnnotationService, + BookmarkViewService, + MagnificationService, + ThumbnailViewService, + ToolbarService, + NavigationService, + TextSearchService, + TextSelectionService, + PrintService, + AnnotationService, + FormFieldsService, + FormDesignerService, + PageOrganizerService + ], + bootstrap: [AppComponent] +}) +export class AppModule { } diff --git a/How to/Add datetime in HandWrittenSignature/src/assets/.gitkeep b/How to/Add datetime in HandWrittenSignature/src/assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/How to/Add datetime in HandWrittenSignature/src/favicon.ico b/How to/Add datetime in HandWrittenSignature/src/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..997406ad22c29aae95893fb3d666c30258a09537 GIT binary patch literal 948 zcmV;l155mgP)CBYU7IjCFmI-B}4sMJt3^s9NVg!P0 z6hDQy(L`XWMkB@zOLgN$4KYz;j0zZxq9KKdpZE#5@k0crP^5f9KO};h)ZDQ%ybhht z%t9#h|nu0K(bJ ztIkhEr!*UyrZWQ1k2+YkGqDi8Z<|mIN&$kzpKl{cNP=OQzXHz>vn+c)F)zO|Bou>E z2|-d_=qY#Y+yOu1a}XI?cU}%04)zz%anD(XZC{#~WreV!a$7k2Ug`?&CUEc0EtrkZ zL49MB)h!_K{H(*l_93D5tO0;BUnvYlo+;yss%n^&qjt6fZOa+}+FDO(~2>G z2dx@=JZ?DHP^;b7*Y1as5^uphBsh*s*z&MBd?e@I>-9kU>63PjP&^#5YTOb&x^6Cf z?674rmSHB5Fk!{Gv7rv!?qX#ei_L(XtwVqLX3L}$MI|kJ*w(rhx~tc&L&xP#?cQow zX_|gx$wMr3pRZIIr_;;O|8fAjd;1`nOeu5K(pCu7>^3E&D2OBBq?sYa(%S?GwG&_0-s%_v$L@R!5H_fc)lOb9ZoOO#p`Nn`KU z3LTTBtjwo`7(HA6 z7gmO$yTR!5L>Bsg!X8616{JUngg_@&85%>W=mChTR;x4`P=?PJ~oPuy5 zU-L`C@_!34D21{fD~Y8NVnR3t;aqZI3fIhmgmx}$oc-dKDC6Ap$Gy>a!`A*x2L1v0 WcZ@i?LyX}70000 + + + + MyApp + + + + + + + + diff --git a/How to/Add datetime in HandWrittenSignature/src/main.ts b/How to/Add datetime in HandWrittenSignature/src/main.ts new file mode 100644 index 0000000..c58dc05 --- /dev/null +++ b/How to/Add datetime in HandWrittenSignature/src/main.ts @@ -0,0 +1,7 @@ +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; + +import { AppModule } from './app/app.module'; + + +platformBrowserDynamic().bootstrapModule(AppModule) + .catch(err => console.error(err)); diff --git a/How to/Add datetime in HandWrittenSignature/src/styles.css b/How to/Add datetime in HandWrittenSignature/src/styles.css new file mode 100644 index 0000000..fc9d8ef --- /dev/null +++ b/How to/Add datetime in HandWrittenSignature/src/styles.css @@ -0,0 +1,10 @@ +/* You can add global styles to this file, and also import other style files */ +@import '../node_modules/@syncfusion/ej2-base/styles/material.css'; +@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css'; +@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css'; +@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css'; +@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css'; +@import '../node_modules/@syncfusion/ej2-popups/styles/material.css'; +@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css'; +@import '../node_modules/@syncfusion/ej2-pdfviewer/styles/material.css'; +@import '../node_modules/@syncfusion/ej2-notifications/styles/material.css'; \ No newline at end of file diff --git a/How to/Add datetime in HandWrittenSignature/tsconfig.app.json b/How to/Add datetime in HandWrittenSignature/tsconfig.app.json new file mode 100644 index 0000000..374cc9d --- /dev/null +++ b/How to/Add datetime in HandWrittenSignature/tsconfig.app.json @@ -0,0 +1,14 @@ +/* To learn more about this file see: https://angular.io/config/tsconfig. */ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "./out-tsc/app", + "types": [] + }, + "files": [ + "src/main.ts" + ], + "include": [ + "src/**/*.d.ts" + ] +} diff --git a/How to/Add datetime in HandWrittenSignature/tsconfig.json b/How to/Add datetime in HandWrittenSignature/tsconfig.json new file mode 100644 index 0000000..ed966d4 --- /dev/null +++ b/How to/Add datetime in HandWrittenSignature/tsconfig.json @@ -0,0 +1,33 @@ +/* To learn more about this file see: https://angular.io/config/tsconfig. */ +{ + "compileOnSave": false, + "compilerOptions": { + "baseUrl": "./", + "outDir": "./dist/out-tsc", + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "sourceMap": true, + "declaration": false, + "downlevelIteration": true, + "experimentalDecorators": true, + "moduleResolution": "node", + "importHelpers": true, + "target": "ES2022", + "module": "ES2022", + "useDefineForClassFields": false, + "lib": [ + "ES2022", + "dom" + ] + }, + "angularCompilerOptions": { + "enableI18nLegacyMessageIdFormat": false, + "strictInjectionParameters": true, + "strictInputAccessModifiers": true, + "strictTemplates": true + } +} diff --git a/How to/Add datetime in HandWrittenSignature/tsconfig.spec.json b/How to/Add datetime in HandWrittenSignature/tsconfig.spec.json new file mode 100644 index 0000000..be7e9da --- /dev/null +++ b/How to/Add datetime in HandWrittenSignature/tsconfig.spec.json @@ -0,0 +1,14 @@ +/* To learn more about this file see: https://angular.io/config/tsconfig. */ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "./out-tsc/spec", + "types": [ + "jasmine" + ] + }, + "include": [ + "src/**/*.spec.ts", + "src/**/*.d.ts" + ] +}