public void ExportExactPages()
        {
            //ExStart
            //ExFor:FixedPageSaveOptions.PageSet
            //ExFor:PageSet.#ctor(int[])
            //ExSummary:Shows how to extract pages based on exact page indices.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Add five pages to the document.
            for (int i = 1; i < 6; i++)
            {
                builder.Write("Page " + i);
                builder.InsertBreak(BreakType.PageBreak);
            }

            // Create an "XpsSaveOptions" object, which we can pass to the document's "Save" method
            // to modify how that method converts the document to .XPS.
            XpsSaveOptions xpsOptions = new XpsSaveOptions();

            // Use the "PageSet" property to select a set of the document's pages to save to output XPS.
            // In this case, we will choose, via a zero-based index, only three pages: page 1, page 2, and page 4.
            xpsOptions.PageSet = new PageSet(0, 1, 3);

            doc.Save(ArtifactsDir + "XpsSaveOptions.ExportExactPages.xps", xpsOptions);
            //ExEnd
        }
Exemple #2
0
        public void CheckThatAllMethodsArePresent()
        {
            HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions();

            htmlFixedSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback();

            ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.Png);

            imageSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback();

            PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();

            pdfSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback();

            PsSaveOptions psSaveOptions = new PsSaveOptions();

            psSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback();

            SvgSaveOptions svgSaveOptions = new SvgSaveOptions();

            svgSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback();

            XamlFixedSaveOptions xamlFixedSaveOptions = new XamlFixedSaveOptions();

            xamlFixedSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback();

            XpsSaveOptions xpsSaveOptions = new XpsSaveOptions();

            xpsSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback();
        }
        public void CheckThatAllMethodsArePresent()
        {
            HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions();
            htmlFixedSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback();

            ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.Png);
            imageSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback();

            PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
            pdfSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback();

            PsSaveOptions psSaveOptions = new PsSaveOptions();
            psSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback();

            SvgSaveOptions svgSaveOptions = new SvgSaveOptions();
            svgSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback();

            SwfSaveOptions swfSaveOptions = new SwfSaveOptions();
            swfSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback();

            XamlFixedSaveOptions xamlFixedSaveOptions = new XamlFixedSaveOptions();
            xamlFixedSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback();

            XpsSaveOptions xpsSaveOptions = new XpsSaveOptions();
            xpsSaveOptions.PageSavingCallback = new CustomPageFileNamePageSavingCallback();
        }
