Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

XpsDocument

OfficeIMO.Xps

Namespace
OfficeIMO.Xps
Assembly
OfficeIMO.Xps
Source revision
0eef6a5756b9 with working tree changes
Modifiers
sealed

A portable XPS/OpenXPS document sequence. Retains unmodified native package parts.

Inheritance

  • object
  • XpsDocument

Usage

Explore 10 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Returned or exposed by 2

Accepted by parameters 8

Methods

public XpsFixedDocument AddDocument() #

Appends an empty fixed document to this sequence.

public string AddFont(byte[] fontBytes, bool obfuscate = true) #

Embeds a caller-provided font and returns its absolute package URI.

Parameters

fontBytes byte[] required
obfuscate bool = true optional

Returns

string

Exceptions

  • ArgumentException – The data is too short to be a font, or its embedding permission forbids embedding it.
public XpsPage AddPage(double width = 816, double height = 1056, string language = "en-US") #

Appends a page to the last fixed document, creating one when the sequence is empty. Dimensions use 1/96-inch units.

Parameters

width double = 816 optional
height double = 1056 optional
language string = "en-US" optional

Returns

XpsPage
public string AddResource(string partName, byte[] bytes, string contentType) #

Adds an immutable package resource. Existing parts cannot be overwritten through this API.

Parameters

partName string required
bytes byte[] required
contentType string required

Returns

string
public static XpsDocument Create(XpsFormat format = OpenXps) #

Creates an empty native document with no external resources.

Parameters

format OfficeIMO.Xps.XpsFormat = OpenXps optional
public byte[] GetPartBytes(string partName) #

Returns a copy of a retained package resource.

Parameters

partName string required

Returns

byte[]
InsertDocument 2 overloads
public XpsFixedDocument InsertDocument(int index) #

Inserts a new empty fixed document. Existing parts and relationships are retained.

Parameters

index int required
public void InsertDocument(int index, XpsFixedDocument document) #

Inserts another reference to a fixed document owned by this package, including a removed document.

Parameters

index int required
document OfficeIMO.Xps.XpsFixedDocument required
Load 3 overloads
public static XpsDocument Load(string path, XpsLoadOptions? options = null, CancellationToken cancellationToken = default) #

Loads from a file without retaining handles.

Parameters

path string required
options OfficeIMO.Xps.XpsLoadOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional
public static XpsDocument Load(byte[] bytes, XpsLoadOptions? options = null, CancellationToken cancellationToken = default) #

Loads from bytes with bounded package and XML expansion.

Parameters

bytes byte[] required
options OfficeIMO.Xps.XpsLoadOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional
public static XpsDocument Load(Stream stream, XpsLoadOptions? options = null, CancellationToken cancellationToken = default) #

Reads from the current position to EOF. The caller's stream remains open; non-seekable streams are supported.

Parameters

stream System.IO.Stream required
options OfficeIMO.Xps.XpsLoadOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional
public void MoveDocument(int sourceIndex, int destinationIndex) #

Moves one sequence reference to its final zero-based index, retaining reference attributes.

Parameters

sourceIndex int required
destinationIndex int required
public XpsLogicalStructure ReadLogicalStructure(CancellationToken cancellationToken = default) #

Reconstructs native stories in DocumentStructure reference order, merging continued paragraphs, lists and tables.

Parameters

cancellationToken System.Threading.CancellationToken = default optional
public void RemoveDocumentAt(int index) #

Removes one sequence reference, retaining its native parts, resources and relationships.

Parameters

index int required
public void ReplaceResource(string partName, byte[] bytes) #

Replaces an existing resource's encoded bytes, retaining its URI and content type. All references see the replacement.

Parameters

partName string required
bytes byte[] required
Save 3 overloads
public void Save(string path, CancellationToken cancellationToken = default) #

Atomically replaces a file only after successful serialization.

Parameters

path string required
cancellationToken System.Threading.CancellationToken = default optional
public void Save(CancellationToken cancellationToken = default) #

Saves to the associated path, failing when no destination is associated.

Parameters

