Skip to content

Commit 957dd7a

Browse files
committed
Add TypeScript example for PSPDFKit integration
- Created a new TypeScript example project demonstrating the integration of PSPDFKit for Web. - Added essential files including package.json, README.md, and TypeScript configuration (tsconfig.json). - Implemented a basic HTML structure with a PDF viewer using PSPDFKit. - Included scripts for verifying installation and copying necessary PSPDFKit files. - Configured Webpack for development and production builds, including handling TypeScript files. - Added a sample PDF for demonstration purposes and styled the application with CSS. - Updated biome.json to include new ignore patterns for build artifacts.
1 parent 97c9cf1 commit 957dd7a

File tree

16 files changed

+6643
-1
lines changed

16 files changed

+6643
-1
lines changed

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
33
"files": {
4-
"ignore": ["examples/angular/.angular/cache/*"],
4+
"ignore": ["examples/angular/.angular/cache/*", "./examples/*/public/*"],
55
"ignoreUnknown": true
66
},
77
"formatter": {

examples/typescript/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
node_modules
3+
src/index.js
4+
src/index.js.map

examples/typescript/LICENSE

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
The PSPDFKit Sample applications are licensed with a modified BSD
2+
license. In plain language: you're allowed to do whatever you wish
3+
with the code, modify, redistribute, embed in your products (free or
4+
commercial), but you must include copyright, terms of usage and
5+
disclaimer as stated in the license.
6+
7+
You will require a commercial PSPDFKit License to run these examples
8+
in non-demo mode. Please refer to [email protected] for details.
9+
10+
Copyright © 2017-present PSPDFKit GmbH.
11+
All rights reserved.
12+
13+
Redistribution and use in source or binary forms,
14+
with or without modification, are permitted provided
15+
that the following conditions are met:
16+
17+
- Redistributions of source code must retain the above copyright
18+
notice, this list of conditions and the following disclaimer.
19+
20+
- Redistributions in binary form must reproduce the above copyright
21+
notice, this list of conditions and the following disclaimer in the
22+
documentation and/or other materials provided with the
23+
distribution.
24+
25+
- Redistributions of PSPDFKit Samples must include attribution to
26+
PSPDFKit, either in documentation or other appropriate media.
27+
28+
- Neither the name of the PSPDFKit, PSPDFKit GmbH, nor its developers
29+
may be used to endorse or promote products derived from
30+
this software without specific prior written permission.
31+
32+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
37+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
38+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
39+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
40+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
42+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

examples/typescript/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Nutrient Web SDK Example – Typescript
2+
3+
This example shows how to integrate [Nutrient Web SDK](https://www.nutrient.io/web/) into a [Typescript](https://www.typescriptlang.org) app.
4+
5+
## Prerequisites
6+
7+
- [Node.js](http://nodejs.org/)
8+
9+
## Getting Started
10+
11+
Clone the repo:
12+
13+
```bash
14+
git clone https://github.com/PSPDFKit/pspdfkit-web-example-typescript.git
15+
cd pspdfkit-web-example-typescript
16+
```
17+
18+
Install the project dependencies with `npm`:
19+
20+
```bash
21+
npm install
22+
```
23+
24+
## Running the Example
25+
26+
We are ready to launch the app! 🎉
27+
28+
```bash
29+
npm start
30+
```
31+
32+
You can now open http://localhost:3000 in your browser and enjoy!
33+
34+
## Support, Issues and License Questions
35+
36+
PSPDFKit offers support for customers with an active SDK license via https://www.nutrient.io/support/request/
37+
38+
Are you [evaluating our SDK](https://www.nutrient.io/try/)? That's great, we're happy to help out! To make sure this is fast, please use a work email and have someone from your company fill out our sales form: https://www.nutrient.io/sales/
39+
40+
## License
41+
42+
This software is licensed under a [modified BSD license](LICENSE).
43+
44+
## Contributing
45+
46+
Please ensure
47+
[you have signed our CLA](https://www.nutrient.io/guides/web/current/miscellaneous/contributing/) so that we can
48+
accept your contributions.
234 KB
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
try {
2+
require("pspdfkit");
3+
} catch (error) {
4+
if (!/cannot find module/i.test(error.message)) {
5+
process.exit(0);
6+
}
7+
8+
console.log(
9+
`This application requires you to install Nutrient Web SDK manually using your unique customer or trial url.
10+
For further instructions please refer to our online guide available at:
11+
12+
https://www.nutrient.io/guides/web/current/standalone/adding-to-your-project#toc_install-with-npm`,
13+
);
14+
process.exit(1);
15+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* webpack configuration file used to build both a development and production
3+
* version of the app.
4+
*
5+
* The production version is built in the `./dist` folder. When building the
6+
* development mode it also starts a web server at http://localhost:8080
7+
*
8+
* This configuration file creates two main bundles:
9+
*
10+
* - vendor.js - contains external libraries (including pspdfkit.js).
11+
* - app.js - contains the application code.
12+
*
13+
* It also copies the WASM/ASM and CSS files from the npm package folder, since
14+
* `PSPDFKit.load` loads them relative to the application execution path.
15+
*/
16+
17+
const path = require("node:path");
18+
const HtmlWebpackPlugin = require("html-webpack-plugin");
19+
const CopyWebpackPlugin = require("copy-webpack-plugin");
20+
21+
const filesToCopy = [
22+
// PSPDFKit files.
23+
{
24+
from: "./node_modules/pspdfkit/dist/pspdfkit-lib",
25+
to: "./pspdfkit-lib",
26+
},
27+
// Application CSS.
28+
{
29+
from: "./src/index.css",
30+
to: "./index.css",
31+
},
32+
// Example PDF.
33+
{
34+
from: "./assets/example.pdf",
35+
to: "./example.pdf",
36+
},
37+
];
38+
39+
/**
40+
* webpack main configuration object.
41+
*/
42+
const config = {
43+
entry: path.resolve(__dirname, "../src/index.ts"),
44+
mode: "development",
45+
devtool: "inline-source-map",
46+
output: {
47+
path: path.resolve(__dirname, "../dist"),
48+
filename: "[name].js",
49+
},
50+
resolve: {
51+
extensions: [".ts", ".tsx", ".js"],
52+
},
53+
module: {
54+
rules: [
55+
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
56+
{
57+
test: /\.tsx?$/,
58+
use: { loader: "ts-loader" },
59+
exclude: /node_modules/,
60+
},
61+
],
62+
},
63+
plugins: [
64+
// Automatically insert <script src="[name].js"><script> to the page.
65+
new HtmlWebpackPlugin({
66+
template: "./src/index.html",
67+
}),
68+
69+
// Copy the WASM/ASM and CSS files to the `output.path`.
70+
new CopyWebpackPlugin({
71+
patterns: filesToCopy,
72+
}),
73+
],
74+
75+
optimization: {
76+
splitChunks: {
77+
cacheGroups: {
78+
// Creates a `vendor.js` bundle which contains external libraries (including pspdfkit.js).
79+
vendor: {
80+
test: /node_modules/,
81+
chunks: "initial",
82+
name: "vendor",
83+
priority: 10,
84+
enforce: true,
85+
},
86+
},
87+
},
88+
},
89+
90+
devServer: {
91+
port: 3000,
92+
},
93+
};
94+
95+
module.exports = config;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @ts-check
2+
3+
import eslint from "@eslint/js";
4+
import tseslint from "typescript-eslint";
5+
6+
export default tseslint.config(
7+
eslint.configs.recommended,
8+
tseslint.configs.recommended,
9+
);

0 commit comments

Comments
 (0)