Exemple #1
0
        static void Main()
        {
            // Create new document
            Document pdfDocument = new Document();

            pdfDocument.RegistrationName = "demo";
            pdfDocument.RegistrationKey  = "demo";

            // If you wish to load an existing document uncomment the line below and comment the Add page section instead
            // pdfDocument.Load(@".\existing_document.pdf");

            //Create instance and load file
            Xps2Image xps2Image = new Xps2Image("Sample.xps");

            // Set parameter
            Parameters oParam = new Parameters();

            oParam.Dpi       = 300;           // Set Dpi
            oParam.ImageType = ImageType.Png; // Output image type

            // Get Bitmap from input file
            var outBitmapList = xps2Image.ToBitmap(oParam);

            foreach (var itmBitmap in outBitmapList)
            {
                // Create new pdf page
                Page page = new Page(PaperFormat.A4);

                // Save image to a bytestream
                MemoryStream byteStream = new MemoryStream();
                itmBitmap.Save(byteStream, ImageFormat.Png);

                // Fill page with image
                Image pageImage = new Image(byteStream);
                page.Canvas.DrawImage(pageImage, 5, 5, pageImage.Width / 2, pageImage.Height / 3);

                // Add pdf page to pdf document
                pdfDocument.Pages.Add(page);
            }

            // Save document to file
            pdfDocument.Save("result.pdf");

            // Cleanup
            pdfDocument.Dispose();

            // Open result document in default associated application (for demo purpose)
            ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf");

            processStartInfo.UseShellExecute = true;
            Process.Start(processStartInfo);
        }
Exemple #2
0
        public void TestStaticConvertFromDisk()
        {
            var images = Xps2Image.ToBitmap(_xpsSinglePage, new Parameters
            {
                ImageType = ImageType.Png,
                Dpi       = 300,
            });

            Assert.That(images.Count(), Is.EqualTo(1));

            images = Xps2Image.ToBitmap(_xpsMultiplePages, new Parameters
            {
                ImageType = ImageType.Png,
                Dpi       = 300,
            });

            Assert.That(images.Count(), Is.EqualTo(8));
        }
Exemple #3
0
        public void TestStaticConvertStream()
        {
            var images = Xps2Image.ToBitmap(new MemoryStream(File.ReadAllBytes(_xpsSinglePage)), new Parameters
            {
                ImageType = ImageType.Png,
                Dpi       = 300,
            });

            Assert.That(images.Count(), Is.EqualTo(1));

            images = Xps2Image.ToBitmap(new MemoryStream(File.ReadAllBytes(_xpsMultiplePages)), new Parameters
            {
                ImageType = ImageType.Png,
                Dpi       = 300,
            });

            Assert.That(images.Count(), Is.EqualTo(8));
        }
Exemple #4
0
        public void TestConvertStream()
        {
            using (var xpsConverter = new Xps2Image(new MemoryStream(File.ReadAllBytes(_xpsSinglePage))))
            {
                var images = xpsConverter.ToBitmap(new Parameters
                {
                    ImageType = ImageType.Png,
                    Dpi = 300,
                });

                Assert.That(images.Count(), Is.EqualTo(1));
            }
            using (var xpsConverter = new Xps2Image(new MemoryStream(File.ReadAllBytes(_xpsMultiplePages))))
            {
                var images = xpsConverter.ToBitmap(new Parameters
                {
                    ImageType = ImageType.Png,
                    Dpi = 300,
                });

                Assert.That(images.Count(), Is.EqualTo(5));
            }
        }
Exemple #5
0
        public void TestConvertFromDisk()
        {
            using (var xpsConverter = new Xps2Image(_xpsSinglePage))
            {
                var images = xpsConverter.ToBitmap(new Parameters
                {
                    ImageType = ImageType.Png,
                    Dpi = 300,
                });

                Assert.That(images.Count(), Is.EqualTo(1));
            }
            using (var xpsConverter = new Xps2Image(_xpsMultiplePages))
            {
                var images = xpsConverter.ToBitmap(new Parameters
                {
                    ImageType = ImageType.Png,
                    Dpi = 300,
                });

                Assert.That(images.Count(), Is.EqualTo(5));
            }
        }
Exemple #6
0
        public void TestConvertFromDisk()
        {
            using (var xpsConverter = new Xps2Image(_xpsSinglePage))
            {
                var images = xpsConverter.ToBitmap(new Parameters
                {
                    ImageType = ImageType.Png,
                    Dpi       = 300,
                });

                Assert.That(images.Count(), Is.EqualTo(1));
            }
            using (var xpsConverter = new Xps2Image(_xpsMultiplePages))
            {
                var images = xpsConverter.ToBitmap(new Parameters
                {
                    ImageType = ImageType.Png,
                    Dpi       = 300,
                });

                Assert.That(images.Count(), Is.EqualTo(8));
            }
        }
Exemple #7
0
        public void TestConvertStream()
        {
            using (var xpsConverter = new Xps2Image(new MemoryStream(File.ReadAllBytes(_xpsSinglePage))))
            {
                var images = xpsConverter.ToBitmap(new Parameters
                {
                    ImageType = ImageType.Png,
                    Dpi       = 300,
                });

                Assert.That(images.Count(), Is.EqualTo(1));
            }
            using (var xpsConverter = new Xps2Image(new MemoryStream(File.ReadAllBytes(_xpsMultiplePages))))
            {
                var images = xpsConverter.ToBitmap(new Parameters
                {
                    ImageType = ImageType.Png,
                    Dpi       = 300,
                });

                Assert.That(images.Count(), Is.EqualTo(8));
            }
        }