Inheritance: ConversionOptions
Example #1
0
        public byte[] ConvertImage(byte[] image, string fileName, ImageConversionOptions options)
        {
            if (image == null || image.Length == 0)
            {
                throw new MissingSourceException("No image was specified.");
            }

            return(ConvertImages(new Dictionary <string, byte[]>()
            {
                { fileName, image }
            }, options));
        }
        protected override void Convert(ConversionOptions options)
        {
            List <string> sourceFiles = new List <string>();

            foreach (KeyValuePair <string, byte[]> sourceFile in m_sourceFiles)
            {
                string tempImageFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + Path.GetExtension(sourceFile.Key));
                File.WriteAllBytes(tempImageFile, sourceFile.Value);
                AddFileToSweep(tempImageFile);

                string widthAttribute  = string.Empty;
                string heightAttribute = string.Empty;

                if (options != null && options is ImageConversionOptions)
                {
                    ImageConversionOptions imageOptions = (ImageConversionOptions)options;

                    if (imageOptions.ImageWidthPixelsMin.HasValue)
                    {
                        widthAttribute = string.Format("width='{0}'", imageOptions.ImageWidthPixelsMin.Value);
                    }


                    if (imageOptions.ImageHeightPixelsMin.HasValue)
                    {
                        heightAttribute = string.Format("width='{0}'", imageOptions.ImageHeightPixelsMin.Value);
                    }
                }

                string tempHtmlFile        = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".html");
                string tempHtmlFileContent = string.Format("<html><body><img src='{0}' {1} {2} /></body></html>",
                                                           tempImageFile, widthAttribute, heightAttribute);
                File.WriteAllText(tempHtmlFile, tempHtmlFileContent);
                sourceFiles.Add(tempHtmlFile);
                AddFileToSweep(tempHtmlFile);
            }

            string optionArguments = GenerateOptionsArguments(options);

            ConvertToPdf(sourceFiles.ToArray(), options);
        }
Example #3
0
        public byte[] ConvertImages(Dictionary <string, byte[]> images, ImageConversionOptions options)
        {
            if (images == null || images.Count == 0)
            {
                throw new MissingSourceException("No images were specified.");
            }

            List <byte[]> converted = new List <byte[]>();

            foreach (KeyValuePair <string, byte[]> file in images)
            {
                UnsupportedTypeHandlingEnum unsupportedHandling = GetUnsupportedHandlingFromOptions(options);
                using (ConversionEngine engine = m_engineFactory.ConstructFileEngine(file.Key, file.Value, unsupportedHandling))
                {
                    engine.ConvertToPdf(options);
                    byte[] result = engine.OutputFile;
                    converted.Add(result);
                }
            }

            return(CombinePdfs(converted, options));
        }
Example #4
0
        public byte[] ConvertImages(Dictionary<string, byte[]> images, ImageConversionOptions options)
        {
            if (images == null || images.Count == 0)
            {
                throw new MissingSourceException("No images were specified.");
            }

            List<byte[]> converted = new List<byte[]>();
            foreach (KeyValuePair<string, byte[]> file in images)
            {
                UnsupportedTypeHandlingEnum unsupportedHandling = GetUnsupportedHandlingFromOptions(options);
                using (ConversionEngine engine = m_engineFactory.ConstructFileEngine(file.Key, file.Value, unsupportedHandling))
                {
                    engine.ConvertToPdf(options);
                    byte[] result = engine.OutputFile;
                    converted.Add(result);
                }
            }

            return CombinePdfs(converted, options);
        }
Example #5
0
        public byte[] ConvertImage(byte[] image, string fileName, ImageConversionOptions options)
        {
            if (image == null || image.Length == 0)
            {
                throw new MissingSourceException("No image was specified.");
            }

            return ConvertImages(new Dictionary<string, byte[]>() { { fileName, image } }, options);
        }