ts-d2 0.0.4 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -1
- package/dist/{index.mjs → index.cjs} +268 -153
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.mts → index.d.cts} +53 -28
- package/dist/index.d.ts +53 -28
- package/dist/index.js +242 -154
- package/dist/index.js.map +1 -0
- package/package.json +34 -42
package/README.md
CHANGED
|
@@ -11,6 +11,28 @@ The following output formats are supported:
|
|
|
11
11
|
* Images (BMP, PNG and more)
|
|
12
12
|
* PostScript
|
|
13
13
|
|
|
14
|
+
## Configuration
|
|
15
|
+
|
|
16
|
+
Before using the library, you need to configure your docPIPE API connection. Create a `.env` file in your project root:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
cp .env.example .env
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Then edit the `.env` file and set your docPIPE API credentials:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# The URL of your docPIPE API server
|
|
26
|
+
DOCPIPE_URL=http://localhost:8080
|
|
27
|
+
|
|
28
|
+
# Your docPIPE API authentication token
|
|
29
|
+
DOCPIPE_TOKEN=your-token-here
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Note:** The `.env` file is already included in `.gitignore` to prevent accidentally committing sensitive credentials.
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
14
36
|
This is a small example creating a document with the content "Hello World" as PDF:
|
|
15
37
|
|
|
16
38
|
```typescript
|
|
@@ -25,6 +47,27 @@ new Deuterium.Content.Document("Hello World")
|
|
|
25
47
|
});
|
|
26
48
|
```
|
|
27
49
|
|
|
50
|
+
### Custom Connection
|
|
51
|
+
|
|
52
|
+
By default, the library uses the connection credentials from your `.env` file. If you need to use different credentials for a specific conversion, you can create a custom `Connection` instance:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import Deuterium from "ts-d2";
|
|
56
|
+
|
|
57
|
+
// Create a custom connection with different credentials
|
|
58
|
+
const customConnection = new Deuterium.Connection(
|
|
59
|
+
"https://api.example.com",
|
|
60
|
+
"custom-token-here"
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
// Use the custom connection for conversion
|
|
64
|
+
const doc = new Deuterium.Content.Document("Hello World");
|
|
65
|
+
customConnection.convertTo(Deuterium.OutputFormat.PDF, doc)
|
|
66
|
+
.then(async (buffer) => {
|
|
67
|
+
fs.writeFileSync("output.pdf", Buffer.from(await buffer.arrayBuffer()));
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
28
71
|
# Basics
|
|
29
72
|
|
|
30
73
|
Documents are divided into DocumentElements, which are the smallest part of a document (like text, vertical space, etc.).
|
|
@@ -44,6 +87,7 @@ The following leaf elements are currently supported:
|
|
|
44
87
|
* Footer
|
|
45
88
|
* Formatted (may be used to directly insert docTYPE code and/or HTML code)
|
|
46
89
|
* Header
|
|
90
|
+
* Linebreak
|
|
47
91
|
* Pagebreak
|
|
48
92
|
* PageDefinition (only useful for page-based formats)
|
|
49
93
|
* Paragraph
|
|
@@ -84,7 +128,6 @@ The following branch elements are supported:
|
|
|
84
128
|
* Directory
|
|
85
129
|
* Document
|
|
86
130
|
* Footer
|
|
87
|
-
* Formatted
|
|
88
131
|
* Header
|
|
89
132
|
* Paragraph
|
|
90
133
|
* Span
|
|
@@ -107,3 +150,24 @@ Especially the first variant of the content parameter can result in small code:
|
|
|
107
150
|
```typescript
|
|
108
151
|
new Deuterium.Content.Footer("...");
|
|
109
152
|
```
|
|
153
|
+
|
|
154
|
+
# Contributing
|
|
155
|
+
|
|
156
|
+
Contributions to this project are very welcome. If you want to contribute, please create a pull request with your changes and a description of what you have done.
|
|
157
|
+
|
|
158
|
+
## Building the project
|
|
159
|
+
|
|
160
|
+
To build the project, you need to have Node.js and npm installed. Then you can run the following command in the project directory:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
pnpm install
|
|
164
|
+
pnpm run build
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Testing the project
|
|
168
|
+
|
|
169
|
+
To run the tests, you can use the following command:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
pnpm run test
|
|
173
|
+
```
|