Exemple #1
0
        public static void SpecifyXpsRenderingOptions()
        {
            //ExStart: SpecifyXpsRenderingOptions
            // Prepare an HTML code
            var code = @"<span>Hello World!!</span>";

            // Initialize the HTML document from the HTML code
            using (var document = new Aspose.Html.HTMLDocument(code, "."))
            {
                // Create the instance of XpsRenderingOptions and set a custom page-size
                var options = new Aspose.Html.Rendering.Xps.XpsRenderingOptions();
                options.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(
                    new Aspose.Html.Drawing.Size(
                        Aspose.Html.Drawing.Length.FromInches(5),
                        Aspose.Html.Drawing.Length.FromInches(2)));

                // Create the XPS Device and specify options and output file
                using (var device = new Aspose.Html.Rendering.Xps.XpsDevice(options, "output.xps"))
                {
                    // Render HTML to XPS
                    document.RenderTo(device);
                }
            }
            //ExEnd: SpecifyXpsRenderingOptions
        }
        public static void Run()
        {
            // ExStart:SVGtoXPS
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Data();

            // Simple SVG file
            File.WriteAllText(dataDir + "my.svg",
                              "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"140\" width=\"500\">" +
                              "<ellipse cx=\"200\" cy=\"80\" rx=\"100\" ry=\"50\" style=\"fill:yellow;stroke:purple;stroke-width:2\" />" +
                              "</svg>");

            // Create the new SVG document
            Aspose.Html.Dom.Svg.SVGDocument document = new Aspose.Html.Dom.Svg.SVGDocument(dataDir + "my.svg");

            // Simple navigation and inspection the element properties
            Aspose.Html.Dom.Svg.SVGEllipseElement ellipse = (Aspose.Html.Dom.Svg.SVGEllipseElement)document.GetElementsByTagName("ellipse").First();
            Console.WriteLine(ellipse.Style.CSSText);  // fill: yellow; stroke: purple; stroke-width: 2;

            // Create the new SVG renderer & XPS device
            using (Aspose.Html.Rendering.SvgRenderer renderer = new Aspose.Html.Rendering.SvgRenderer())
                using (Aspose.Html.Rendering.Xps.XpsDevice device = new Aspose.Html.Rendering.Xps.XpsDevice(dataDir + "my.xps"))
                {
                    // Render to the output device
                    renderer.Render(device, document);
                }
            // ExEnd:SVGtoXPS
        }
Exemple #3
0
        public static void Run()
        {
            // ExStart:1
            string dataDir = RunExamples.GetDataDir_Data();

            using (var fs = File.OpenRead(dataDir + "document.epub"))
                using (var device = new Aspose.Html.Rendering.Xps.XpsDevice(dataDir + "document_out.xps"))
                    using (var renderer = new Aspose.Html.Rendering.EpubRenderer())
                    {
                        renderer.Render(device, fs);
                    }
            // ExEnd:1
        }
Exemple #4
0
        public static void AddTitleAndPageNumber()
        {
            //ExStart: AddTitleAndPageNumber
            //  Initialize configuration object and set up the page-margins for the document
            using (Configuration configuration = new Configuration())
            {
                // Get the User Agent service
                var userAgent = configuration.GetService <Aspose.Html.Services.IUserAgentService>();

                // Set the style of custom margins and create marks on it
                userAgent.UserStyleSheet = @"@page 
                                            {
                                                /* Page margins should be not empty in order to write content inside the margin-boxes */
                                                margin-top: 1cm;
                                                margin-left: 2cm;
                                                margin-right: 2cm;
                                                margin-bottom: 2cm;
                                                /* Page counter located at the bottom of the page */
                                                @bottom-right
                                                {
                                                    -aspose-content: ""Page "" currentPageNumber() "" of "" totalPagesNumber();
                                                    color: green;
                                                }

                                                /* Page title located at the top-center box */
                                                @top-center
                                                {
                                                    -aspose-content: ""Hello World Document Title!!!"";
                                                    vertical-align: bottom;
                                                    color: blue;
                                                }    
                                            }";

                //  Initialize an HTML document
                using (HTMLDocument document = new HTMLDocument("<div>Hello World!!!</div>", ".", configuration))
                {
                    //  Initialize an output device
                    using (Aspose.Html.Rendering.Xps.XpsDevice device = new Aspose.Html.Rendering.Xps.XpsDevice("output.xps"))
                    {
                        // Send the document to the output device
                        document.RenderTo(device);
                    }
                }
            }
            //ExEnd: AddTitleAndPageNumber
        }
