---
title: Preview document via xPression
summary: Renders an xPression package as preview bytes, either through the fixed design-mode PDF call or through the current/supplied output profile.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-07-30
library: SAIF.Services.Printing
reference_type: package
operation_id: OP-PRT-01
trigger: Caller invokes clsPrint.previewPDF or one of the clsPrint.previewDocument overloads
---

# Preview document via xPression

`clsPrint` exposes two related preview paths that both return rendered bytes from the xPression document-generation service without printing or distributing anything: a design-mode PDF preview with a fixed application label, and a document preview that uses the object's current (or caller-supplied) output profile. Both paths share the same package-name normalization and store the caller's package/XML state on the `clsPrint` instance before calling the SOAP proxy.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-PRT-01 |
| **Trigger** | Caller invokes `previewPDF(package, xml)`, `previewDocument(package, xml)`, or `previewDocument(package, xml, outputProfile)` |
| **Inputs** | Package name, report XML payload, optional output profile name |
| **Outputs** | Rendered preview byte array from the xPression service |
| **Primary components** | `clsPrint.previewPDF`, `clsPrint.xpreviewPDF`, `clsPrint.previewDocument` (public overloads and private worker) |
| **Entry point** | `Services\SAIF.Services.Printing\clsPrint.vb` |

## Steps

1. **Design-mode PDF preview (`previewPDF`).** The caller supplies a package name and XML payload.
   - The `Package` property setter stores the value, stripping a trailing `.pkg` extension if present ([BR-007](../business-rules.md#br-007-package-name-normalization-strips-a-trailing-pkg-extension)).
   - `XML` is stored as-is.
   - The method calls the private `xpreviewPDF` wrapper with the normalized package name, the XML, and the literal application label `"xPression Design"`.
   - `xpreviewPDF` forwards the call to the generated `xpresso.clsGenerate.previewPDF` SOAP proxy and returns the resulting byte array.
2. **Document preview without an explicit profile (`previewDocument(package, xml)`).** The caller supplies a package name and XML payload.
   - `Package` and `XML` are stored the same way as step 1 ([BR-007](../business-rules.md#br-007-package-name-normalization-strips-a-trailing-pkg-extension)).
   - The public overload calls the private, parameterless `previewDocument()` worker.
3. **Document preview with an explicit profile (`previewDocument(package, xml, outputProfile)`).** The caller additionally supplies an output profile name.
   - `Package`, `XML`, and `OutputProfile` are all stored on the instance.
   - The overload then calls the same private `previewDocument()` worker used in step 2.
4. **Shared preview call.** The private `previewDocument()` worker calls `m_Xpresso.previewDocument(m_Package, m_XML, m_OutputProfile, m_Application)` on the xPression SOAP proxy and returns the byte array response.
   - `m_Application` defaults to `"xPression Design"` and `m_OutputProfile` defaults to `"PDF"` unless previously changed by the caller (for example, through `SetDefaultProfile`/`SetDraftProfile` on a `ReportBase`-derived report, see [Render report](render-report.md)).

## Process flow

The following diagram visualizes the two preview entry points converging on the xPression SOAP proxy.

```mermaid
flowchart TD
	Start([Caller supplies package and XML]) --> Norm[Normalize package name<br>strip trailing .pkg]
	Norm --> Which{Which entry point?}
	Which -->|previewPDF| Design[Call xpreviewPDF with<br>fixed 'xPression Design' label]
	Which -->|previewDocument, no profile| Doc1[Use current OutputProfile]
	Which -->|previewDocument, with profile| Doc2[Store supplied OutputProfile]
	Doc1 --> Shared[Call previewDocument worker]
	Doc2 --> Shared
	Design --> ProxyPDF[xpresso.clsGenerate.previewPDF]
	Shared --> ProxyDoc[xpresso.clsGenerate.previewDocument]
	ProxyPDF --> End([Return preview bytes])
	ProxyDoc --> End
```

## Failure and edge-case behavior

- Neither preview path catches exceptions from the SOAP proxy call; a service fault or communication failure propagates directly to the caller.*
- `previewPDF` always uses the literal application label `"xPression Design"` regardless of the `Application` property value, so callers that changed `Application` still get design-mode behavior for this specific call.
- If a package name ending in `.pkg` (any case) is supplied, the stored `Package` value silently omits the suffix; callers inspecting `clsPrint.Package` after the call see the normalized value, not their original input.

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

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with ** could not be confirmed; treat as unknown until verified.

## Sources
- `Services\SAIF.Services.Printing\clsPrint.vb`
