XpsDocument
OfficeIMO.Xps
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
- Method XpsDocument.Create
- Method XpsDocument.Load
Accepted by parameters 8
- Extension method XpsDocument.SaveAsImages
- Extension method XpsDocument.SaveAsImagesAsync
- Extension method XpsDocument.ToImages
- Extension method XpsDocument.ToImagesAsync
- Method XpsDocumentImageConversionExtensions.SaveAsImages
- Method XpsDocumentImageConversionExtensions.SaveAsImagesAsync
- Method XpsDocumentImageConversionExtensions.ToImages
- Method XpsDocumentImageConversionExtensions.ToImagesAsync
Methods
public XpsFixedDocument AddDocument() #Appends an empty fixed document to this sequence.
Returns
XpsFixedDocumentpublic string AddFont(byte[] fontBytes, bool obfuscate = true) #Embeds a caller-provided font and returns its absolute package URI.
Parameters
- fontBytes byte[]
- obfuscate bool = true
Returns
stringExceptions
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
- height double = 1056
- language string = "en-US"
Returns
XpsPagepublic string AddResource(string partName, byte[] bytes, string contentType) #Adds an immutable package resource. Existing parts cannot be overwritten through this API.
Parameters
- partName string
- bytes byte[]
- contentType string
Returns
stringpublic static XpsDocument Create(XpsFormat format = OpenXps) #Creates an empty native document with no external resources.
Parameters
- format OfficeIMO.Xps.XpsFormat = OpenXps
Returns
XpsDocumentpublic byte[] GetPartBytes(string partName) #Returns a copy of a retained package resource.
Parameters
- partName string
Returns
byte[]public XpsFixedDocument InsertDocument(int index) #Inserts a new empty fixed document. Existing parts and relationships are retained.
Parameters
- index int
Returns
XpsFixedDocumentpublic void InsertDocument(int index, XpsFixedDocument document) #Inserts another reference to a fixed document owned by this package, including a removed document.
Parameters
- index int
- document OfficeIMO.Xps.XpsFixedDocument
public static XpsDocument Load(string path, XpsLoadOptions? options = null, CancellationToken cancellationToken = default) #Loads from a file without retaining handles.
Parameters
- path string
- options OfficeIMO.Xps.XpsLoadOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
XpsDocumentpublic static XpsDocument Load(byte[] bytes, XpsLoadOptions? options = null, CancellationToken cancellationToken = default) #Loads from bytes with bounded package and XML expansion.
Parameters
- bytes byte[]
- options OfficeIMO.Xps.XpsLoadOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
XpsDocumentpublic 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
- options OfficeIMO.Xps.XpsLoadOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
XpsDocumentpublic void MoveDocument(int sourceIndex, int destinationIndex) #Moves one sequence reference to its final zero-based index, retaining reference attributes.
Parameters
- sourceIndex int
- destinationIndex int
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
Returns
XpsLogicalStructurepublic void RemoveDocumentAt(int index) #Removes one sequence reference, retaining its native parts, resources and relationships.
Parameters
- index int
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
- bytes byte[]
public void Save(string path, CancellationToken cancellationToken = default) #Atomically replaces a file only after successful serialization.
Parameters
- path string
- cancellationToken System.Threading.CancellationToken = default
public void Save(CancellationToken cancellationToken = default) #Saves to the associated path, failing when no destination is associated.
Parameters
- cancellationToken System.Threading.CancellationToken = default
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
- cancellationToken System.Threading.CancellationToken = default
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
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 source path or logical name.
- includeSvgPreviewAssets bool = false
- Includes self-contained page SVG assets through the strict native renderer.
- cancellationToken System.Threading.CancellationToken = default
- Cancels native structure reading and rendering.
Returns
OfficeDocumentModelInherited Methods
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
- folderPath string
- options OfficeIMO.Drawing.OfficeImageExportOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
OfficeConversionReportpublic 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
- folderPath string
- options OfficeIMO.Drawing.OfficeImageExportOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
Task<OfficeConversionReport>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
- options OfficeIMO.Drawing.OfficeImageExportOptions? = null
- cancellationToken System.Threading.CancellationToken = default
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
- consumer OfficeIMO.Drawing.OfficeImageExportConsumer
- options OfficeIMO.Drawing.OfficeImageExportOptions? = null
- cancellationToken System.Threading.CancellationToken = default
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
- options OfficeIMO.Drawing.OfficeImageExportOptions? = null
- cancellationToken System.Threading.CancellationToken = default
Returns
Task<IReadOnlyList<OfficeImageExportResult>>