Exemple #5
0
        public static void Run()
        {
            // ExStart:HtmlToXPS
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Data();

            String InputHtml = dataDir + "FirstFile.html";

            using (FileStream fs = File.Create(InputHtml))
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.Write(
                        @"<style>
                    .st
                    {
                    color: green;
                    }
                    </style>
                    <div id=id1>Aspose.Html rendering Text in Black Color</div>
                    <div id=id2 class=''st''>Aspose.Html rendering Text in Green Color</div>
                    <div id=id3 class=''st'' style='color: blue;'>Aspose.Html rendering Text in Blue Color</div>
                    <div id=id3 class=''st'' style='color: red;'>Aspose.Html rendering Text in Red Color</div>
                    ");
                }

            // File name for resultant XPS file
            string Resultnat_output = dataDir + "simple-any-page_out.xps";

            // Create XpxRendering Options object
            Aspose.Html.Rendering.Xps.XpsRenderingOptions xps_options = new Aspose.Html.Rendering.Xps.XpsRenderingOptions();
            // The PageSetup also provides different properties i.e. FirstPage, LastPage, LeftPage, RightPage and they are used to setup (PageSize, Margin) for every page.
            // In most cases, usage of setup any page is enough, but in some complicated cases, you may need to fine tune page settings. It can be done either by CSS styles or by using rendering options.
            // the size for drawing is in pixels
            xps_options.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(200, 60));
            // Instantiate XPSDevice object while passing XPSRenderingOptions and resultant file path as arguments
            using (Aspose.Html.Rendering.Xps.XpsDevice device = new Aspose.Html.Rendering.Xps.XpsDevice(xps_options, Resultnat_output))
                // Create HtmlRenderer object
                using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer())
                    // Create HtmlDocument instnace while passing path of already created HTML file
                    using (Aspose.Html.HTMLDocument html_document = new Aspose.Html.HTMLDocument(InputHtml))
                    {
                        // Render the output using HtmlRenderer
                        renderer.Render(device, html_document);
                    }
            // ExEnd:HtmlToXPS
        }
        public static void Run()
        {
            // ExStart:AdjustXPSPageSize
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Data();

            // Set input file name.
            String SimpleStyledFilePath = dataDir + "FirstFile.html";

            using (FileStream fs = File.Create(SimpleStyledFilePath))
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.Write(
                        @"<style>
                    .st
                    {
                    color: green;
                    }
                    </style>
                    <div id=id1>Aspose.Html rendering Text in Black Color</div>
                    <div id=id2 class=''st''>Aspose.Html rendering Text in Green Color</div>
                    <div id=id3 class=''st'' style='color: blue;'>Aspose.Html rendering Text in Blue Color</div>
                    <div id=id3 class=''st'' style='color: red;'>Aspose.Html rendering Text in Red Color</div>
                    ");
                }

            // Create HtmlRenderer object
            using (Aspose.Html.Rendering.HtmlRenderer renderer = new Aspose.Html.Rendering.HtmlRenderer())
                // Create HtmlDocument instnace while passing path of already created HTML file
                using (Aspose.Html.HTMLDocument html_document = new Aspose.Html.HTMLDocument(SimpleStyledFilePath))
                {
                    // Set the page size less than document min-width. The content in the resulting file will be cropped becuase of element with width: 200px
                    Aspose.Html.Rendering.Xps.XpsRenderingOptions xps_options = new Aspose.Html.Rendering.Xps.XpsRenderingOptions
                    {
                        PageSetup =
                        {
                            AnyPage            = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(100, 100)),
                            AdjustToWidestPage = false
                        },
                    };
                    string output = dataDir + "not-adjusted-to-widest-page_out.xps";
                    using (Aspose.Html.Rendering.Xps.XpsDevice device = new Aspose.Html.Rendering.Xps.XpsDevice(xps_options, output))
                    {
                        // Render the output
                        renderer.Render(device, html_document);
                    }


                    // Set the page size less than document min-width and enable AdjustToWidestPage option
                    // The page size of the resulting file will be changed according to content width
                    xps_options = new Aspose.Html.Rendering.Xps.XpsRenderingOptions
                    {
                        PageSetup =
                        {
                            AnyPage            = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(100, 100)),
                            AdjustToWidestPage = true
                        },
                    };
                    output = dataDir + "adjusted-to-widest-page_out.xps";
                    using (Aspose.Html.Rendering.Xps.XpsDevice device = new Aspose.Html.Rendering.Xps.XpsDevice(xps_options, output))
                    {
                        // render the output
                        renderer.Render(device, html_document);
                    }
                }
            // ExEnd:AdjustXPSPageSize
        }