Exemple #4
0
        public void OptimizeOutput(bool optimizeOutput)
        {
            //ExStart
            //ExFor:FixedPageSaveOptions.OptimizeOutput
            //ExSummary:Shows how to optimize document objects while saving to xps.
            Document doc = new Document(MyDir + "Unoptimized document.docx");

            // When saving to .xps, we can use SaveOptions to optimize the output in some cases
            XpsSaveOptions saveOptions = new XpsSaveOptions {
                OptimizeOutput = optimizeOutput
            };

            doc.Save(ArtifactsDir + "XpsSaveOptions.OptimizeOutput.xps", saveOptions);

            // The input document had adjacent runs with the same formatting, which, if output optimization was enabled,
            // have been combined to save space
            FileInfo outFileInfo = new FileInfo(ArtifactsDir + "XpsSaveOptions.OptimizeOutput.xps");

            if (optimizeOutput)
            {
                Assert.True(outFileInfo.Length < 45000);
            }
            else
            {
                Assert.True(outFileInfo.Length > 60000);
            }
            //ExEnd

            TestUtil.DocPackageFileContainsString(
                optimizeOutput
                    ? "Glyphs OriginX=\"34.294998169\" OriginY=\"10.31799984\" " +
                "UnicodeString=\"This document contains complex content which can be optimized to save space when \""
                    : "<Glyphs OriginX=\"34.294998169\" OriginY=\"10.31799984\" UnicodeString=\"This\"",
                ArtifactsDir + "XpsSaveOptions.OptimizeOutput.xps", "1.fpage");
        }
        public void BookFold(bool renderTextAsBookFold)
        {
            //ExStart
            //ExFor:XpsSaveOptions.#ctor(SaveFormat)
            //ExFor:XpsSaveOptions.UseBookFoldPrintingSettings
            //ExSummary:Shows how to save a document to the XPS format in the form of a book fold.
            Document doc = new Document(MyDir + "Paragraphs.docx");

            // Create an "XpsSaveOptions" object which we can pass to the document's "Save" method
            // to modify the way in which that method converts the document to .XPS.
            XpsSaveOptions xpsOptions = new XpsSaveOptions(SaveFormat.Xps);

            // Set the "UseBookFoldPrintingSettings" property to "true" to arrange the contents
            // in the output XPS in a way that helps us use it to make a booklet.
            // Set the "UseBookFoldPrintingSettings" property to "false" to render the XPS normally.
            xpsOptions.UseBookFoldPrintingSettings = renderTextAsBookFold;

            // If we are rendering the document as a booklet, we must set the "MultiplePages"
            // properties of all page setup objects of all sections to "MultiplePagesType.BookFoldPrinting".
            if (renderTextAsBookFold)
            {
                foreach (Section s in doc.Sections)
                {
                    s.PageSetup.MultiplePages = MultiplePagesType.BookFoldPrinting;
                }
            }

            // Once we print this document, we can turn it into a booklet by stacking the pages
            // in the order they come out of the printer and then folding down the middle
            doc.Save(ArtifactsDir + "XpsSaveOptions.BookFold.xps", xpsOptions);
            //ExEnd
        }
        public void ConvertMDtoXPSWithXpsSaveOptionsTest()
        {
            // Prepare a path to a source Markdown file
            string sourcePath = Path.Combine(DataDir, "nature.md");

            // Prepare a path for converted PDF file saving
            string savePath = Path.Combine(OutputDir, "nature-output.xps");

            // Convert Markdown to HTML
            using var document = Converter.ConvertMarkdown(sourcePath);

            // Initialize XpsSaveOptions. Set up the resilutions, page-size, margins and change the background color to AntiqueWhite
            var options = new XpsSaveOptions()
            {
                HorizontalResolution = 200,
                VerticalResolution   = 200,
                BackgroundColor      = Color.AntiqueWhite
            };

            options.PageSetup.AnyPage = new Page(new Aspose.Html.Drawing.Size(Length.FromInches(5.0f), Length.FromInches(10.0f)), new Margin(30, 20, 10, 10));

            // Convert HTML to XPS file format
            Converter.ConvertHTML(document, options, savePath);

            Assert.True(File.Exists(savePath));
        }
        public void OptimizeOutput(bool optimizeOutput)
        {
            //ExStart
            //ExFor:FixedPageSaveOptions.OptimizeOutput
            //ExSummary:Shows how to optimize document objects while saving to xps.
            Document doc = new Document(MyDir + "Unoptimized document.docx");

            // When saving to .xps, we can use SaveOptions to optimize the output in some cases
            XpsSaveOptions saveOptions = new XpsSaveOptions {
                OptimizeOutput = optimizeOutput
            };

            doc.Save(ArtifactsDir + "XpsSaveOptions.OptimizeOutput.xps", saveOptions);

            // The input document had adjacent runs with the same formatting, which, if output optimization was enabled,
            // have been combined to save space
            FileInfo outFileInfo = new FileInfo(ArtifactsDir + "XpsSaveOptions.OptimizeOutput.xps");

            if (optimizeOutput)
            {
                Assert.True(outFileInfo.Length < 45000);
            }
            else
            {
                Assert.True(outFileInfo.Length > 60000);
            }
            //ExEnd
        }
        public void SaveAsXps()
        {
            //ExStart
            //ExFor:XpsSaveOptions
            //ExFor:XpsSaveOptions.#ctor
            //ExFor:Document.Save(String)
            //ExFor:Document.Save(Stream, SaveFormat)
            //ExFor:Document.Save(String, SaveOptions)
            //ExId:SaveToXps_NewAPI
            //ExSummary:Shows how to save a document to the Xps format using the Save method and the XpsSaveOptions class.
            // Open the document
            Document doc = new Document(MyDir + "Rendering.doc");

            // Save document to file in the Xps format with default options
            doc.Save(MyDir + @"\Artifacts\Rendering.XpsDefaultOptions.xps");

            // Save document to stream in the Xps format with default options
            MemoryStream docStream = new MemoryStream();

            doc.Save(docStream, SaveFormat.Xps);
            // Rewind the stream position back to the beginning, ready for use
            docStream.Seek(0, SeekOrigin.Begin);

            // Save document to file in the Xps format with specified options
            // Render the first page only
            XpsSaveOptions xpsOptions = new XpsSaveOptions();

            xpsOptions.PageIndex = 0;
            xpsOptions.PageCount = 1;
            doc.Save(MyDir + @"\Artifacts\Rendering.XpsCustomOptions.xps", xpsOptions);
            //ExEnd
        }
        public void EPUBtoXPSWithXpsSaveOptionsTest()
        {
            // Open an existing EPUB file for reading
            using var stream = File.OpenRead(DataDir + "input.epub");

            // Prepare a path to save the converted file
            string savePath = Path.Combine(OutputDir, "input-options.xps");

            // Create an instance of XpsSaveOptions. Set up the page-size and change the background color to LightGray
            var options = new XpsSaveOptions()
            {
                PageSetup =
                {
                    AnyPage  = new Page()
                    {
                        Size = new Aspose.Html.Drawing.Size(Length.FromPixels(500), Length.FromPixels(500))
                    }
                },
                BackgroundColor = Color.LightGray
            };

            // Call the ConvertEPUB method to convert EPUB to XPS
            Converter.ConvertEPUB(stream, options, savePath);

            Assert.True(File.Exists(savePath));
        }
        public void SpecifyXpsSaveOptionsTest()
        {
            string documentPath = Path.Combine(OutputDir, "save-options.html");
            string savePath     = Path.Combine(OutputDir, "save-options-output.xps");

            // Prepare HTML code and save it to a file
            var code = "<h1>  XpsSaveOptions Class</h1>\r\n" +
                       "<p>Using XpsSaveOptions Class, you can programmatically apply a wide range of conversion parameters such as BackgroundColor, PageSetup, etc.</p>\r\n";

            File.WriteAllText(documentPath, code);

            // Initialize an HTML Document from the html file
            using var document = new HTMLDocument(documentPath);

            // Set up the page-size, margins and change the background color to AntiqueWhite
            var options = new XpsSaveOptions()
            {
                BackgroundColor = Color.AntiqueWhite
            };

            options.PageSetup.AnyPage = new Page(new Aspose.Html.Drawing.Size(Length.FromInches(4.9f), Length.FromInches(3.5f)), new Margin(30, 20, 10, 10));

            // Convert HTML to XPS
            Converter.ConvertHTML(document, options, savePath);

            Assert.True(File.Exists(savePath));
        }
        public void SVGtoXPSWithXpsSaveOptionsTest()
        {
            // Prepare a path to a source SVG file
            string documentPath = Path.Combine(DataDir, "aspose.svg");

            // Prepare a path for converted file saving
            string savePath = Path.Combine(OutputDir, "aspose-options.xps");

            // Initialize an SVG document from the file
            using var document = new SVGDocument(documentPath);

            // Initialize XpsSaveOptions. Set up the page-size 500x500 pixels, margins, resolutions and change the background color to AliceBlue
            var options = new XpsSaveOptions()
            {
                HorizontalResolution = 200,
                VerticalResolution   = 200,
                BackgroundColor      = Color.AliceBlue
            };

            options.PageSetup.AnyPage = new Page(new Aspose.Html.Drawing.Size(500, 500), new Margin(30, 10, 10, 10));

            // Convert SVG to XPS
            Converter.ConvertSVG(document, options, savePath);

            Assert.True(File.Exists(Path.Combine(OutputDir, "aspose-options.xps")));
        }
        public void OptimizeOutput()
        {
            Document doc = new Document(MyDir + "XPSOutputOptimize.docx");

            XpsSaveOptions saveOptions = new XpsSaveOptions();
            saveOptions.OptimizeOutput = true;

            doc.Save(MyDir + @"\Artifacts\XPSOutputOptimize.docx");
        }