cancellationToken System.Threading.CancellationToken = default optional
public void Save(Stream stream, CancellationToken cancellationToken = default) #

Writes a ZIP package to a writable stream, leaving it open. Use a fresh/empty stream.

Parameters

stream System.IO.Stream required
cancellationToken System.Threading.CancellationToken = default optional
public byte[] ToBytes(CancellationToken cancellationToken = default) #

Serializes the same dialect. Unknown native parts are retained; signed packages cannot be rewritten.

Parameters

cancellationToken System.Threading.CancellationToken = default optional

Returns

byte[]
public OfficeDocumentModel ToOfficeDocumentModel(string? sourceName = null, bool includeSvgPreviewAssets = false, CancellationToken cancellationToken = default) #

Projects literal Unicode, native reading order and semantic structure into the shared document model.

Parameters

sourceName string? = null optional
Optional source path or logical name.
includeSvgPreviewAssets bool = false optional
Includes self-contained page SVG assets through the strict native renderer.
cancellationToken System.Threading.CancellationToken = default optional
Cancels native structure reading and rendering.

Returns

OfficeDocumentModel

Properties

public string? FilePath { get; } #

Gets the associated path, or null for an in-memory document.

public XpsFormat Format { get; } #

The markup dialect detected from the package relationship and sequence.

public IReadOnlyList<XpsPage> Pages { get; } #

Pages in document-sequence order. Repeated references share one editable native page.

public IReadOnlyCollection<string> PartNames { get; } #

Names of retained package parts, without a leading slash.

public XNamespace StructureNamespace { get; } #

The native DocumentStructure/StoryFragments namespace for this document's dialect.

public IReadOnlyList<XpsFixedDocument> Documents { get; } #

Fixed documents in sequence order. Repeated references share the same editable document.

Extension Methods

public static OfficeConversionReport SaveAsImages(XpsDocument document, string folderPath, OfficeImageExportOptions? options = null, CancellationToken cancellationToken = default) #

Saves selected pages with atomic files, bounded output and fidelity acceptance.

Parameters

document OfficeIMO.Xps.XpsDocument required
folderPath string required
options OfficeIMO.Drawing.OfficeImageExportOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

OfficeConversionReport
public static async Task<OfficeConversionReport> SaveAsImagesAsync(XpsDocument document, string folderPath, OfficeImageExportOptions? options = null, CancellationToken cancellationToken = default) #

Saves selected pages asynchronously without retaining completed image payloads.

Parameters

document OfficeIMO.Xps.XpsDocument required
folderPath string required
options OfficeIMO.Drawing.OfficeImageExportOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

Task<OfficeConversionReport>
ToImages 2 overloads
public static IReadOnlyList<OfficeImageExportResult> ToImages(XpsDocument document, OfficeImageExportOptions? options = null, CancellationToken cancellationToken = default) #

Renders selected source pages in caller order, retaining source and encoding diagnostics.

Parameters

document OfficeIMO.Xps.XpsDocument required
options OfficeIMO.Drawing.OfficeImageExportOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

IReadOnlyList<OfficeImageExportResult>
public static void ToImages(XpsDocument document, OfficeImageExportConsumer consumer, OfficeImageExportOptions? options = null, CancellationToken cancellationToken = default) #

Streams selected images without retaining earlier encoded payloads.

Parameters

document OfficeIMO.Xps.XpsDocument required
consumer OfficeIMO.Drawing.OfficeImageExportConsumer required
options OfficeIMO.Drawing.OfficeImageExportOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional
public static Task<IReadOnlyList<OfficeImageExportResult>> ToImagesAsync(XpsDocument document, OfficeImageExportOptions? options = null, CancellationToken cancellationToken = default) #

Renders selected source pages asynchronously with shared cancellation and deadlines.

Parameters

document OfficeIMO.Xps.XpsDocument required
options OfficeIMO.Drawing.OfficeImageExportOptions? = null optional
cancellationToken System.Threading.CancellationToken = default optional

Returns

Task<IReadOnlyList<OfficeImageExportResult>>