Beispiel #1
0
        protected static IDevice GetOutputDevice(ConversionApplicationOptions options, string filePath)
        {
            T ApplyPageSizeIfAny <T>(T renderingOptions)
                where T : RenderingOptions
            {
                if (options.PageSize != null)
                {
                    renderingOptions.PageSetup.AnyPage.Size = options.PageSize;
                }
                return(renderingOptions);
            }

            if (FileFormat.PDF == options.OutputFormat)
            {
                var pdfOptions = new Aspose.Html.Rendering.Pdf.PdfRenderingOptions();
                if (!string.IsNullOrEmpty(options.UserPassword) && !string.IsNullOrEmpty(options.OwnerPassword))
                {
                    const PdfPermissions allPermissions = PdfPermissions.PrintDocument | PdfPermissions.ModifyContent |
                                                          PdfPermissions.ExtractContent | PdfPermissions.ModifyTextAnnotations |
                                                          PdfPermissions.FillForm | PdfPermissions.ExtractContentWithDisabilities |
                                                          PdfPermissions.AssembleDocument | PdfPermissions.PrintingQuality;

                    pdfOptions.Encryption = new Aspose.Html.Rendering.Pdf.Encryption.PdfEncryptionInfo(
                        options.UserPassword,
                        options.OwnerPassword,
                        allPermissions,
                        PdfEncryptionAlgorithm.RC4_128);
                }
                pdfOptions.BackgroundColor = options.BackgroundColor;
                return(new PdfDevice(pdfOptions, filePath));
            }

            if (FileFormat.XPS == options.OutputFormat)
            {
                var xpsOptions = new XpsRenderingOptions();
                xpsOptions = ApplyPageSizeIfAny(xpsOptions);
                return(new XpsDevice(ApplyPageSizeIfAny(xpsOptions), filePath));
            }


            if (FileFormat.JPEG == options.OutputFormat ||
                FileFormat.PNG == options.OutputFormat ||
                FileFormat.BMP == options.OutputFormat ||
                FileFormat.TIFF == options.OutputFormat ||
                FileFormat.GIF == options.OutputFormat)
            {
                var imageOptions = new ImageRenderingOptions(options.OutputFormat.ToImageFormat());
                imageOptions.BackgroundColor = options.BackgroundColor;
                imageOptions = ApplyPageSizeIfAny(imageOptions);
                return(new ImageDevice(imageOptions, filePath));
            }


            throw new ArgumentException("The output format is not supported.", "OutputFormat");
        }
        public static void Run()
        {
            //ExStart: ConvertSVGToXPS
            string dataDir = RunExamples.GetDataDir_Convert();

            using (var document = new SVGDocument(Path.Combine(dataDir, "smiley.svg")))
            {
                var options = new XpsRenderingOptions()
                {
                    PageSetup =
                    {
                        AnyPage = new Page(new Size(500, 500))
                    }
                };
                using (var device = new XpsDevice(options, dataDir + "smiley_out.xps"))
                {
                    document.RenderTo(device);
                }
            }
            //ExEnd: ConvertSVGToXPS
        }
 static void ConvertSVGtoXPS()
 {
     // Load input SVG file
     using (var document = new SVGDocument(Path.Combine(dataDir, "smiley.svg")))
     {
         // Specify XPSRenderingOptions
         var options = new XpsRenderingOptions()
         {
             // Set PDF page size, margins, etc.
             PageSetup =
             {
                 AnyPage = new Page(new Size(500, 500))
             }
         };
         using (var device = new XpsDevice(options, dataDir + "smiley_out.xps"))
         {
             // Render SVG to XPS
             document.RenderTo(device);
         }
     }
 }
        public static void Run()
        {
            //ExStart: RenderingOptions
            string dataDir = RunExamples.GetDataDir_Save();

            using (var document = new SVGDocument(Path.Combine(dataDir, "smiley.svg")))
            {
                var options = new XpsRenderingOptions()
                {
                    PageSetup =
                    {
                        AnyPage = new Page(new Aspose.Svg.Drawing.Size(500, 500), new Margin(50, 50, 50, 50))
                    },
                    BackgroundColor = Color.Blue
                };
                using (XpsDevice device = new XpsDevice(options, dataDir + "RenderingOptions_out.xps"))
                {
                    document.RenderTo(device);
                }
            }
            //ExEnd: RenderingOptions
        }
Beispiel #5
0
        public virtual void Export(string sourcePath, string outPath, RenderingOptions options = null)
        {
            switch (dstFormat_)
            {
            case ExportFormat.PDF:
                PdfRenderingOptions pdf_opts = options as PdfRenderingOptions;
                if (pdf_opts == null)
                {
                    pdf_opts = new PdfRenderingOptions();
                }

                using (PdfDevice device = new PdfDevice(pdf_opts, outPath))
                {
                    Render(sourcePath, device);
                }
                break;

            case ExportFormat.XPS:
                XpsRenderingOptions xps_opts = options as XpsRenderingOptions
                ;
                if (xps_opts == null)
                {
                    xps_opts = new XpsRenderingOptions();
                }

                using (XpsDevice device = new XpsDevice(xps_opts, outPath))
                {
                    Render(sourcePath, device);
                }
                break;

            case ExportFormat.MD:
                IDevice nullDev = null;
                Render(sourcePath, nullDev);
                break;

            case ExportFormat.MHTML:
                throw new NotImplementedException("Conversion to 'MHTML' isn't implemented yet.");

            //break;
            case ExportFormat.JPEG:
            case ExportFormat.PNG:
            case ExportFormat.BMP:
            case ExportFormat.TIFF:
            case ExportFormat.GIF:
                ImageRenderingOptions img_opts = options as ImageRenderingOptions;
                if (img_opts == null)
                {
                    img_opts = new ImageRenderingOptions();
                }
                switch (dstFormat_)
                {
                case ExportFormat.JPEG:
                    img_opts.Format = ImageFormat.Jpeg; break;

                case ExportFormat.PNG:
                    img_opts.Format = ImageFormat.Png; break;

                case ExportFormat.BMP:
                    img_opts.Format = ImageFormat.Bmp; break;

                case ExportFormat.TIFF:
                    img_opts.Format = ImageFormat.Tiff; break;

                case ExportFormat.GIF:
                    img_opts.Format = ImageFormat.Gif; break;
                }
                using (ImageDevice device = new ImageDevice(img_opts, outPath))
                {
                    Render(sourcePath, device);
                }

                break;
            }
        }