private void GenerateDocumentContent()
        {
            // The default image quality is controlled by PdfFormatProvider.ExportSettings.
            this.AddPageWithImage("This is JPEG image with RGB colorspace.", CreateImageSource("Resources/rgb.jpg"));
            this.AddPageWithImage("This is JPEG image with Grayscale colorspace.", CreateImageSource("Resources/grayScale.jpg"));
            this.AddPageWithImage("This is JPEG image with CMYK colorspace.", CreateImageSource("Resources/cmyk.jpg"));
#if !NETCOREAPP
            this.AddPageWithImage("This is PNG image with transparency encoded with DCTDecode.", CreateImageSource("Resources/transparent.png"));
#endif
#if !NETCOREAPP
            // This example shows how to insert RGBA image compressed with FlateDecode.
            // This approach guarantees lossless image quality compression different from the previous compression which exports the images with the lossy DCTDecode filter.
            EncodedImageData imageDataFlateDecode = this.EncodeRgbaPngImageWithFlateDecode("Resources/transparent.png");
            this.AddPageWithImage("This is RGBA PNG image encoded with FlateDecode.", new ImageSource(imageDataFlateDecode));
#endif

            // JPEG2000 images must be inserted with ImageQuality.High.
            // Exporting this image format with lower quality requires decoding the JPEG2000 image, which is currently not supported by RadPdfProcessing.
            // That is why the image quality must be specified in the constructor of the ImageSource class in order to override PdfFormatProvider.ExportSettings.ImageQuality value.
            this.AddPageWithImage("This is JPEG2000 image with RGB colorspace.", CreateImageSource("Resources/rgb.jp2", ImageQuality.High));
            this.AddPageWithImage("This is JPEG2000 image with Grayscale colorspace.", CreateImageSource("Resources/grayScale.jp2", ImageQuality.High));
#if !NETCOREAPP
            // This example shows how to insert dualtone image compressed with FlateDecode and with BitsPerComponent 1.
            // Exporting this image with the above mentioned properties will reduce the size of the produced PDF file.
            // Inserting image with EncodedImageData guarantees that the image is inserted with maximum image quality.
            // The image is exported as it is without respecting PdfFormatProvider.ExportSettings.ImageQuality value.
            EncodedImageData encodedImageData = EncodeDualtonePngImage("Resources/dualtone.png");
            this.AddPageWithImage("This is Dualtone PNG image encoded with FlateDecode.", new ImageSource(encodedImageData));
#endif
        }
Beispiel #2
0
        private byte[] CreateDocument()
        {
            RadFixedDocument document = new RadFixedDocument();

            byte[]           resourceBytes = ResourceHelper.GetResourceBytes("Resources/rgb.jpg");
            EncodedImageData rgbJpeg       = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceRgb, new string[] { PdfFilterNames.DCTDecode });

            this.CreatePageWithImage(document, "JPEG", rgbJpeg);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/grayScale.jpg");
            EncodedImageData jpeg2000Gray = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceGray, new string[] { PdfFilterNames.DCTDecode });

            this.CreatePageWithImage(document, "JPEG", jpeg2000Gray);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/rgb.jp2");
            EncodedImageData rgbJpc = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceRgb, new string[] { PdfFilterNames.JPXDecode });

            this.CreatePageWithImage(document, "JPEG 2000", rgbJpc);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/grayScale.jp2");
            EncodedImageData grayScaleJpc = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceGray, new string[] { PdfFilterNames.JPXDecode });

            this.CreatePageWithImage(document, "JPEG 2000", grayScaleJpc);

            if (File.Exists(TestFileName))
            {
                File.Delete(TestFileName);
            }

            byte[] documentBytes = new PdfFormatProvider().Export(document);

            return(documentBytes);
        }
