# Classic .doc Generation (DOC/DOC-NEW)

Use this page when you maintain legacy `DOC` or `DOC-NEW` templates.

These formats generate Word-compatible output from HTML-based template content.

They are not true binary `.doc` files.

{% hint style="info" %}
Choose [Microsoft Word (DOCX)](/sdocs/template-architecture/document-formats/docx-s-docs.md) when you need true `.docx` output and Word-native template design.
{% endhint %}

### How classic DOC generation works

`DOC` and `DOC-NEW` are legacy Word-compatible formats.

They render from the HTML created in the template editor.

That lets S-Docs turn template markup directly into a file Microsoft Word can open.

In practice, the generated file is Word-compatible rather than a true DOC binary.

That is why Word usually opens the file without issue, even when Salesforce preview behavior is inconsistent.

### Preview behavior for DOC-NEW files

Salesforce file preview does not reliably render `DOC-NEW` output.

It can display the file encoding or underlying source instead of the expected document.

This happens because Salesforce does not properly preview the MHT-style structure used for these files.

{% hint style="warning" %}
If preview shows raw content, send users a direct download link instead of the standard file preview link.
{% endhint %}

#### Use a direct download link

{% stepper %}
{% step %}

### Get the latest content version ID

Use `ContentDocument.LatestPublishedVersionId` for the generated file.
{% endstep %}

{% step %}

### Build the download path

Append `/sfc/servlet.shepherd/version/download/` to your Salesforce domain.
{% endstep %}

{% step %}

### Add the content version ID

Place the version ID at the end of the path.

The final URL downloads the file directly instead of opening preview.
{% endstep %}
{% endstepper %}

Example pattern:

```
https://your-domain.lightning.force.com/sfc/servlet.shepherd/version/download/<LatestPublishedVersionId>
```

You can use the same pattern with a `my.salesforce.com` domain if needed.

### RTF fields in DOC-NEW

`DOC-NEW` can remove the next two characters after an equals sign inside an RTF field.

This can affect normal text and URLs.

Example:

* Input: `something = something`
* Output: `something =omething`

Use this replacement to avoid the issue:

{% code title="rtf-replaceall-fix.txt" %}

```plaintext
replaceAll="= ,=XX "
```

{% endcode %}

Apply that fix in the affected RTF field.

### Add page numbers to DOC or DOC-NEW

To add page numbers like `Page 1 of 3`, place this markup in the template footer:

{% code title="doc-page-numbers.txt" overflow="wrap" %}

```html
<strong>Page <span style="mso-field-code: PAGE ">
</span> of <span style="mso-field-code: NUMPAGES "></span></strong>
```

{% endcode %}

Microsoft Word resolves those field codes when the file opens.

### Key considerations

Keep these legacy format rules in mind:

* `DOC` and `DOC-NEW` are HTML-based Word-compatible outputs
* Salesforce preview may not render `DOC-NEW` correctly
* direct download is the safest delivery pattern for `DOC-NEW`
* some legacy RTF patterns need workarounds
* page numbering works through Word field-code markup

### When to use DOCX instead

Use [Microsoft Word (DOCX)](/sdocs/template-architecture/document-formats/docx-s-docs.md) for new Word-based implementations when you need:

* true `.docx` output
* Word-native layout and styling
* clearer long-term support patterns
* fewer preview and legacy format edge cases


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.sdocs.com/sdocs/template-architecture/document-formats/other-formats/doc-doc-new-s-docs-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
