コード例 #1
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithDocumentConversion();
            // Input file
            string inputFileName = dataDir + "input.xps";
            //Outut file
            string outputFileName = dataDir + "XPStoImage_out.png";

            // Initialize XPS input stream
            using (Stream xpsStream = File.Open(inputFileName, FileMode.Open, FileAccess.Read))
            {
                // Load XPS document form the stream
                XpsDocument document = new XpsDocument(xpsStream, new XpsLoadOptions());
                // or load XPS document directly from file. No xpsStream is needed then.
                // XpsDocument document = new XpsDocument(inputFileName, new XpsLoadOptions());

                // Initialize options object with necessary parameters.
                PngSaveOptions options = new PngSaveOptions()
                {
                    SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality,
                    Resolution    = 300,
                    PageNumbers   = new int[] { 1, 2, 6 }
                };

                // Create rendering device for PDF format
                ImageDevice device = new ImageDevice();

                document.Save(device, options);

                // Iterate through document partitions (fixed documents, in XPS terms)
                for (int i = 0; i < device.Result.Length; i++)
                {
                    // Iterate through partition pages
                    for (int j = 0; j < device.Result[i].Length; j++)
                    {
                        // Initialize image output stream
                        using (Stream imageStream = System.IO.File.Open(Path.GetDirectoryName(outputFileName) +
                                                                        Path.GetFileNameWithoutExtension(outputFileName) + "_" + (i + 1) + "_" + (j + 1) +
                                                                        Path.GetExtension(outputFileName), System.IO.FileMode.Create, System.IO.FileAccess.Write))
                            // Write image
                            imageStream.Write(device.Result[i][j], 0, device.Result[i][j].Length);
                    }
                }
            }
            // ExEnd:1
        }
コード例 #2
0
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithDocumentConversion();
            // Load Existing XPS Document
            XpsDocument doc = new XpsDocument(dataDir + "input.xps");
            // Initialize PngSaveOptions
            PngSaveOptions pngSaveOptions = new PngSaveOptions();

            // Specify Resolution
            pngSaveOptions.Resolution = 300f;
            // Save as PNG Image
            doc.Save(dataDir + "XPStoImage_out.png", pngSaveOptions);
            // ExEnd:1
        }
コード例 #3
0
        private Response ConvertXpsToImage(string fileName, string folderName, string outputType)
        {
            return(ProcessTask(fileName, folderName, "." + outputType, true, false,

                               delegate(string inFilePath, string outPath, string zipOutFolder)
            {
                using (Stream xpsStream = System.IO.File.Open(inFilePath, FileMode.Open, FileAccess.Read))
                {
                    XpsDocument document = new XpsDocument(xpsStream, new XpsLoadOptions());
                    Aspose.Page.XPS.Presentation.Image.ImageSaveOptions options = new BmpSaveOptions();

                    switch (outputType)
                    {
                    case "tiff":
                        options = new TiffSaveOptions();
                        break;

                    case "png":
                        options = new PngSaveOptions();
                        break;

                    case "jpg":
                        options = new JpegSaveOptions();
                        break;
                    }

                    Page.XPS.Presentation.Image.ImageDevice device = new Page.XPS.Presentation.Image.ImageDevice();

                    document.Save(device, options);

                    for (int i = 0; i < device.Result.Length; i++)
                    {
                        for (int j = 0; j < device.Result[i].Length; j++)
                        {
                            string imagePath = Path.GetFileNameWithoutExtension(fileName) + "_" + (j + 1) + "." + outputType;
                            outPath = zipOutFolder + "/" + imagePath;

                            using (Stream imageStream = System.IO.File.Open(outPath, FileMode.Create, FileAccess.Write))
                            {
                                imageStream.Write(device.Result[i][j], 0, device.Result[i][j].Length);
                            }
                        }
                    }
                }
            }));
        }