Skip to content

Commit

Permalink
Update Packer usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
adamSherwoodGenieAI committed Jan 22, 2025
1 parent c2560c9 commit e53209f
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 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` or `base64 string`. 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`, 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 All @@ -14,6 +14,14 @@ Packer.toBuffer(doc).then((buffer) => {
});
```

### Export as string

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

### Export as a `base64` string

```ts
Expand All @@ -32,3 +40,26 @@ Packer.toBlob(doc).then((blob) => {
saveAs(blob, "example.docx");
});
```

### Export as a Stream

```ts
Packer.toStream(doc).then((stream) => {
// read from stream
});
```

### Export using optional arguments

The `Packer` methods support 2 optional arguments.

The first is for controlling the indentation of the xml and should be a `boolean` or `keyof typeof PrettifyType`.

The second is an array of subfile overrides (`{path: string, data: string}[]`). These overrides can be used to write additional subfiles to the result or even override default subfiles in the case that the default handling of these subfiles does not meet your needs.

```ts
const overrides = [{ path: "word/commentsExtended.xml", data: "string_data" }];
Packer.toString(doc, true, overrides).then((string) => {
console.log(string);
});
```

0 comments on commit e53209f

Please sign in to comment.