Exemple #13
0
        public void OptimizeOutput()
        {
            Document doc = new Document(MyDir + "XPSOutputOptimize.docx");

            XpsSaveOptions saveOptions = new XpsSaveOptions();

            saveOptions.OptimizeOutput = true;

            doc.Save(MyDir + @"\Artifacts\XPSOutputOptimize.docx");
        }
Exemple #14
0
        public void OptimizeOutput()
        {
            //ExStart
            //ExFor:FixedPageSaveOptions.OptimizeOutput
            //ExSummary:Shows how to optimize document objects while saving to xps.
            Document doc = new Document(MyDir + "XPSOutputOptimize.docx");

            XpsSaveOptions saveOptions = new XpsSaveOptions {
                OptimizeOutput = true
            };

            doc.Save(ArtifactsDir + "XPSOutputOptimize.xps", saveOptions);
            //ExEnd
        }
        public void ExportExactPages()
        {
            //ExStart
            //ExFor:FixedPageSaveOptions.PageSet
            //ExFor:PageSet.#ctor(int[])
            //ExSummary:Shows how to extract pages based on exact page indices.
            Document doc = new Document(MyDir + "Images.docx");

            XpsSaveOptions xpsOptions = new XpsSaveOptions();

            xpsOptions.PageSet = new PageSet(0, 1, 2, 4, 1, 3, 2, 3);

            doc.Save(ArtifactsDir + "XpsSaveOptions.ExportExactPages.xps", xpsOptions);
            //ExEnd
        }
        public void ConvertEPUBToXPSTest()
        {
            // Open an existing EPUB file for reading
            using var stream = File.OpenRead(DataDir + "input.epub");

            // Prepare a path to save the converted file
            string savePath = Path.Combine(OutputDir, "input-output.xps");

            // Create an instance of XpsSaveOptions
            var options = new XpsSaveOptions();

            // Call the ConvertEPUB method to convert EPUB to XPS
            Converter.ConvertEPUB(stream, options, savePath);

            Assert.True(File.Exists(savePath));
        }
