Search code examples
wpfsizexps

Reduce the size of XPS in WPF


I am creating an XPS Document using XPSDocumentWriter and The XPS document contains charts. Currently the file size of XPS are too big, Is there any way to reduce the size of the XPS Documents. Thanks


Solution

  • Specify CompressionOption.Maximum in the XpsDocument constructor.

    MemoryStream memoryStream = new MemoryStream();
    Package package = Package.Open(memoryStream, FileMode.OpenOrCreate, FileAccess.ReadWrite);
    string pack = "pack://temp.xps";
    PackageStore.AddPackage(new Uri(pack), package);
    XpsDocument xpsDocument = new XpsDocument(package, CompressionOption.Maximum, pack);