Skip to content

Commit 7c923bf

Browse files
authored
Merge pull request #49 from SyncfusionExamples/EJ2-931940-customFont
931940: Sample on How to load Custom Fonts for Pre-Exisiting Signature using UseEffect
2 parents 562fde4 + cb7a6e2 commit 7c923bf

File tree

14 files changed

+308
-0
lines changed

14 files changed

+308
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Getting Started with Create React App
2+
3+
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4+
5+
## Available Scripts
6+
7+
In the project directory, you can run:
8+
9+
### `npm start`
10+
11+
Runs the app in the development mode.\
12+
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
13+
14+
The page will reload when you make changes.\
15+
You may also see any lint errors in the console.
16+
17+
### `npm test`
18+
19+
Launches the test runner in the interactive watch mode.\
20+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21+
22+
### `npm run build`
23+
24+
Builds the app for production to the `build` folder.\
25+
It correctly bundles React in production mode and optimizes the build for the best performance.
26+
27+
The build is minified and the filenames include the hashes.\
28+
Your app is ready to be deployed!
29+
30+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31+
32+
### `npm run eject`
33+
34+
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
35+
36+
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37+
38+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
39+
40+
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
41+
42+
## Learn More
43+
44+
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45+
46+
To learn React, check out the [React documentation](https://reactjs.org/).
47+
48+
### Code Splitting
49+
50+
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51+
52+
### Analyzing the Bundle Size
53+
54+
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55+
56+
### Making a Progressive Web App
57+
58+
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59+
60+
### Advanced Configuration
61+
62+
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63+
64+
### Deployment
65+
66+
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67+
68+
### `npm run build` fails to minify
69+
70+
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "quickstart",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@syncfusion/ej2-react-pdfviewer": "*",
7+
"@testing-library/jest-dom": "^5.16.5",
8+
"@testing-library/react": "^13.4.0",
9+
"@testing-library/user-event": "^13.5.0",
10+
"react": "^18.2.0",
11+
"react-dom": "^18.2.0",
12+
"react-scripts": "5.0.1",
13+
"web-vitals": "^2.1.4"
14+
},
15+
"scripts": {
16+
"start": "react-scripts start",
17+
"build": "react-scripts build",
18+
"test": "react-scripts test",
19+
"eject": "react-scripts eject"
20+
},
21+
"eslintConfig": {
22+
"extends": [
23+
"react-app",
24+
"react-app/jest"
25+
]
26+
},
27+
"browserslist": {
28+
"production": [
29+
">0.2%",
30+
"not dead",
31+
"not op_mini all"
32+
],
33+
"development": [
34+
"last 1 chrome version",
35+
"last 1 firefox version",
36+
"last 1 safari version"
37+
]
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Syncfusion React PDF Viewer</title>
5+
<meta charset="utf-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<meta name="description" content="Essential JS 2 for React Components" />
8+
<meta name="author" content="Syncfusion" />
9+
<link href="https://cdn.syncfusion.com/ej2/26.1.35/bootstrap5.css" rel="stylesheet">
10+
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
11+
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js"></script>
12+
</head>
13+
<body>
14+
<div style="margin-top: 50px;"></div>
15+
<div id='sample'>
16+
<div id='loader'>Loading....</div>
17+
</div>
18+
</body>
19+
</html>
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
},
10+
{
11+
"src": "logo192.png",
12+
"type": "image/png",
13+
"sizes": "192x192"
14+
},
15+
{
16+
"src": "logo512.png",
17+
"type": "image/png",
18+
"sizes": "512x512"
19+
}
20+
],
21+
"start_url": ".",
22+
"display": "standalone",
23+
"theme_color": "#000000",
24+
"background_color": "#ffffff"
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://www.robotstxt.org/robotstxt.html
2+
User-agent: *
3+
Disallow:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
2+
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
3+
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
4+
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
5+
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
6+
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
7+
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
8+
@import "../node_modules/@syncfusion/ej2-pdfviewer/styles/material.css";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { createRoot } from 'react-dom/client';
2+
import './index.css';
3+
import * as React from 'react';
4+
import {
5+
PdfViewerComponent,
6+
Toolbar,
7+
Magnification,
8+
Navigation,
9+
LinkAnnotation,
10+
BookmarkView,
11+
ThumbnailView,
12+
Print,
13+
TextSelection,
14+
TextSearch,
15+
Annotation,
16+
FormFields,
17+
FormDesigner,
18+
PageOrganizer,
19+
Inject,
20+
} from '@syncfusion/ej2-react-pdfviewer';
21+
22+
function Default() {
23+
let viewer;
24+
React.useEffect(() => {
25+
// Load Google Fonts using Web Font Loader
26+
if (window.WebFont) {
27+
window.WebFont.load({
28+
google: {
29+
families: ['Roboto:300,400,700', 'Caveat:300,400,700'], // Add required fonts
30+
},
31+
loading: function () {
32+
console.log('Fonts are being loaded');
33+
},
34+
active: function () {
35+
console.log('Fonts have been rendered');
36+
},
37+
inactive: function () {
38+
console.error('Failed to load fonts');
39+
},
40+
});
41+
}
42+
}, []);
43+
const documentLoad = (args) => {
44+
//var viewer = document.getElementById('container').ej2_instances[0];
45+
//To add form fields
46+
// viewer.formDesignerModule.addFormField('SignatureField', {
47+
// bounds: { X: 146, Y: 200, Width: 150, Height: 70 },
48+
// });
49+
50+
//To retrieve form fields
51+
const formFields = viewer.retrieveFormFields();
52+
const field = formFields[0];
53+
//To update form fields value
54+
if(field){
55+
field.value = 'Tiago';
56+
field.fontName = 'Caveat';
57+
viewer?.updateFormFieldsValue(field);
58+
}
59+
};
60+
return (
61+
<div>
62+
<div className="control-section">
63+
</div>
64+
{/* Render the PDF Viewer */}
65+
<PdfViewerComponent
66+
ref={(scope) => {
67+
viewer = scope;
68+
}}
69+
id="container"
70+
documentLoad={documentLoad}
71+
documentPath="https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf"
72+
resourceUrl="https://cdn.syncfusion.com/ej2/23.2.6/dist/ej2-pdfviewer-lib"
73+
style={{ height: '640px' }}
74+
signatureFieldSettings={{
75+
typeSignatureFonts: ['Caveat'],
76+
}}
77+
>
78+
<Inject
79+
services={[
80+
Toolbar,
81+
Magnification,
82+
Navigation,
83+
LinkAnnotation,
84+
BookmarkView,
85+
ThumbnailView,
86+
Print,
87+
TextSelection,
88+
TextSearch,
89+
Annotation,
90+
FormFields,
91+
FormDesigner,
92+
PageOrganizer,
93+
]}
94+
/>
95+
</PdfViewerComponent>
96+
</div>
97+
);
98+
}
99+
export default Default;
100+
101+
const root = createRoot(document.getElementById('sample'));
102+
root.render(<Default />);
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const reportWebVitals = onPerfEntry => {
2+
if (onPerfEntry && onPerfEntry instanceof Function) {
3+
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4+
getCLS(onPerfEntry);
5+
getFID(onPerfEntry);
6+
getFCP(onPerfEntry);
7+
getLCP(onPerfEntry);
8+
getTTFB(onPerfEntry);
9+
});
10+
}
11+
};
12+
13+
export default reportWebVitals;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// jest-dom adds custom jest matchers for asserting on DOM nodes.
2+
// allows you to do things like:
3+
// expect(element).toHaveTextContent(/react/i)
4+
// learn more: https://github.com/testing-library/jest-dom
5+
import '@testing-library/jest-dom';

0 commit comments

Comments
 (0)