예제 #1
0
        public void GeneratePdfToImageBasicTest()
        {
            var fileCreated  = _pdftoImageConverter.ConvertToImage(Source1, destination1, null, true);
            var fileCreated1 = _pdftoImageConverter.ConvertToImage(Source2, destination2, null, true);

            Assert.IsNotNull(fileCreated);
        }
예제 #2
0
        public ResultMedia GetMediaFromPdfFile(string pdfFilePath, string folderLocationToSaveFile, string testNamePrefix, bool hideSections = false, List <RectangleDimesion> rectangles = null, List <RectangleDimesion> highQualityRectangles = null, bool convertImageBackToPdf = false)
        {
            var imageName          = testNamePrefix + "_" + DateTime.Now.ToFileTimeUtc() + ".jpg";
            var thumbnailImageName = "Thumb_" + imageName;
            var filePath           = folderLocationToSaveFile + imageName;

            var imageConverted = !rectangles.IsNullOrEmpty() ? _pdfToImageConverter.ConvertToImage(pdfFilePath, filePath, _logger, hideSections, rectangles, highQualityRectangles) : _pdfToImageConverter.ConvertToImage(pdfFilePath, filePath, _logger, hideSections);

            if (!imageConverted)
            {
                return(null);
            }
            _logger.Info("Convert back to pdf : " + convertImageBackToPdf);
            if (convertImageBackToPdf)
            {
                var pdfName = ConvertJpgAsPdf(filePath, testNamePrefix, Directory.GetParent(folderLocationToSaveFile).FullName);

                _logger.Info("pdf file name : " + pdfName);
                return(new ResultMedia
                {
                    File = new Core.Application.Domain.File
                    {
                        Path = pdfName,
                        UploadedOn = DateTime.Now,
                        Type = FileType.Pdf,
                        FileSize = new FileInfo(filePath).Length
                    }
                });
            }
            CreateThumbnailImage(filePath, folderLocationToSaveFile + thumbnailImageName);
            return(new ResultMedia
            {
                File =
                    new Core.Application.Domain.File
                {
                    Path = imageName,
                    UploadedOn = DateTime.Now,
                    Type = FileType.Image,
                    FileSize = new FileInfo(filePath).Length
                },
                Thumbnail =
                    new Core.Application.Domain.File
                {
                    Path = thumbnailImageName,
                    UploadedOn = DateTime.Now,
                    Type = FileType.Image,
                    FileSize = new FileInfo(folderLocationToSaveFile + thumbnailImageName).Length
                }
            });
        }