---
title: Document generation, preview, distribution and print
summary: Preview, categorize, distribute, or print documents through the xPression Design document service.
status: draft
owner: SAIF.Core Documentation Team
last_reviewed: 2026-09-24
library: SAIF.Services.Web.Proxies
reference_type: package
operation_id: OP-WP-02
trigger: SAIF.Services.Utilities.Documents.DocumentService, or package consumers
---

# Document generation, preview, distribution and print

`DocumentServiceProxy` wraps the Document SOAP service (`clsGenerateSoapClient`) to preview a PDF, list categories/packages, and distribute or print a document package, mapping SAIF.Core document, mail, and fax contract types to the wire types on every call.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-WP-02 |
| **Trigger** | `SAIF.Services.Utilities.Documents.DocumentService` (constructed at `DocumentService.cs:35`), or package consumers |
| **Inputs** | Package/profile/category names; `DocumentGenerationConfig`; `MailMessage`; `FaxInfoClass`; `DeferredPrintConfig`; `PrintConfig` |
| **Outputs** | PDF bytes, sorted category/package arrays, or a distribution/print side effect |
| **Primary components** | `DocumentServiceProxy.PreviewPdf`, `GetCategories`, `GetPackages`, `DistributeDocument`, `DistributeDocumentDocCenter`, `PrintDocument` |
| **Entry point** | `Services/SAIF.Services.Web.Proxies/DocumentServiceProxy.cs` |

## Steps

1. Construct `DocumentServiceProxy(serviceUrl)`: guard `serviceUrl` ([WP-BR-001](../business-rules.md#wp-br-001-required-arguments-must-be-non-null-or-non-empty)), then build a `BasicHttpBinding` with `MaxReceivedMessageSize` and `MaxArrayLength` set to `int.MaxValue`.
2. **`PreviewPdf(package, xml, profile)`:** guard `package` and `xml` are not null/whitespace ([WP-BR-001](../business-rules.md#wp-br-001-required-arguments-must-be-non-null-or-non-empty)), then call wire `previewDocument(package, xml, profile, inApplication: "xPression Design")` ([WP-BR-004](../business-rules.md#wp-br-004-document-calls-identify-as-xpression-design)) and return the PDF bytes.
3. **`GetCategories()`:** call wire `categoriesForUser(ref "xPression Design")` and return the categories sorted ascending ([WP-BR-005](../business-rules.md#wp-br-005-document-categories-and-packages-are-sorted-ascending)).
4. **`GetPackages(category)`:** call wire `documentsForCategory(ref category, ref "xPression Design")` and return the result sorted ascending ([WP-BR-005](../business-rules.md#wp-br-005-document-categories-and-packages-are-sorted-ascending)).
5. **`DistributeDocument(docConfig, printer, copies, plexMode, scaleMode, paperTray, imageImportSettings, mailMessage, faxInfo, deferredPrintConfig, imagePath)`:**
   1. Guard `docConfig`.
   2. Map `PlexMode`, `ScaleMode`, and `PaperTray` by name via `Helpers.MapEnumByName` ([WP-BR-006](../business-rules.md#wp-br-006-plex-scale-and-paper-tray-enums-map-by-name)).
      - On failure: an unmatched enum name throws `ArgumentNullException`.
   3. Map `MailMessage` to `EmailInfoClass`, setting `BCC`/`CC` only when non-empty; a null message produces a null result ([WP-BR-007](../business-rules.md#wp-br-007-email-cc-and-bcc-are-sent-only-when-present)).
   4. Map `DeferredPrintConfig` to `DeferredPrintInfoClass`, copying `SortField0`–`SortField9` into `Sort0Value`–`Sort9Value`; a null config produces null.
   5. Call wire `distributeDocument(inPackage, inXML, inPrinter, inMode, inCopies, inScaleMode, inOutputProfile, inImportInfo, inEmailInfo, inFaxInfo, inIDMPath, inTray, inDeferredInfo, inApplication)` with `docConfig.OutputProfile`, fax info forced to null ([WP-BR-008](../business-rules.md#wp-br-008-standard-distribution-never-sends-fax-info)), and application `"xPression Design"`.
      - Note: the `faxInfo` string parameter is ignored; it is suppressed via CA1801.
6. **`DistributeDocumentDocCenter(docConfig, printer, copies, plexMode, scaleMode, paperTray, imageImportSettings, mailMessage, faxInfo, deferredPrintConfig, imagePath)`:** the same mapping as step 5, with these differences:
   - Uses `docConfig.OutputProfileOverride`.
   - Maps `FaxInfoClass` to the wire `FaxInfoClass` only when `ToFaxNumber` is non-empty; otherwise fax is null ([WP-BR-009](../business-rules.md#wp-br-009-doccenter-distribution-sends-fax-info-only-when-present)).
   - Uses `docConfig.ApplicationName` when set, falling back to `"xPression Design"` ([WP-BR-004](../business-rules.md#wp-br-004-document-calls-identify-as-xpression-design)).
   - On failure: a null `faxInfo` argument throws `NullReferenceException`, because `MapFaxMessage` dereferences it without a guard.
7. **`PrintDocument(docConfig, printConfig)`:** guard both arguments, then call wire `distributeDocument` with the printer, plex, copies, scale, and tray taken from `printConfig`, `docConfig.OutputProfile`, empty import info and IDM path, null email/fax/deferred info, and application `"xPression Design"`.

## Process flow

The following diagram visualizes the branch between preview/catalog reads and the distribution/print write path.

```mermaid
flowchart TD
	Start([Caller invokes wrapper method]) --> Which{Which method?}
	Which -->|PreviewPdf| Guard1[Guard package/xml] --> Preview[Call previewDocument] --> RetPdf([Return PDF bytes])
	Which -->|GetCategories/GetPackages| Cat[Call wire operation] --> Sort["Sort result ascending"] --> RetSorted([Return sorted array])
	Which -->|Distribute or Print| MapEnums["Map Plex/Scale/Tray by name"] --> MapMail["Map MailMessage,<br>DeferredPrintConfig, FaxInfoClass"] --> Dist[Call distributeDocument] --> RetDist([Distribution side effect])
```

## Failure and edge-case behavior

- A null/whitespace `package`, `xml`, or `serviceUrl` throws an argument exception before the wire call.
- An unmatched enum name in `Helpers.MapEnumByName` throws `ArgumentNullException`.
- `DistributeDocumentDocCenter` throws `NullReferenceException` on a null `faxInfo` argument.
- `DistributeDocument`'s `faxInfo` string parameter is always ignored, which is a documented parameter-mismatch finding rather than a defect in this operation's contract.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

## Sources
- `Services/SAIF.Services.Web.Proxies/DocumentServiceProxy.cs`
- `Services/SAIF.Services.Web.Proxies/Helpers.cs`
