Skip to content

Commit

Permalink
Update docs for new Packer methods (#2961)
Browse files Browse the repository at this point in the history
To cover #2920
  • Loading branch information
joshkel authored Feb 17, 2025
1 parent a887927 commit 4e2befb
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion docs/usage/packers.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Packers are the way in which `docx` turns your code into `.docx` format. It is completely decoupled from the `docx.Document`.
Packers works in both a node and browser environment (Angular etc). Now, the packer returns a `Buffer`, `Blob`, `string`, `base64 string`, or `Stream`. It is up to you to take that and persist it with node's `fs`, send it down as a downloadable file, or anything else you wish. As of `version 4+`, this library will not have options to export to PDF.
Packers works in both a node and browser environment (Angular etc). Now, the packer returns a `Buffer`, `Blob`, `string`, `base64 string`, `ArrayBuffer`, or `Stream`. It is up to you to take that and persist it with node's `fs`, send it down as a downloadable file, or anything else you wish. As of `version 4+`, this library will not have options to export to PDF.

### Export as Buffer

Expand Down Expand Up @@ -41,6 +41,16 @@ Packer.toBlob(doc).then((blob) => {
});
```

### Export as ArrayBuffer

This may be useful when working in a Node.js worker.

```ts
Packer.toArrayBuffer(doc).then((arrayBuffer) => {
port.postMessage(arrayBuffer, [arrayBuffer]);
});
```

### Export as a Stream

```ts
Expand All @@ -63,3 +73,13 @@ Packer.toString(doc, true, overrides).then((string) => {
console.log(string);
});
```

### Export to arbitrary formats

You can also use the lower-level `Packer.pack` method to export to any specified type.

```ts
Packer.pack(doc, 'string').then((string) => {
console.log(string);
});
```

0 comments on commit 4e2befb

Please sign in to comment.