Exemple #17
0
        public void ConvertMHTMLToXPSTest()
        {
            // Open an existing MHTML file for reading
            using var stream = File.OpenRead(DataDir + "sample.mht");

            // Prepare a path for converted file saving
            string savePath = Path.Combine(OutputDir, "sample-output.xps");

            // Create an instance of XpsSaveOptions
            var options = new XpsSaveOptions();

            // Call the ConvertMHTML method to convert MHTML to XPS
            Converter.ConvertMHTML(stream, options, savePath);

            Assert.True(File.Exists(savePath));
        }
        public void ConvertSVGtoXPSTest()
        {
            // Prepare SVG code
            var code = "<svg xmlns='http://www.w3.org/2000/svg'>" +
                       "<circle cx ='100' cy ='100' r ='60' fill='none' stroke='red' stroke-width='10' />" +
                       "</svg>";

            // Prepare a path for converted file saving
            string savePath = Path.Combine(OutputDir, "circle.xps");

            // Initialize XpsSaveOptions
            var options = new XpsSaveOptions();

            // Convert SVG to XPS
            Converter.ConvertSVG(code, ".", options, savePath);

            Assert.True(File.Exists(Path.Combine(OutputDir, "circle.xps")));
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory
            string dataDir = RunExamples.GetDataDir_Data();
            // Source EPUUB document
            FileStream fileStream = File.OpenRead(dataDir + "sample.mht");
            // Initialize XpsSaveOptions
            XpsSaveOptions options = new XpsSaveOptions()
            {
                BackgroundColor = System.Drawing.Color.Cyan
            };
            // Output file path
            string outputFile = dataDir + "MHTMLtoXPS_Output.xps";

            // Convert MHTML to XPS
            Converter.ConvertMHTML(fileStream, options, outputFile);
            // ExEnd:1
        }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory
            string dataDir = RunExamples.GetDataDir_Data();
            // Source SVG document
            SVGDocument svgDocument = new SVGDocument(dataDir + "input.svg");
            // Initialize XpsSaveOptions
            XpsSaveOptions options = new XpsSaveOptions()
            {
                BackgroundColor = System.Drawing.Color.Cyan
            };
            // Output file path
            string outputFile = dataDir + "SVGtoXPS_Output.xps";

            // Convert SVG to XPS
            Converter.ConvertSVG(svgDocument, options, outputFile);
            // ExEnd:1
        }
        public void OutlineLevels()
        {
            //ExStart
            //ExFor:XpsSaveOptions
            //ExFor:XpsSaveOptions.#ctor
            //ExFor:XpsSaveOptions.OutlineOptions
            //ExFor:XpsSaveOptions.SaveFormat
            //ExSummary:Shows how to limit the level of headings that will appear in the outline of a saved XPS document.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Insert headings that can serve as TOC entries of levels 1, 2, and then 3.
            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;

            Assert.True(builder.ParagraphFormat.IsHeading);

            builder.Writeln("Heading 1");

            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;

            builder.Writeln("Heading 1.1");
            builder.Writeln("Heading 1.2");

            builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading3;

            builder.Writeln("Heading 1.2.1");
            builder.Writeln("Heading 1.2.2");

            // Create an "XpsSaveOptions" object which we can pass to the document's "Save" method
            // to modify the way in which that method converts the document to .XPS.
            XpsSaveOptions saveOptions = new XpsSaveOptions();

            Assert.AreEqual(SaveFormat.Xps, saveOptions.SaveFormat);

            // The output XPS document will contain an outline, which is a table of contents that lists headings in the document body.
            // Clicking on an entry in this outline will take us to the location of its respective heading.
            // Set the "HeadingsOutlineLevels" property to "2" to exclude all headings whose levels are above 2 from the outline.
            // The last two headings we have inserted above will not appear.
            saveOptions.OutlineOptions.HeadingsOutlineLevels = 2;

            doc.Save(ArtifactsDir + "XpsSaveOptions.OutlineLevels.xps", saveOptions);
            //ExEnd
        }
        public void ConvertHTMLtoXPSTest()
        {
            // Prepare a path to a source HTML file
            string documentPath = Path.Combine(DataDir, "canvas.html");

            // Prepare a path for converted file saving
            string savePath = Path.Combine(OutputDir, "canvas-output.xps");

            // Initialize an HTML document from the file
            using var document = new HTMLDocument(documentPath);

            // Initialize XpsSaveOptions
            var options = new XpsSaveOptions();

            // Convert HTML to XPS
            Converter.ConvertHTML(document, options, savePath);

            Assert.True(File.Exists(savePath));
        }
