Skip to content

Commit fe7d8fa

Browse files
committed
DOC-2582: Add importword and exportword guide.
1 parent 9ccd3e0 commit fe7d8fa

File tree

5 files changed

+430
-12
lines changed

5 files changed

+430
-12
lines changed

modules/ROOT/nav.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,12 @@
315315
**** xref:export-to-pdf-with-jwt-authentication-nodejs.adoc[Export to PDF with JWT authentication (Nodejs)]
316316
**** xref:html-to-pdf-converter-api.adoc[HTML to PDF Converter API]
317317
*** xref:exportword.adoc[Export to Word]
318+
**** xref:export-to-word-with-jwt-authentication-nodejs.adoc[Export to Word with JWT authentication (Nodejs)]
318319
**** xref:html-to-docx-converter-api.adoc[HTML to DOCX Converter API]
319320
*** xref:footnotes.adoc[Footnotes]
320321
*** xref:formatpainter.adoc[Format Painter]
321322
*** xref:importword.adoc[Import from Word]
323+
**** xref:importword-with-jwt-authentication-nodejs.adoc[Import from Word with JWT authentication (Nodejs)]
322324
**** xref:docx-to-html-converter-api.adoc[DOCX to HTML Converter API]
323325
*** xref:editimage.adoc[Image Editing]
324326
*** xref:inline-css.adoc[Inline CSS]

modules/ROOT/pages/export-to-pdf-with-jwt-authentication-nodejs.adoc

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
= Export to PDF with JWT authentication (Node.js) Guide
1+
= {pluginname} with JWT authentication (Node.js) Guide
22
:navtitle: JWT Authentication setup for Export to PDF
3-
:description: Guide on how to setup JWT Authentication for exporting PDF files with {productname}
3+
:description: Guide on how to setup JWT Authentication for exporting pdf files with Export to PDF
44
:keywords: jwt, authentication, exportpdf, pdf, node.js
55
:pluginname: Export to PDF
66
:plugincode: exportpdf
@@ -16,21 +16,21 @@ This guide provides a comprehensive walkthrough for integrating {pluginname} wit
1616

1717
Before diving into the technical details, here's what you'll achieve with this guide:
1818

19-
* A working PDF export system for your TinyMCE editor
19+
* A working PDF export system for your {productname} editor
2020
* A secure authentication system using JWT tokens
2121
* A simple Node.js server to handle the authentication
2222

2323
[TIP]
2424
====
25-
This guide is designed for developers new to JWT authentication and TinyMCE integration.
25+
This guide is designed for developers new to JWT authentication and {productname} integration.
2626
====
2727

2828
== Prerequisites
2929

3030
Before starting, ensure you have:
3131

