Exemple #1
0
        public static void SpecifyPdfSaveOptions()
        {
            //ExStart: SpecifyPdfSaveOptions
            // Prepare an SVG code and save it to the file.
            var code = "<svg xmlns='http://www.w3.org/2000/svg'>" +
                       "<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" +
                       "</svg>";

            System.IO.File.WriteAllText("document.svg", code);

            // Set A5 as a page-size and change the background color to green
            var options = new Aspose.Html.Saving.PdfSaveOptions()
            {
                PageSetup =
                {
                    AnyPage  = new Aspose.Html.Drawing.Page()
                    {
                        Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromInches(8.3f), Aspose.Html.Drawing.Length.FromInches(5.8f))
                    }
                },
                BackgroundColor = System.Drawing.Color.Green,
            };

            // Convert SVG document to PDF
            Aspose.Html.Converters.Converter.ConvertSVG("document.svg", options, "output.pdf");
            //ExEnd: SpecifyPdfSaveOptions
        }
Exemple #2
0
        public static void SpecifyPdfSaveOptions()
        {
            //ExStart: SpecifyPdfSaveOptions
            string dataDir = RunExamples.GetDataDir_Data();

            // Open an existing MHTML file for reading.
            using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht"))
            {
                // Create an instance of the PdfSaveOptions with a custom page-size and a background-color.
                var options = new Aspose.Html.Saving.PdfSaveOptions()
                {
                    PageSetup =
                    {
                        AnyPage  = new Aspose.Html.Drawing.Page()
                        {
                            Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromPixels(3000), Aspose.Html.Drawing.Length.FromPixels(1000))
                        }
                    },
                    BackgroundColor = System.Drawing.Color.AliceBlue,
                };

                // Call the ConvertMHTML method to convert the MHTML to PDF.
                Aspose.Html.Converters.Converter.ConvertMHTML(stream, options, "output.pdf");
            }
            //ExEnd: SpecifyPdfSaveOptions
        }
Exemple #3
0
        public static void SpecifyPdfSaveOptions()
        {
            //ExStart: SpecifyPdfSaveOptions
            // Prepare an HTML code and save it to the file
            var code = @"<span>Hello</span> <span>World!!</span>";

            System.IO.File.WriteAllText("document.html", code);

            // Set A5 as a page-size and change the background color to green
            var options = new Aspose.Html.Saving.PdfSaveOptions()
            {
                PageSetup =
                {
                    AnyPage  = new Aspose.Html.Drawing.Page()
                    {
                        Size = new Aspose.Html.Drawing.Size(Aspose.Html.Drawing.Length.FromInches(8.3f), Aspose.Html.Drawing.Length.FromInches(5.8f))
                    }
                },
                BackgroundColor = System.Drawing.Color.Green,
            };

            // Convert HTML document to PDF
            Aspose.Html.Converters.Converter.ConvertHTML("document.html", options, "output.pdf");
            //ExEnd: SpecifyPdfSaveOptions
        }
Exemple #4
0
        public static void ConvertMHTMLFileToPDF()
        {
            //ExStart: ConvertMHTMLFileToPDF
            string dataDir = RunExamples.GetDataDir_Data();

            // Open an existing MHTML file for reading.
            using (var stream = System.IO.File.OpenRead(dataDir + "sample.mht"))
            {
                // Create an instance of PdfSaveOptions.
                var options = new Aspose.Html.Saving.PdfSaveOptions();

                // Call the ConvertMHTML method to convert the MHTML to PDF.
                Aspose.Html.Converters.Converter.ConvertMHTML(stream, options, "output.pdf");
            }
            //ExEnd: ConvertMHTMLFileToPDF
        }
Exemple #5
0
        public static void ConvertHTMLDocumentToPDF()
        {
            //ExStart: ConvertHTMLDocumentToPDF
            // Prepare an HTML code and save it to the file.
            var code = @"<span>Hello World!!</span>";

            System.IO.File.WriteAllText("document.html", code);

            // Initialize an HTML document from the file
            using (var document = new HTMLDocument("document.html"))
            {
                // Initialize PdfSaveOptions
                var options = new Aspose.Html.Saving.PdfSaveOptions();

                // Convert HTML to PDF
                Aspose.Html.Converters.Converter.ConvertHTML(document, options, "output.pdf");
            }
            //ExEnd: ConvertHTMLDocumentToPDF
        }
Exemple #6
0
        public static void ConvertSVGDocumentToPDF()
        {
            //ExStart: ConvertSVGDocumentToPDF
            // Prepare an SVG code and save it to the file.
            var code = "<svg xmlns='http://www.w3.org/2000/svg'>" +
                       "<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />" +
                       "</svg>";

            System.IO.File.WriteAllText("document.svg", code);

            // Initialize an SVG document from the svg file.
            using (var document = new Aspose.Html.Dom.Svg.SVGDocument("document.svg"))
            {
                // Initialize PdfSaveOptions.
                var options = new Aspose.Html.Saving.PdfSaveOptions();

                // Convert HTML to PDF
                Aspose.Html.Converters.Converter.ConvertSVG(document, options, "output.pdf");
            }
            //ExEnd: ConvertSVGDocumentToPDF
        }