Exemple #23
0
        public void MHTMLtoXPSWithXpsSaveOptionsTest()
        {
            // Open an existing MHTML file for reading
            using var stream = File.OpenRead(DataDir + "sample.mht");

            // Prepare a path for converted file saving
            string savePath = Path.Combine(OutputDir, "sample-options.xps");

            // Create an instance of XpsSaveOptions. Set up the page-size and change the background color to AliceBlue
            var options = new XpsSaveOptions();

            options.PageSetup.AnyPage = new Page(new Aspose.Html.Drawing.Size(Length.FromInches(8.3f), Length.FromInches(5.8f)));
            options.BackgroundColor   = Color.AliceBlue;

            // Call the ConvertMHTML method to convert MHTML to XPS
            Converter.ConvertMHTML(stream, options, savePath);

            Assert.True(File.Exists(savePath));
        }
        private static SaveOptions AddBookmarkSaveOptions(SaveFormat saveFormat)
        {
            PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
            XpsSaveOptions xpsSaveOptions = new XpsSaveOptions();
            SwfSaveOptions swfSaveOptions = new SwfSaveOptions();

            switch (saveFormat)
            {
            case SaveFormat.Pdf:

                //Add bookmarks to the document
                pdfSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("My Bookmark", 1);
                pdfSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Nested Bookmark", 2);
                pdfSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Bookmark_WithoutWhiteSpaces", 3);

                return(pdfSaveOptions);

            case SaveFormat.Xps:

                //Add bookmarks to the document
                xpsSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("My Bookmark", 1);
                xpsSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Nested Bookmark", 2);
                xpsSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Bookmark_WithoutWhiteSpaces", 3);

                return(xpsSaveOptions);

            case SaveFormat.Swf:

                //Add bookmarks to the document
                swfSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("My Bookmark", 1);
                swfSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Nested Bookmark", 2);
                swfSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Bookmark_WithoutWhiteSpaces", 3);

                return(swfSaveOptions);
            }

            return(null);
        }
        public void OptimizeOutput(bool optimizeOutput)
        {
            //ExStart
            //ExFor:FixedPageSaveOptions.OptimizeOutput
            //ExSummary:Shows how to optimize document objects while saving to xps.
            Document doc = new Document(MyDir + "Unoptimized document.docx");

            // Create an "XpsSaveOptions" object to pass to the document's "Save" method
            // to modify how that method converts the document to .XPS.
            XpsSaveOptions saveOptions = new XpsSaveOptions();

            // Set the "OptimizeOutput" property to "true" to take measures such as removing nested or empty canvases
            // and concatenating adjacent runs with identical formatting to optimize the output document's content.
            // This may affect the appearance of the document.
            // Set the "OptimizeOutput" property to "false" to save the document normally.
            saveOptions.OptimizeOutput = optimizeOutput;

            doc.Save(ArtifactsDir + "XpsSaveOptions.OptimizeOutput.xps", saveOptions);
            //ExEnd

            FileInfo outFileInfo = new FileInfo(ArtifactsDir + "XpsSaveOptions.OptimizeOutput.xps");

            if (optimizeOutput)
            {
                Assert.That(50000, Is.AtLeast(outFileInfo.Length));
            }
            else
            {
                Assert.That(60000, Is.LessThan(outFileInfo.Length));
            }

            TestUtil.DocPackageFileContainsString(
                optimizeOutput
                    ? "Glyphs OriginX=\"34.294998169\" OriginY=\"10.31799984\" " +
                "UnicodeString=\"This document contains complex content which can be optimized to save space when \""
                    : "<Glyphs OriginX=\"34.294998169\" OriginY=\"10.31799984\" UnicodeString=\"This\"",
                ArtifactsDir + "XpsSaveOptions.OptimizeOutput.xps", "1.fpage");
        }
        public void SaveAsXps()
        {
            //ExStart
            //ExFor:XpsSaveOptions
            //ExFor:XpsSaveOptions.#ctor
            //ExFor:Document.Save(String)
            //ExFor:Document.Save(Stream, SaveFormat)
            //ExFor:Document.Save(String, SaveOptions)
            //ExId:SaveToXps_NewAPI
            //ExSummary:Shows how to save a document to the Xps format using the Save method and the XpsSaveOptions class.
            // Open the document
            Document doc = new Document(MyDir + "Rendering.doc");
            // Save document to file in the Xps format with default options
            doc.Save(MyDir + "Rendering.XpsDefaultOptions Out.xps");

            // Save document to stream in the Xps format with default options
            MemoryStream docStream = new MemoryStream();
            doc.Save(docStream, SaveFormat.Xps);
            // Rewind the stream position back to the beginning, ready for use
            docStream.Seek(0, SeekOrigin.Begin);

            // Save document to file in the Xps format with specified options
            // Render the first page only
            XpsSaveOptions xpsOptions = new XpsSaveOptions();
            xpsOptions.PageIndex = 0;
            xpsOptions.PageCount = 1;
            doc.Save(MyDir + "Rendering.XpsCustomOptions Out.xps", xpsOptions);
            //ExEnd
        }
        private static SaveOptions AddBookmarkSaveOptions(SaveFormat saveFormat)
        {
            PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
            XpsSaveOptions xpsSaveOptions = new XpsSaveOptions();
            SwfSaveOptions swfSaveOptions = new SwfSaveOptions();

            switch (saveFormat)
            {
                case SaveFormat.Pdf:

                    //Add bookmarks to the document
                    pdfSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("My Bookmark", 1);
                    pdfSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Nested Bookmark", 2);
                    pdfSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Bookmark_WithoutWhiteSpaces", 3);

                    return pdfSaveOptions;

                case SaveFormat.Xps:

                    //Add bookmarks to the document
                    xpsSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("My Bookmark", 1);
                    xpsSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Nested Bookmark", 2);
                    xpsSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Bookmark_WithoutWhiteSpaces", 3);

                    return xpsSaveOptions;

                case SaveFormat.Swf:

                    //Add bookmarks to the document
                    swfSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("My Bookmark", 1);
                    swfSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Nested Bookmark", 2);
                    swfSaveOptions.OutlineOptions.BookmarksOutlineLevels.Add("Bookmark_WithoutWhiteSpaces", 3);

                    return swfSaveOptions;
            }

            return null;
        }