Beispiel #3
0
        private byte[] CreateDocument()
        {
            RadFixedDocument document = new RadFixedDocument();

            byte[] resourceBytes = ResourceHelper.GetResourceBytes("Resources/rgb.jpg");
            EncodedImageData rgbJpeg = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceRgb, new string[] { PdfFilterNames.DCTDecode });
            this.CreatePageWithImage(document, "JPEG", rgbJpeg);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/grayScale.jpg");
            EncodedImageData jpeg2000Gray = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceGray, new string[] { PdfFilterNames.DCTDecode });
            this.CreatePageWithImage(document, "JPEG", jpeg2000Gray);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/rgb.jp2");
            EncodedImageData rgbJpc = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceRgb, new string[] { PdfFilterNames.JPXDecode });
            this.CreatePageWithImage(document, "JPEG 2000", rgbJpc);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/grayScale.jp2");
            EncodedImageData grayScaleJpc = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceGray, new string[] { PdfFilterNames.JPXDecode });
            this.CreatePageWithImage(document, "JPEG 2000", grayScaleJpc);

            if (File.Exists(TestFileName))
            {
                File.Delete(TestFileName);
            }

            byte[] documentBytes = new PdfFormatProvider().Export(document);

            return documentBytes;
        }
Beispiel #4
0
        private void PopulateLayers()
        {
            char[] pixelData = EncodedImageData.ToCharArray();
            Console.WriteLine($"total - {pixelData.Length} per layer - {(Width * Height)} num layers - {(pixelData.Length / (Width * Height))}");
            int layerCount    = pixelData.Length / (Width * Height);
            int pixelsManaged = 0;

            for (int i = 1; i <= layerCount; i++)
            {
                ImageLayer layer = new ImageLayer(i);
                layer.Pixels = new int[Width, Height];
                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        char pixel = pixelData[pixelsManaged];
                        layer.Pixels[x, y] = Int32.Parse(pixel.ToString());
                        if (layer.LayerNumber == 1)
                        {
                            Console.WriteLine($"{x},{y} - {pixel}");
                        }
                        pixelsManaged++;
                    }
                }
                Layers.Add(layer);
            }
        }
Beispiel #5
0
        private byte[] CreateDocument()
        {
            RadFixedDocument document = new RadFixedDocument();

            byte[]           resourceBytes = ResourceHelper.GetResourceBytes("Resources/rgb.jpg");
            EncodedImageData rgbJpeg       = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceRgb, new string[] { PdfFilterNames.DCTDecode });

            this.CreatePageWithImage(document, "JPEG", rgbJpeg);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/grayScale.jpg");
            EncodedImageData grayJpeg = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceGray, new string[] { PdfFilterNames.DCTDecode });

            this.CreatePageWithImage(document, "JPEG", grayJpeg);

            // decode is used for inverting the colors of the cmyk image.
            // More information on the matter can be found here: http://graphicdesign.stackexchange.com/a/15906
            double[] decode = new double[] { 1, 0, 1, 0, 1, 0, 1, 0 };
            resourceBytes = ResourceHelper.GetResourceBytes("Resources/cmyk.jpg");
            EncodedImageData cmykJpeg = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceCmyk, new string[] { PdfFilterNames.DCTDecode });

            this.CreatePageWithImage(document, "JPEG", cmykJpeg, decode);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/rgb.jp2");
            EncodedImageData rgbJpc = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceRgb, new string[] { PdfFilterNames.JPXDecode });

            this.CreatePageWithImage(document, "JPEG 2000", rgbJpc);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/grayScale.jp2");
            EncodedImageData grayScaleJpc = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceGray, new string[] { PdfFilterNames.JPXDecode });

            this.CreatePageWithImage(document, "JPEG 2000", grayScaleJpc);

            if (File.Exists(TestFileName))
            {
                File.Delete(TestFileName);
            }

            byte[] documentBytes = new PdfFormatProvider().Export(document);

            return(documentBytes);
        }