3232
* Node.js installed on your computer
33-
* A TinyMCE API key (get one from link:https://www.tiny.cloud/signup[TinyMCE's website])
33+
* A {productname} API key (get one from link:https://www.tiny.cloud/signup[TinyMCE's website])
3434
* Basic familiarity with the command line
3535

3636
[IMPORTANT]
@@ -207,9 +207,5 @@ node jwt.js
207207

208208
. Open your browser to: `http://localhost:3000`
209209
. You should see:
210-
* The TinyMCE editor
211-
* An "Export PDF" button in the toolbar
212-
213-
=== Start Server
214-
215-
* Define the port and start the server using `app.listen`.
210+
* The {productname} editor
211+
* An "Export to PDF" button in the toolbar
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
= {pluginname} with JWT authentication (Node.js) Guide
2+
:navtitle: JWT Authentication setup for Export to Word
3+
:description: Guide on how to setup JWT Authentication for exporting docx files with Export to Word
4+
:keywords: jwt, authentication, exportword, node.js
5+
:pluginname: Export to Word
6+
:plugincode: exportword
7+
8+
9+
== Introduction
10+
11+
{pluginname} requires setting up JSON Web Token (JWT) authentication to maintain control over file security. A JWT endpoint generates and provides authorization tokens that verify submitted content is sent by authorized users, preventing unauthorized access. As a standard web services authorization solution, JWT is documented extensively at link:https://jwt.io/[https://jwt.io/].
12+
13+
This guide provides a comprehensive walkthrough for integrating {pluginname} with {productname}, including {pluginname} functionality, by using a Node.js server for JWT token generation. It covers project setup, server configuration, and {productname} customization.
14+
15+
== What You'll Build
16+
17+
Before diving into the technical details, here's what you'll achieve with this guide:
18+
19+
* A working {pluginname} system for your {productname} editor
20+
* A secure authentication system using JWT tokens
21+
* A simple Node.js server to handle the authentication
22+
23+
[TIP]
24+
====
25+
This guide is designed for developers new to JWT authentication and {productname} integration.
26+
====
27+
28+
== Prerequisites
29+
30+
Before starting, ensure you have:
31+
32+
* Node.js installed on your computer
33+
* A {productname} API key (get one from link:https://www.tiny.cloud/signup[TinyMCE's website])
34+
* Basic familiarity with the command line
35+
36+
[IMPORTANT]
37+
====
38+
Make sure you have your API key ready before starting. You'll need it for both the server and client configuration.
39+
====
40+
41+
== Quick Start Guide
42+
43+
=== Project Setup (5 minutes)
44+
45+
[source,bash]
46+
----
47+
# Create and enter project directory
48+
mkdir tinymce-export-to-word
49+
cd tinymce-export-to-word
50+
51+
# Initialize project
52+
npm init -y
53+
54+
# Install required packages
55+
npm install express cors jsonwebtoken
56+
----
57+
58+
Verify that the `package.json` file includes the below required dependencies:
59+
60+
[source,json]
61+
----
62+
{
63+
"dependencies": {
64+
"cors": "^2.8.5",
65+
"express": "^4.21.0",
66+
"jsonwebtoken": "^9.0.2"
67+
}
68+
}
69+
----
70+
71+
=== Create Project Structure
72+
73+
[source,bash]
74+
----
75+
# Create the public folder for your web files
76+
mkdir public
77+
touch public/index.html
78+
touch jwt.js
79+
----
80+
81+
Your project should look like this:
82+
83+
[source]
84+
----
85+
/tinymce-export-to-word
86+
/public
87+
index.html (TinyMCE webpage)
88+
jwt.js (Server code)
89+
package.json (Project configuration)
90+
----
91+
92+
. Inside the `public` folder where you created the `index.html` file add the HTML setup code (refer to the *Setting up {productname} HTML* section).
93+
94+
==== Web Page Setup (public/index.html)
95+
96+
[source,html]
97+
----
98+
<!DOCTYPE html>
99+
<html>
100+
<head>
101+
<title>TinyMCE with Export to Word</title>
102+
<script
103+
src="https://cdn.tiny.cloud/1/YOUR-API-KEY/tinymce/7/tinymce.min.js"
104+
referrerpolicy="origin">
105+
</script>
106+
<script>
107+
tinymce.init({
108+
selector: 'textarea',
109+
plugins: 'exportword',
110+
toolbar: 'exportword',
111+
exportword_converter_options: {
112+
'document': {
113+
'size': 'Letter'
114+
}
115+
},
116+
exportword_service_url: "<serviceURL>",
117+
118+
// export_token_provider fetches a token from the `/jwt` endpoint.
119+
exportword_token_provider: () => {
120+
return fetch('http://localhost:3000/jwt', {
121+
method: 'POST',
122+
headers: { 'Content-Type': 'application/json' },
123+
}).then(response => response.json());
124+
},
125+
});
126+
</script>
127+
</head>
128+
<body>
129+
<h1>TinyMCE Export to Word Demo</h1>
130+
<textarea>
131+
Welcome to TinyMCE! Try the Export to Word feature.
132+
</textarea>
133+
</body>
134+
</html>
135+
----
136+
137+
. In the root directory, copy and paste the server setup code into the `jwt.js` file (refer to the *Configuring the Node.js Server for JWT Token Generation* section).
138+
139+
==== Server Setup (jwt.js)
140+
141+
[source,javascript]
142+
----
143+
const express = require('express'); // Sets up the web server.
144+
const jwt = require('jsonwebtoken'); // Generates and signs JWTs.
145+
const cors = require('cors'); // Allows cross-origin requests.
146+
const path = require('path'); // Handles file paths.
147+
148+
const app = express();
149+
app.use(cors());
150+
151+
// Your private key (Replace this with your actual key)
152+
const privateKey = `
153+
-----BEGIN PRIVATE KEY-----
154+
{Your private PKCS8 key goes here}
155+
-----END PRIVATE KEY-----
156+
`;
157+
158+
app.use(express.static(path.join(__dirname, 'public')));
159+
160+
// JWT token generation endpoint
161+
app.post('/jwt', (req, res) => {
162+
const payload = {
163+
aud: 'YOUR-API-KEY-HERE', // Replace with your actual API key
164+
iat: Math.floor(Date.now() / 1000), // Issue timestamp
165+
exp: Math.floor(Date.now() / 1000) + (60 * 10) // Expiration time (10 minutes)
166+
};
167+
168+
try {
169+
// Tokens are signed with the RS256 algorithm using your private key
170+
const token = jwt.sign(payload, privateKey, { algorithm: 'RS256' });
171+
res.json({ token });
172+
} catch (error) {
173+
res.status(500).send('Failed to generate JWT token.');
174+
console.error(error.message);
175+
}
176+
});
177+
178+
const PORT = 3000;
179+
app.listen(PORT, () => {
180+
console.log(`Server running at http://localhost:${PORT}`);
181+
});
182+
----
183+
184+
=== Configuration Steps
185+
186+
==== 1. Add Your API Key
187+
188+
* Replace `YOUR-API-KEY` in both files with your actual {productname} API key
189+
* The API key should be the same in both the HTML script source and the JWT payload
190+
191+
==== 2. Add Your Private Key
192+
193+
* Replace the private key placeholder in `jwt.js` with your actual private key
194+
* Make sure it's in `PKCS8` format
195+
* Keep this key secure and never share it publicly
196+
197+
=== Running Your Project
198+
199+
. Start the server:
200+
+
201+
[source,bash]
202+
----
203+
node jwt.js
204+
----
205+
206+
. Open your browser to: `http://localhost:3000`
207+
. You should see:
208+
* The {productname} editor
209+
* An "Export to Word" button in the toolbar

modules/ROOT/pages/exportword.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= Export to Word
1+
= Export to Word plugin
22
:navtitle: exportword
33
:description: The export to Word feature lets you generate a .docx file directly from the editor.
44
:description_short: Generate a .docx file directly from the editor.

0 commit comments

Comments
 (0)