Ejemplo n.º 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
        }
Ejemplo n.º 2
0
        ///<Summary>
        /// ConvertHtmlToXps to convert html file to xps
        ///</Summary>
        public Response ConvertHtmlToXps(string[] fileNames, string folderName)
        {
            return(ProcessTask_(fileNames, (inFiles, outPath, zipOutFolder) =>
            {
                Aspose.Html.Rendering.Xps.XpsRenderingOptions xps_options = new Aspose.Html.Rendering.Xps.XpsRenderingOptions();
                if (Opts.HasCustomParameter("pageSize"))
                {
                    var sz = OptionHelper.getPageSizeByName(Opts.GetCustomParameter("pageSize"));
                    if (sz != null)
                    {
                        xps_options.PageSetup.AnyPage.Size = sz;
                    }
                }
                Dictionary <string, string> customParams = null;
                if (Opts.HasCustomParameter("mdTheme"))
                {
                    var csstheme = Opts.GetCustomParameter("mdTheme");
                    customParams = new Dictionary <string, string> {
                        { "cssTheme", csstheme }
                    };
                }
                SourceFormat srcFormat = ExportHelper.GetSourceFormatByFileName(Opts.FileName);
                ExportHelper helper = ExportHelper.GetHelper(srcFormat, ExportFormat.XPS, customParams);

                helper.Export(inFiles, outPath, xps_options);
            }));
        }
 ///<Summary>
 /// ConvertHtmlToXps to convert html file to xps
 ///</Summary>
 public Response ConvertHtmlToXps(string fileName, string folderName)
 {
     return(ProcessTask(fileName, folderName, ".xps", false, false, delegate(string inFilePath, string outPath, string zipOutFolder)
     {
         Aspose.Html.Rendering.Xps.XpsRenderingOptions xps_options = new Aspose.Html.Rendering.Xps.XpsRenderingOptions();
         SourceFormat srcFormat = ExportHelper.GetSourceFormatByFileName(fileName);
         ExportHelper helper = ExportHelper.GetHelper(srcFormat, ExportFormat.XPS);
         helper.Export(inFilePath, outPath, xps_options);
     }));
 }
Ejemplo n.º 4
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
        }