Beispiel #6
0
        private void CreatePageWithImage(RadFixedDocument document, string imageExtension, EncodedImageData imageData)
        {
            RadFixedPage page = document.Pages.AddPage();
            page.Size = PageSize;
            FixedContentEditor editor = new FixedContentEditor(page);
            editor.Position.Translate(Margins.Left, Margins.Top);

            Block block = new Block();
            block.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            block.TextProperties.FontSize = 22;
            block.InsertText(string.Format("This is {0} image in {1} color space encoded with {2} filter.", imageExtension, imageData.ColorSpace, imageData.Filters.FirstOrDefault() ?? "None"));
            Size blockSize = block.Measure(RemainingPageSize);
            editor.DrawBlock(block, RemainingPageSize);

            editor.Position.Translate(Margins.Left, blockSize.Height + Margins.Top + 50);

            Block imageBlock = new Block();
            imageBlock.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            imageBlock.InsertImage(new ImageSource(imageData), new Size(imageData.Width, imageData.Height));
            editor.DrawBlock(imageBlock, RemainingPageSize);
        }
        private byte[] CreateDocument()
        {
            RadFixedDocument document = new RadFixedDocument();

            byte[] resourceBytes = ResourceHelper.GetResourceBytes("Resources/rgb.jpg");
            EncodedImageData rgbJpeg = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceRgb, new string[] { PdfFilterNames.DCTDecode });
            this.CreatePageWithImage(document, "JPEG", rgbJpeg);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/grayScale.jpg");
            EncodedImageData grayJpeg = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceGray, new string[] { PdfFilterNames.DCTDecode });
            this.CreatePageWithImage(document, "JPEG", grayJpeg);

            // decode is used for inverting the colors of the cmyk image.
            // More information on the matter can be found here: http://graphicdesign.stackexchange.com/a/15906
            double[] decode = new double[] { 1, 0, 1, 0, 1, 0, 1, 0 };
            resourceBytes = ResourceHelper.GetResourceBytes("Resources/cmyk.jpg");
            EncodedImageData cmykJpeg = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceCmyk, new string[] { PdfFilterNames.DCTDecode });
            this.CreatePageWithImage(document, "JPEG", cmykJpeg, decode);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/rgb.jp2");
            EncodedImageData rgbJpc = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceRgb, new string[] { PdfFilterNames.JPXDecode });
            this.CreatePageWithImage(document, "JPEG 2000", rgbJpc);

            resourceBytes = ResourceHelper.GetResourceBytes("Resources/grayScale.jp2");
            EncodedImageData grayScaleJpc = new EncodedImageData(resourceBytes, 8, 655, 983, ColorSpaceNames.DeviceGray, new string[] { PdfFilterNames.JPXDecode });
            this.CreatePageWithImage(document, "JPEG 2000", grayScaleJpc);

            if (File.Exists(TestFileName))
            {
                File.Delete(TestFileName);
            }

            byte[] documentBytes = new PdfFormatProvider().Export(document);

            return documentBytes;
        }
Beispiel #8
0
        private void CreatePageWithImage(RadFixedDocument document, string imageExtension, EncodedImageData imageData)
        {
            RadFixedPage page = document.Pages.AddPage();

            page.Size = PageSize;
            FixedContentEditor editor = new FixedContentEditor(page);

            editor.Position.Translate(Margins.Left, Margins.Top);

            Block block = new Block();

            block.HorizontalAlignment     = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            block.TextProperties.FontSize = 22;
            block.InsertText(string.Format("This is {0} image in {1} color space encoded with {2} filter.", imageExtension, imageData.ColorSpace, imageData.Filters.FirstOrDefault() ?? "None"));
            Size blockSize = block.Measure(RemainingPageSize);

            editor.DrawBlock(block, RemainingPageSize);

            editor.Position.Translate(Margins.Left, blockSize.Height + Margins.Top + 50);

            Block imageBlock = new Block();

            imageBlock.HorizontalAlignment = Telerik.Windows.Documents.Fixed.Model.Editing.Flow.HorizontalAlignment.Center;
            imageBlock.InsertImage(new ImageSource(imageData), new Size(imageData.Width, imageData.Height));
            editor.DrawBlock(imageBlock, RemainingPageSize);
        }