Beispiel #1
1
 protected void publish_import_upload_OnFileUploaded(object sender, FileUploadedEventArgs e)
 {
     var id = CurrentResource.Id;
     var file = e.File;
     var tempId = HomoryContext.Value.GetId();
     var suffix = file.GetExtension().Replace(".", "").ToLower();
     var path = string.Format("../Common/资源/{0}/{1}/{2}.{3}", CurrentUser.Id.ToString().ToUpper(), ResourceType.ToString(),
         tempId.ToString().ToUpper(), ResourceType == ResourceType.视频 ? suffix == "flv" ? suffix : "mp4" : "pdf");
     var pathX = Server.MapPath(path);
     var source = string.Format("../Common/资源/{0}/{1}/{2}.{3}", CurrentUser.Id.ToString().ToUpper(), ResourceType.ToString(),
         tempId.ToString().ToUpper(), suffix);
     var sourceX = Server.MapPath(source);
     var cpic = path.Replace(".pdf", ".jpg").Replace(".flv", ".jpg").Replace(".mp4", ".jpg");
     var cpicX = pathX.Replace(".pdf", ".jpg").Replace(".flv", ".jpg").Replace(".mp4", ".jpg");
     var res = HomoryContext.Value.Resource.Single(o => o.Id == id);
     file.SaveAs(sourceX, true);
     switch (suffix)
     {
         case "doc":
         case "docx":
         case "txt":
         case "rtf":
             var docW = new Aspose.Words.Document(sourceX);
             docW.Save(pathX, Aspose.Words.SaveFormat.Pdf);
             docW.Save(cpicX, Aspose.Words.SaveFormat.Jpeg);
             res.Image = cpic;
             res.FileType = ResourceFileType.Word;
             res.Thumbnail = ((int)ResourceFileType.Word).ToString();
             break;
         case "ppt":
         case "pptx":
             var docP = new Aspose.Slides.Presentation(sourceX);
             docP.Save(pathX, Aspose.Slides.Export.SaveFormat.Pdf);
             var tcdocp = new Aspose.Pdf.Document(pathX);
             using (var imageStream = new FileStream(cpicX, FileMode.Create))
             {
                 var resolution = new Resolution(300);
                 var jpegDevice = new JpegDevice(resolution, 100);
                 jpegDevice.Process(tcdocp.Pages[1], imageStream);
                 imageStream.Close();
             }
             res.Image = cpic;
             res.FileType = ResourceFileType.Powerpoint;
             res.Thumbnail = ((int)ResourceFileType.Powerpoint).ToString();
             break;
         case "xls":
         case "xlsx":
             var docE = new Aspose.Cells.Workbook(sourceX);
             docE.Save(pathX, Aspose.Cells.SaveFormat.Pdf);
             var tcdoce = new Aspose.Pdf.Document(pathX);
             using (var imageStream = new FileStream(cpicX, FileMode.Create))
             {
                 var resolution = new Resolution(300);
                 var jpegDevice = new JpegDevice(resolution, 100);
                 jpegDevice.Process(tcdoce.Pages[1], imageStream);
                 imageStream.Close();
             }
             res.Image = cpic;
             res.FileType = ResourceFileType.Excel;
             res.Thumbnail = ((int)ResourceFileType.Excel).ToString();
             break;
         case "pdf":
             var tcdoc = new Aspose.Pdf.Document(pathX);
             using (var imageStream = new FileStream(cpicX, FileMode.Create))
             {
                 var resolution = new Resolution(300);
                 var jpegDevice = new JpegDevice(resolution, 100);
                 jpegDevice.Process(tcdoc.Pages[1], imageStream);
                 imageStream.Close();
             }
             res.Image = cpic;
             res.FileType = ResourceFileType.Pdf;
             res.Thumbnail = ((int)ResourceFileType.Pdf).ToString();
             break;
         case "avi":
         case "mpg":
         case "mpeg":
         case "flv":
         case "mp4":
         case "rm":
         case "rmvb":
         case "wmv":
             NReco.VideoConverter.FFMpegConverter c = new NReco.VideoConverter.FFMpegConverter();
             c.GetVideoThumbnail(sourceX, cpicX, 2F);
             //if (!sourceX.EndsWith("flv", StringComparison.OrdinalIgnoreCase))
             //{
             //    c.ConvertMedia(sourceX, pathX, NReco.VideoConverter.Format.flv);
             //}
             res.Image = cpic;
             res.FileType = ResourceFileType.Media;
             res.Thumbnail = ((int)ResourceFileType.Media).ToString();
             break;
     }
     res.SourceName = file.GetName();
     res.Title = file.GetNameWithoutExtension();
     res.Source = source;
     res.Preview = path;
     res.Converted = true;
     HomoryContext.Value.SaveChanges();
 }
Beispiel #2
0
        public void ToJpeg(string absoluteFilePath, string outputPath)
        {
            float x = 0.0F;
            int   y = 0;

            using (var pdfDocument = new Document(absoluteFilePath))
            {
                for (var i = 1; i < pdfDocument.Pages.Count + 1; i++)
                {
                    x = (float)i / (float)pdfDocument.Pages.Count;
                    y = (int)(x * 100);
                    backgroundWorker1.ReportProgress(y);
                    if (backgroundWorker1.CancellationPending)  // 如果用户取消则跳出处理数据代码
                    {
                        break;
                    }
                    using (FileStream imageStream = new FileStream(Path.Combine(outputPath, i.ToString() + ".jpeg"), FileMode.Create))
                    {
                        //Quality [0-100], 100 is Maximum
                        //create Resolution object
                        Resolution resolution = new Resolution(300);
                        JpegDevice jpegDevice = new JpegDevice(resolution, 100);

                        //convert a particular page and save the image to stream
                        //拆分
                        jpegDevice.Process(pdfDocument.Pages[i], imageStream);

                        //close stream
                        imageStream.Close();
                    }
                }
            }
        }
Beispiel #3
0
        private void HandleDocumentToImg(string filePath, string fullFileName, string imgType, ProgressNotice noticeCallback, int rowIndex)
        {
            Document pdfDocument = new Document(filePath);
            var      pageCount   = pdfDocument.Pages.Count;
            var      realPercent = 0.0;

            for (int pageIndex = 1; pageIndex <= pageCount; pageIndex++)
            {
                realPercent += (double)100 / pageCount;
                using (FileStream imageStream = new FileStream(fullFileName + "\\" + pageIndex + imgType,
                                                               FileMode.Create))
                {
                    Resolution resolution = new Resolution(300);
                    JpegDevice jpegDevice = new JpegDevice(resolution, 100);
                    jpegDevice.Process(pdfDocument.Pages[pageIndex], imageStream);
                    imageStream.Close();
                }
                if (pageIndex == pdfDocument.Pages.Count)
                {
                    realPercent = 100;
                }
                var noticeResult = new NoticeResult
                {
                    Success   = true,
                    rowIndex  = rowIndex,
                    pageIndex = pageIndex,
                    per       = (int)realPercent
                };
                this.Invoke(noticeCallback, noticeResult);
            }
        }
        public static void SinglePageToImage()
        {
           
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Images();

            // Open document
            Document pdfDocument = new Document(dataDir + "PagesToImages.pdf");
           
            using (FileStream imageStream = new FileStream(dataDir + "image" + 1 + ".jpg", FileMode.Create))
            {
                // Create JPEG device with specified attributes
                // Width, Height, Resolution, Quality
                // Quality [0-100], 100 is Maximum
                // Create Resolution object
                Resolution resolution = new Resolution(300);

                // JpegDevice jpegDevice = new JpegDevice(500, 700, resolution, 100);
                JpegDevice jpegDevice = new JpegDevice(resolution, 100);
                // ExStart:ConvertParticularPage
                // Convert a particular page and save the image to stream
                jpegDevice.Process(pdfDocument.Pages[1], imageStream);
                // ExEnd:ConvertParticularPage
                // Close stream
                imageStream.Close();
            }            
          
        }
        public static void Run()
        {
            // ExStart:PagesToImages
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
            
            // Open document
            Document pdfDocument = new Document(dataDir + "PagesToImages.pdf");

            for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
            {
                using (FileStream imageStream = new FileStream(dataDir + "image" + pageCount + "_out" + ".jpg", FileMode.Create))
                {
                    // Create JPEG device with specified attributes
                    // Width, Height, Resolution, Quality
                    // Quality [0-100], 100 is Maximum
                    // Create Resolution object
                    Resolution resolution = new Resolution(300);
                    
                    // JpegDevice jpegDevice = new JpegDevice(500, 700, resolution, 100);
                    JpegDevice jpegDevice = new JpegDevice(resolution, 100);

                    // Convert a particular page and save the image to stream
                    jpegDevice.Process(pdfDocument.Pages[pageCount], imageStream);

                    // Close stream
                    imageStream.Close();

                }
            }
            // ExEnd:PagesToImages
            System.Console.WriteLine("PDF pages are converted to individual images successfully!");
        }
        public static void SinglePageToImage()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Images();

            // Open document
            Document pdfDocument = new Document(dataDir + "PagesToImages.pdf");

            using (FileStream imageStream = new FileStream(dataDir + "image" + 1 + ".jpg", FileMode.Create))
            {
                // Create JPEG device with specified attributes
                // Width, Height, Resolution, Quality
                // Quality [0-100], 100 is Maximum
                // Create Resolution object
                Resolution resolution = new Resolution(300);

                // JpegDevice jpegDevice = new JpegDevice(500, 700, resolution, 100);
                JpegDevice jpegDevice = new JpegDevice(resolution, 100);
                // ExStart:ConvertParticularPage
                // Convert a particular page and save the image to stream
                jpegDevice.Process(pdfDocument.Pages[1], imageStream);
                // ExEnd:ConvertParticularPage
                // Close stream
                imageStream.Close();
            }
        }
        /// <summary>
        /// Efetua a conversão do PDF em imagens
        /// </summary>
        /// <param name="pdfPath">Caminho do PDF</param>
        /// <returns>Lista de caminhos das imagens por página</returns>
        public List<string> Convert(string pdfPath)
        {
            List<string> imagePaths = new List<string>();
            Document pdfDocument = new Document(pdfPath);

            for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
            {
                var imagePath = Path.Combine(Path.GetDirectoryName(pdfPath), "image" + pageCount + ".jpg");
                using (FileStream imageStream = new FileStream(imagePath, FileMode.Create))
                {
                    // Create Resolution object
                    Resolution resolution = new Resolution(300);
                    // Create JPEG device with specified attributes (Width, Height, Resolution, Quality)
                    // where Quality [0-100], 100 is Maximum
                    JpegDevice jpegDevice = new JpegDevice(resolution, 100);

                    // Convert a particular page and save the image to stream
                    jpegDevice.Process(pdfDocument.Pages[pageCount], imageStream);
                    // Close stream
                    imageStream.Close();
                }


                imagePaths.Add(imagePath);
            }

            return imagePaths;
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //open document
            Document pdfDocument = new Document(dataDir + "input.pdf");

            for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
            {
                using (FileStream imageStream = new FileStream(dataDir + "image" + pageCount + ".jpg", FileMode.Create))
                {
                    //create JPEG device with specified attributes
                    //Width, Height, Resolution, Quality
                    //Quality [0-100], 100 is Maximum
                    //create Resolution object
                    Resolution resolution = new Resolution(300);

                    //JpegDevice jpegDevice = new JpegDevice(500, 700, resolution, 100);
                    JpegDevice jpegDevice = new JpegDevice(resolution, 100);

                    //convert a particular page and save the image to stream
                    jpegDevice.Process(pdfDocument.Pages[pageCount], imageStream);

                    //close stream
                    imageStream.Close();

                }
            }

            System.Console.WriteLine("PDF pages are converted to individual images successfully!");
        }
        public static void Run()
        {
            // ExStart:CreateThumbnailImages
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Images();

            // Retrieve names of all the PDF files in a particular directory
            string[] fileEntries = Directory.GetFiles(dataDir, "*.pdf");

            // Iterate through all the files entries in array
            for (int counter = 0; counter < fileEntries.Length; counter++)
            {
                //Open document
                Document pdfDocument = new Document(fileEntries[counter]);

                for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
                {
                    using (FileStream imageStream = new FileStream(dataDir + "\\Thumbanils" + counter.ToString() + "_" + pageCount + ".jpg", FileMode.Create))
                    {
                        //Create Resolution object
                        Resolution resolution = new Resolution(300);
                        //JpegDevice jpegDevice = new JpegDevice(500, 700, resolution, 100);
                        JpegDevice jpegDevice = new JpegDevice(45, 59, resolution, 100);
                        //Convert a particular page and save the image to stream
                        jpegDevice.Process(pdfDocument.Pages[pageCount], imageStream);
                        //Close stream
                        imageStream.Close();
                    }
                }
            }
            // ExEnd:CreateThumbnailImages
            System.Console.WriteLine("PDF pages are converted to thumbnails successfully!");
        }
        private OutputDevice GetCorrectOutputDevice(Job job)
        {
            OutputDevice device;

            switch (job.Profile.OutputFormat)
            {
            case OutputFormat.PdfA1B:
            case OutputFormat.PdfA2B:
            case OutputFormat.PdfA3B:
            case OutputFormat.PdfX:
            case OutputFormat.Pdf:
                device = new PdfDevice(job);
                break;

            case OutputFormat.Png:
                device = new PngDevice(job);
                break;

            case OutputFormat.Jpeg:
                device = new JpegDevice(job);
                break;

            case OutputFormat.Tif:
                device = new TiffDevice(job);
                break;

            case OutputFormat.Txt:
                device = new TextDevice(job);
                break;

            default:
                throw new Exception("Illegal OutputFormat specified");
            }
            return(device);
        }
Beispiel #11
0
        ///<Summary>
        /// ConvertPdfToJpg method to convert PDF to JPG
        ///</Summary>
        public Response ConvertPdfToJpg(string fileName, string folderName)
        {
            return(ProcessTask(fileName, folderName, ".Jpg", true, "", true, delegate(string inFilePath, string outPath, string zipOutFolder)
            {
                Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(inFilePath);

                string outfileName = Path.GetFileNameWithoutExtension(fileName) + "_{0}";
                int totalPages = pdfDocument.Pages.Count;

                for (int pageCount = 1; pageCount <= totalPages; pageCount++)
                {
                    if (totalPages > 1)
                    {
                        outPath = zipOutFolder + "/" + outfileName;
                        outPath = string.Format(outPath, pageCount);
                    }
                    else
                    {
                        outPath = zipOutFolder + "/" + Path.GetFileNameWithoutExtension(fileName);
                    }

                    Resolution resolution = new Resolution(300);
                    JpegDevice jpgDevice = new JpegDevice(resolution);
                    jpgDevice.Process(pdfDocument.Pages[pageCount], outPath + ".Jpg");
                }
            }));
        }
Beispiel #12
0
        private static void test3()
        {
            // Open document
            Document pdfDocument = new Document(@"C:\Users\Giovanni\OneDrive\UTU\docs\DI038452553.pdf");

            for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
            {
                using (FileStream imageStream = new FileStream(@"C:\Users\Giovanni\OneDrive\UTU\docs\DI038452553.jpg", FileMode.Create))
                {
                    // Create JPEG device with specified attributes
                    // Width, Height, Resolution, Quality
                    // Quality [0-100], 100 is Maximum
                    // Create Resolution object
                    Resolution resolution = new Resolution(300);

                    // JpegDevice jpegDevice = new JpegDevice(500, 700, resolution, 100);
                    JpegDevice jpegDevice = new JpegDevice(resolution, 100);

                    // Convert a particular page and save the image to stream
                    jpegDevice.Process(pdfDocument.Pages[pageCount], imageStream);

                    // Close stream
                    imageStream.Close();
                }
            }
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_Images();

            //open document
            Document pdfDocument = new Document(dataDir + "PagesToImages.pdf");

            for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
            {
                using (FileStream imageStream = new FileStream(dataDir + "image" + pageCount + ".jpg", FileMode.Create))
                {
                    //create JPEG device with specified attributes
                    //Width, Height, Resolution, Quality
                    //Quality [0-100], 100 is Maximum
                    //create Resolution object
                    Resolution resolution = new Resolution(300);

                    //JpegDevice jpegDevice = new JpegDevice(500, 700, resolution, 100);
                    JpegDevice jpegDevice = new JpegDevice(resolution, 100);

                    //convert a particular page and save the image to stream
                    jpegDevice.Process(pdfDocument.Pages[pageCount], imageStream);

                    //close stream
                    imageStream.Close();
                }
            }

            System.Console.WriteLine("PDF pages are converted to individual images successfully!");
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //open document
            Document pdfDocument = new Document(dataDir + "input.pdf");

            for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
            {
                using (FileStream imageStream = new FileStream(dataDir + "image" + pageCount + ".jpg", FileMode.Create))
                {
                    //create Resolution object
                    Resolution resolution = new Resolution(300);
                    //create JPEG device with specified attributes (Width, Height, Resolution, Quality)
                    // where Quality [0-100], 100 is Maximum
                    JpegDevice jpegDevice = new JpegDevice(resolution, 100);

                    //convert a particular page and save the image to stream
                    jpegDevice.Process(pdfDocument.Pages[pageCount], imageStream);
                    //close stream
                    imageStream.Close();
                }
            }
        }
Beispiel #15
0
        public static OutputDevice GenerateDevice(OutputFormat outputFormat, IFile fileWrap = null)
        {
            var jobStub = GenerateJobStub(outputFormat);

            var fileStub = fileWrap ?? Substitute.For <IFile>();

            var osHelperStub = Substitute.For <IOsHelper>();

            osHelperStub.WindowsFontsFolder.Returns(WindowsFontsFolderDummie);

            var commandLineUtilStub = Substitute.For <ICommandLineUtil>();

            OutputDevice device = null;

            switch (outputFormat)
            {
            case OutputFormat.Jpeg:
                device = new JpegDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub);
                break;

            case OutputFormat.Pdf:
            case OutputFormat.PdfA1B:
            case OutputFormat.PdfA2B:
            case OutputFormat.PdfX:
                device = new PdfDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub);
                break;

            case OutputFormat.Png:
                device = new PngDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub);
                break;

            case OutputFormat.Tif:
                device = new TiffDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub);
                break;

            case OutputFormat.Txt:
                device = new TextDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub);
                break;
            }

            return(device);
        }
        public static OutputDevice GenerateDevice(OutputFormat outputFormat)
        {
            var jobStub = GenerateJobStub(outputFormat);

            var fileStub = MockRepository.GenerateStub <IFile>();

            var osHelperStub = MockRepository.GenerateStub <IOsHelper>();

            osHelperStub.Stub(x => x.WindowsFontsFolder).Return(WindowsFontsFolderDummie);

            var commandLineUtilStub = MockRepository.GenerateStub <ICommandLineUtil>();

            OutputDevice device = null;

            switch (outputFormat)
            {
            case OutputFormat.Jpeg:
                device = new JpegDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub);
                break;

            case OutputFormat.Pdf:
            case OutputFormat.PdfA1B:
            case OutputFormat.PdfA2B:
            case OutputFormat.PdfX:
                device = new PdfDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub);
                break;

            case OutputFormat.Png:
                device = new PngDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub);
                break;

            case OutputFormat.Tif:
                device = new TiffDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub);
                break;

            case OutputFormat.Txt:
                device = new TextDevice(jobStub, fileStub, osHelperStub, commandLineUtilStub);
                break;
            }

            return(device);
        }
Beispiel #17
0
        /// <summary>
        /// PDF转JPG
        /// </summary>
        /// <param name="filePath"></param>
        void Pdf2Image(string filePath)
        {
            var fileName = Path.GetFileNameWithoutExtension(filePath);
            var path     = Path.Combine(breadCrumbEdit_output.Path, fileName);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            using (var pdfDocument = new Document(filePath))
            {
                var            resolution      = new Resolution(300);
                var            jpegDeviceLarge = new JpegDevice(resolution, 100);
                PageCollection pc = pdfDocument.Pages;
                for (int i = 1, count = pc.Count, len = count.ToString().Length; i <= count; ++i)
                {
                    jpegDeviceLarge.Process(pc[i], Path.Combine(path, string.Format("{0}_{1}.jpg", fileName, i.ToString().PadLeft(len, '0'))));
                }
            }
        }
Beispiel #18
0
        private OutputDevice GetOutputDevice(Job job, ConversionMode conversionMode)
        {
            OutputDevice device;

            if (conversionMode == ConversionMode.IntermediateConversion)
            {
                return(new PdfIntermediateDevice(job));
            }

            switch (job.Profile.OutputFormat)
            {
            case OutputFormat.PdfA1B:
            case OutputFormat.PdfA2B:
            case OutputFormat.PdfA3B:
            case OutputFormat.PdfX:
            case OutputFormat.Pdf:
                device = new PdfDevice(job, conversionMode);
                break;

            case OutputFormat.Png:
                device = new PngDevice(job, conversionMode);
                break;

            case OutputFormat.Jpeg:
                device = new JpegDevice(job, conversionMode);
                break;

            case OutputFormat.Tif:
                device = new TiffDevice(job, conversionMode);
                break;

            case OutputFormat.Txt:
                device = new TextDevice(job, conversionMode);
                break;

            default:
                throw new Exception("Illegal OutputFormat specified");
            }
            return(device);
        }
Beispiel #19
0
        public void ToJpeg(string absoluteFilePath, string outputPath)
        {
            using (var pdfDocument = new Aspose.Pdf.Document(absoluteFilePath))
            {
                for (var i = 1; i < pdfDocument.Pages.Count + 1; i++)
                {
                    using (FileStream imageStream = new FileStream(Path.Combine(outputPath, i.ToString() + ".jpeg"), FileMode.Create))
                    {
                        //Quality [0-100], 100 is Maximum
                        //create Resolution object
                        Resolution resolution = new Resolution(300);
                        JpegDevice jpegDevice = new JpegDevice(resolution, 100);

                        //convert a particular page and save the image to stream
                        jpegDevice.Process(pdfDocument.Pages[i], imageStream);

                        //close stream
                        imageStream.Close();
                    }
                }
            }
        }
Beispiel #20
0
        private static void PdfToImage()
        {
            Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(@"C:\test.pdf");

            for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
            {
                using (FileStream imageStream = new FileStream(@"C:\PDFimage" + pageCount + ".jpg", FileMode.Create))
                {
                    // Create Resolution object
                    Resolution resolution = new Resolution(300);
                    // Create JPEG device with specified attributes (Width, Height, Resolution, Quality)
                    // where Quality [0-100], 100 is Maximum
                    JpegDevice jpegDevice = new JpegDevice(resolution, 100);

                    // Convert a particular page and save the image to stream
                    jpegDevice.Process(pdfDocument.Pages[pageCount], imageStream);
                    // Close stream
                    imageStream.Close();
                }
            }
            //Convert each page to PDF file
        }
Beispiel #21
0
        public async Task ProcessFilesAsync(IEnumerable <int> previewDelta, Func <Stream, string, Task> pagePreviewCallback,
                                            CancellationToken token)
        {
            var resolution = new Resolution(150);
            var jpegDevice = new JpegDevice(resolution, 90);
            var t          = new List <Task>();
            var doc        = _doc.Value;
            var diff       = Enumerable.Range(0, doc.Pages.Count).Except(previewDelta);

            foreach (int item in diff)
            {
                if (token.IsCancellationRequested)
                {
                    break;
                }
                var page = doc.Pages[item + 1];
                var ms   = new MemoryStream();
                jpegDevice.Process(page, ms);
                t.Add(pagePreviewCallback(ms, $"{item}.jpg").ContinueWith(_ => ms.Dispose(), token));
            }

            await Task.WhenAll(t);
        }
Beispiel #22
0
 private void pdf_to_ppt(save_progress progress, System.Windows.Forms.Form dlg, string fileType)
 {
     try
     {
         Aspose.Pdf.Document document = null;
         int num = 0;
         if (fileType == ".pdf")
         {
             document = this.pdf_doc;
             num      = 0;
         }
         else if ((fileType == ".doc") || (fileType == ".docx"))
         {
             document = this.doc_to_pdf(progress, dlg, 0);
             num      = 50;
         }
         else if ((fileType == ".xls") || (fileType == ".xlsx"))
         {
             document = this.xls_to_pdf(progress, dlg, 0);
             num      = 50;
         }
         Presentation presentation = new Presentation();
         JpegDevice   device       = new JpegDevice(new Resolution(300), 100);
         if (progress != null)
         {
             dlg.Invoke(progress, new object[] { num });
         }
         int num3 = 0;
         for (int i = 1; num3 < document.Pages.Count; i++)
         {
             presentation.Slides.AddEmptySlide(presentation.LayoutSlides[0]);
             presentation.Slides[num3].Shapes.AddAutoShape(Aspose.Slides.ShapeType.Rectangle, 10f, 20f, (float)this.global_config.pic_width, (float)this.global_config.pic_height);
             int num2 = presentation.Slides[num3].Shapes.Count - 1;
             presentation.Slides[num3].Shapes[num2].FillFormat.FillType = FillType.Picture;
             presentation.Slides[num3].Shapes[num2].FillFormat.PictureFillFormat.PictureFillMode = PictureFillMode.Stretch;
             MemoryStream output = new MemoryStream();
             device.Process(document.Pages[i], output);
             IPPImage image = presentation.Images.AddImage(new Bitmap(output));
             presentation.Slides[num3].Shapes[num2].FillFormat.PictureFillFormat.Picture.Image = image;
             if (progress != null)
             {
                 if (num == 50)
                 {
                     dlg.Invoke(progress, new object[] { ((num3 * 50) / document.Pages.Count) + 50 });
                 }
                 else
                 {
                     dlg.Invoke(progress, new object[] { (num3 * 100) / document.Pages.Count });
                 }
             }
             num3++;
         }
         presentation.Save(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + this.get_suffix(), Aspose.Slides.Export.SaveFormat.Ppt);
     }
     catch (Exception)
     {
         return;
     }
     if (progress != null)
     {
         dlg.Invoke(progress, new object[] { 100 });
     }
 }
Beispiel #23
0
        /// <summary>
        ///     Run the Job
        /// </summary>
        protected override JobState RunJobWork()
        {
            try
            {
                if (string.IsNullOrEmpty(Thread.CurrentThread.Name))
                {
                    Thread.CurrentThread.Name = "JobWorker";
                }
            }
            catch (InvalidOperationException)
            {
            }

            try
            {
                _ghostScript.Output += Ghostscript_Output;
                OnJobCompleted      += (sender, args) => _ghostScript.Output -= Ghostscript_Output;

                OutputFiles.Clear();

                Logger.Trace("Setting up actions");
                SetUpActions();

                Logger.Debug("Starting Ghostscript Job");

                OutputDevice device;
                switch (Profile.OutputFormat)
                {
                case OutputFormat.PdfA1B:
                case OutputFormat.PdfA2B:
                case OutputFormat.PdfX:
                case OutputFormat.Pdf:
                    device = new PdfDevice(this);
                    break;

                case OutputFormat.Png:
                    device = new PngDevice(this);
                    break;

                case OutputFormat.Jpeg:
                    device = new JpegDevice(this);
                    break;

                case OutputFormat.Tif:
                    device = new TiffDevice(this);
                    break;

                case OutputFormat.Txt:
                    device = new TextDevice(this);
                    break;

                default:
                    throw new Exception("Illegal OutputFormat specified");
                }

                Logger.Trace("Output format is: {0}", Profile.OutputFormat.ToString());

                _ghostScript.Output += Ghostscript_Logging;
                var success = _ghostScript.Run(device, JobTempFolder);
                _ghostScript.Output -= Ghostscript_Logging;

                Logger.Trace("Finished Ghostscript execution");

                if (!success)
                {
                    var errorMessage = ExtractGhostscriptErrors(GhostscriptOutput);
                    Logger.Error("Ghostscript execution failed: " + errorMessage);
                    ErrorMessage = errorMessage;

                    JobState = JobState.Failed;
                    return(JobState);
                }

                ProcessOutput();

                Logger.Trace("Moving output files to final location");
                MoveOutputFiles();

                Logger.Trace("Finished Ghostscript Job");
                JobState = JobState.Succeeded;
                return(JobState);
            }
            catch (ProcessingException)
            {
                JobState = JobState.Failed;
                throw;
            }
            catch (DeviceException)
            {
                JobState = JobState.Failed;
                throw;
            }
            catch (Exception ex)
            {
                JobState = JobState.Failed;
                Logger.Error("There was an error while converting the Job {0}: {1}", JobInfo.InfFile, ex);
                throw;
            }
        }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        int SchoolID = info.getId();

        if (btnAdd.Text == "تسجيل الوارد")
        {
            Incoming inc = new Incoming();

            inc.Number = txtIncomingID.Text;
            //  inc.Date = Convert.ToDateTime(txtDate.Text);

            if (Calendar1.CultureName == "ar-SA")
            {
                inc.Date = MyDate.convertHijriToGregorian(txtDate.Text);
            }
            else
            {
                inc.Date = Convert.ToDateTime(txtDate.Text);
            }

            inc.Source     = int.Parse(ddlFrom.SelectedValue);
            inc.Subject    = txtSubject.Text;
            inc.SemesterId = MyDate.getCurrentSemesterId();
            inc.FileNumber = txtFileNumber.Text;
            inc.SchoolId   = SchoolID;
            inc.Type       = int.Parse(ddlType.SelectedValue);
            inc.Attachment = int.Parse(ddlFileAttach.SelectedValue);
            inc.IsDeleted  = false;


            var fileLocation = pdfFrame.Attributes["src"];
            ose.Incomings.Add(inc);
            ose.SaveChanges();

            if (!String.IsNullOrEmpty(fileLocation))
            {
                inc.FileLocation = fileLocation.Substring(2, fileLocation.Length - 2);

                var      path        = MapPath("~/");
                Document pdfDocument = new Document(path + "testImage.pdf");

                Resolution resolution = new Resolution(300);
                JpegDevice jpegDevice = new JpegDevice(resolution, 100);

                var x = pdfDocument.Pages.Count;

                for (int i = 1; i <= x; ++i)
                {
                    string filename = "images/Incomings/" + Guid.NewGuid() + ".jpg";
                    jpegDevice.Process(pdfDocument.Pages[i], path + filename);

                    IncomingsImage img = new IncomingsImage();
                    img.IncomingId = inc.Id;
                    img.Image      = filename;
                    ose.IncomingsImages.Add(img);
                }
            }

            ose.SaveChanges();

            /******************************************************************************************************************/
            List <Employee>      empLst = new List <Employee>();
            OnlineSchoolEntities km     = new OnlineSchoolEntities();

            if (RadioType.SelectedValue == "1")
            {
                empLst = (from k in km.Employees where k.SchoolId == SchoolID select k).ToList();
            }
            else
            if (RadioType.SelectedValue == "2")
            {
                foreach (ListViewItem item in LstJopEmployees.Items)
                {
                    CheckBox che = (CheckBox)item.FindControl("chkRow");
                    if (che.Checked)
                    {
                        var jobid = int.Parse(((HiddenField)item.FindControl("HiddenField2")).Value);

                        foreach (var emp in km.Employees)
                        {
                            if (emp.JobId == jobid && emp.SchoolId == SchoolID)
                            {
                                empLst.Add(emp);
                            }
                        }
                    }
                }

                foreach (ListViewItem item in LstEmp.Items)
                {
                    CheckBox che = (CheckBox)item.FindControl("chkRow");
                    if (che.Checked)
                    {
                        var userId = ((HiddenField)item.FindControl("HiddenField1")).Value;

                        empLst.Add((from k in km.Employees where k.IdentityNumber == userId select k).FirstOrDefault());
                    }
                }

                foreach (ListViewItem item in LstSpecification.Items)
                {
                    CheckBox che = (CheckBox)item.FindControl("chkRow");
                    if (che.Checked)
                    {
                        UsersTask ut            = new UsersTask();
                        string    specification = ((Label)item.FindControl("NameLabel")).Text;

                        foreach (Employee emp in km.Employees)
                        {
                            if (emp.Specification == specification && emp.SchoolId == SchoolID)
                            {
                                empLst.Add(emp);
                            }
                        }
                    }
                }
            }
            foreach (Employee emp in empLst.Distinct())
            {
                if (emp.SchoolId == SchoolID)
                {
                    UsersGeneralization userGeneralization = new UsersGeneralization();
                    userGeneralization.UserId     = emp.IdentityNumber;
                    userGeneralization.IncomingId = inc.Id;
                    userGeneralization.isSeen     = false;

                    km.UsersGeneralizations.Add(userGeneralization);
                    km.SaveChanges();
                    //    lblerror.Text = "تم الاضافة بنجاح";
                }
            }

            /*******************************************************************************************************************/

            //lblerror.Text = "تمت اضافة الوارد بنجاح";
            //IncId.Value = (inc.Id).ToString();
            // lnkTask.NavigateUrl = "~/Communication/TaskAdd.aspx?type=Incoming&typeId=" + inc.Id;
            ClientScript.RegisterStartupScript(this.GetType(), "openModal", "<script> openModal(); </script>", false);
            clear();
        }
        else
        {
            int id = int.Parse(Request.QueryString["id"].ToString());
            var c  = (from k in ose.Incomings where k.Id == id select k).FirstOrDefault();

            c.Number     = txtIncomingID.Text;
            c.FileNumber = txtFileNumber.Text;
            //   c.Date = Convert.ToDateTime(txtDate.Text);
            try
            {
                if (Calendar1.CultureName == "ar-SA")
                {
                    c.Date = MyDate.convertHijriToGregorian(txtDate.Text);
                }
                else
                {
                    c.Date = Convert.ToDateTime(txtDate.Text);
                }
            }catch (Exception ex)
            {
                txtDate.Text      = "";
                lblDateError.Text = "الرجاء ادخال تاريخ صحيح";
                return;
            }
            c.Source     = int.Parse(ddlFrom.SelectedValue);
            c.Subject    = txtSubject.Text;
            c.Type       = int.Parse(ddlType.SelectedValue);
            c.Attachment = int.Parse(ddlFileAttach.SelectedValue);

            var fileLocation = pdfFrame.Attributes["src"];
            if (!String.IsNullOrEmpty(fileLocation))
            {
                c.FileLocation = fileLocation.Substring(2, fileLocation.Length - 2);
            }
            ose.SaveChanges();
            //PlaceHolderSuccess.Visible = true;
            //lblerror.Text = "تم تعديل الوارد بنجاح";
            //IncId.Value = (c.Id).ToString();
            //  lnkTask.NavigateUrl = "~/Communication/TaskAdd.aspx?type=Incoming&typeId=" + c.Id;
            ClientScript.RegisterStartupScript(this.GetType(), "openModal", "<script> openModal(); </script>", false);
        }
    }
        public ActionResult Upload(HttpPostedFileBase file)
        {
            string path = Server.MapPath("~/Areas/Admin/Files/" + file.FileName);
            string ext  = System.IO.Path.GetExtension(file.FileName);

            string[] nameFielCV = file.FileName.Split('.');
            if (String.Compare(ext.ToLower(), "pdf") == 0)
            {
                @ViewBag.Path = "Bạn chỉ có thể tải lên file PDF";
            }
            else
            {
                file.SaveAs(path);
                @ViewBag.Path = path;
                //@ViewBag.Path = "Test"+ExtractTextFromPdf(path);
                Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(path);

                int pageNum = pdfDoc.Pages.Count;
                // Response.Write("Hello--" + pageNum);
                XImage[] image = new XImage[pageNum];

                String NoiSoanCV, SoCV, TieuDeCV, NoiDungCV, NoiNhanCV, ChuKyCV, filePath;
                NoiSoanCV = SoCV = TieuDeCV = NoiDungCV = NoiNhanCV = ChuKyCV = filePath = "";
                Color c;
                for (int i = 1; i <= pageNum; i++)
                {
                    Bitmap         bt;
                    UnmanagedImage sourceimage;
                    BitmapData     cloneBitmapCopyC;
                    filePath = rootPath + file.FileName + nameFielCV[0] + i + ".bmp";
                    if (!System.IO.File.Exists(filePath))
                    {
                        using (FileStream imageStream = new FileStream(rootPath + nameFielCV[0] + i + ".bmp", FileMode.Create))
                        {
                            // Create Resolution object
                            Resolution resolution = new Resolution(300);
                            // Create JPEG device with specified attributes (Width, Height, Resolution, Quality)
                            // where Quality [0-100], 100 is Maximum
                            JpegDevice jpegDevice = new JpegDevice(resolution, 100);

                            // Convert a particular page and save the image to stream
                            jpegDevice.Process(pdfDoc.Pages[i], imageStream);
                            // Close stream
                            imageStream.Close();
                        }
                        // Thao tác với bt
                        bt = (Bitmap)Bitmap.FromFile((rootPath + nameFielCV[0] + i + ".bmp"));
                        bt.SetResolution(192f, 192f);
                        cloneBitmapCopyC = bt.LockBits(new System.Drawing.Rectangle(0, 114, bt.Width, bt.Height - 114), System.Drawing.Imaging.ImageLockMode.ReadWrite, bt.PixelFormat);
                        sourceimage      = new UnmanagedImage(cloneBitmapCopyC);

                        // chuyển thành ảnh cấp xám xong Nhi Phan (Đen thành đen , Trắng Thành Trắng)
                        for (int m = 0; m < sourceimage.Width; m++)
                        {
                            for (int j = 0; j < sourceimage.Height; j++)
                            {
                                c = sourceimage.GetPixel(m, j);
                                //c.R = 0; // màu đen
                                int grayScale = (int)((c.R * 0.3) + (c.G * 0.59) + (c.B * 0.11));
                                sourceimage.SetPixel(m, j, Color.FromArgb(c.A, grayScale, grayScale, grayScale));
                                if (c.R < 140)
                                {
                                    sourceimage.SetPixel(m, j, Color.Black);
                                }
                                else
                                {
                                    sourceimage.SetPixel(m, j, Color.White);
                                }
                            }
                        }
                        bt       = sourceimage.ToManagedImage();
                        bt       = Crop(bt);
                        filePath = rootPath + nameFielCV[0] + "output_grayCV" + i + ".bmp";
                        if (!System.IO.File.Exists(filePath))
                        {
                            FileStream output_gray = new FileStream((rootPath + nameFielCV[0] + "output_grayCV" + i + ".bmp"), FileMode.Create);
                            bt.Save(output_gray, System.Drawing.Imaging.ImageFormat.Jpeg);
                            output_gray.Dispose();
                            output_gray.Close();
                        }
                    }
                    else
                    {
                        // Thao tác với bt
                        bt = (Bitmap)Bitmap.FromFile((rootPath + nameFielCV[0] + "output_grayCV" + i + ".bmp"));
                        cloneBitmapCopyC = bt.LockBits(new System.Drawing.Rectangle(0, 0, bt.Width, bt.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bt.PixelFormat);
                        sourceimage      = new UnmanagedImage(cloneBitmapCopyC);
                    }

                    sourceimage = UnmanagedImage.FromManagedImage(bt);

                    String nameFile = "";
                    if (i == 1)
                    {
                        int ht, hs;
                        ht = hs = 0;

                        //Cắt tiêu đề
                        nameFile = nameFielCV[0] + "donviSoanCV";
                        Dictionary <string, int> dictionaryheightDV = CropImgae(cloneBitmapCopyC, bt, sourceimage, ht, nameFile);
                        ht = dictionaryheightDV["height"] + (int)1.3 * dictionaryheightDV["heighd"];
                        Bitmap dvCV = (Bitmap)Bitmap.FromFile((rootPath + nameFile + ".bmp"));
                        NoiSoanCV = GetText(dvCV);

                        //cắt số công văn
                        nameFile = nameFielCV[0] + "soCV";
                        Dictionary <string, int> dictionaryheightSoCV = CropImgae(cloneBitmapCopyC, bt, sourceimage, ht, nameFile);
                        ht = ht + dictionaryheightSoCV["height"];
                        Bitmap soCV = (Bitmap)Bitmap.FromFile((rootPath + nameFile + ".bmp"));
                        SoCV = GetText(soCV);

                        //cắt tiêu đề công văn
                        nameFile = nameFielCV[0] + "TieuDeCV";
                        Dictionary <string, int> dictionaryheightTieuDeCV = CropImgae(cloneBitmapCopyC, bt, sourceimage, ht, nameFile);
                        Bitmap TieuDeCVBit = (Bitmap)Bitmap.FromFile((rootPath + nameFile + ".bmp"));
                        ht = ht + dictionaryheightTieuDeCV["height"];
                        if (ht > 460)
                        {
                            ht = ht + (int)(2 * dictionaryheightTieuDeCV["heighd"]);
                        }
                        TieuDeCV = GetText(TieuDeCVBit);

                        //cắt nội dung
                        nameFile = nameFielCV[0] + "NoiDungCV";
                        BitmapData cloneBitmapNoiDungCV = bt.LockBits(new System.Drawing.Rectangle(0, ht, sourceimage.Width, sourceimage.Height - ht), System.Drawing.Imaging.ImageLockMode.ReadWrite, bt.PixelFormat);

                        UnmanagedImage titileImage = new UnmanagedImage(cloneBitmapNoiDungCV);
                        Bitmap         imgTitile   = titileImage.ToManagedImage();
                        filePath = rootPath + nameFile + ".bmp";
                        if (!System.IO.File.Exists(filePath))
                        {
                            FileStream output_title = new FileStream((rootPath + nameFile + ".bmp"), FileMode.Create);
                            imgTitile.Save(output_title, System.Drawing.Imaging.ImageFormat.Jpeg);
                            output_title.Dispose();
                            output_title.Close();
                        }
                        Bitmap NoiDungCVBit = (Bitmap)Bitmap.FromFile((rootPath + nameFile + ".bmp"));
                        NoiDungCV = GetText(NoiDungCVBit);
                    }
                    if (i == pageNum)
                    {
                        //cắt nơi nhận, chữ ký
                        bool kt = false;
                        for (int k = (int)(0.98 * bt.Height); k < bt.Height; k++)
                        {
                            c = sourceimage.GetPixel((int)(0.5 * bt.Width), k);
                            if (c.R == 0)
                            {
                                kt = true; break;
                            }
                        }
                        if (kt)
                        {
                            BitmapData cloneBitmapPageEnd = bt.LockBits(new System.Drawing.Rectangle(0, 0, bt.Width, bt.Height - 114), System.Drawing.Imaging.ImageLockMode.ReadWrite, bt.PixelFormat);
                            sourceimage = new UnmanagedImage(cloneBitmapPageEnd);
                            bt          = sourceimage.ToManagedImage();
                            bt          = Crop(bt);
                            nameFile    = nameFielCV[0] + "PageEndCV";
                            filePath    = rootPath + nameFile + ".bmp";
                            if (!System.IO.File.Exists(filePath))
                            {
                                FileStream PageEndCV = new FileStream((rootPath + nameFile + ".bmp"), FileMode.Create);
                                bt.Save(PageEndCV, System.Drawing.Imaging.ImageFormat.Jpeg);
                                PageEndCV.Dispose();
                                PageEndCV.Close();
                            }
                            sourceimage = UnmanagedImage.FromManagedImage(bt);
                            //bt.UnlockBits(cloneBitmapPageEnd);
                        }

                        //cắt chữ ký
                        nameFile = nameFielCV[0] + "ChuKyCV";
                        BitmapData cloneBitmapChuKyCV = bt.LockBits(new System.Drawing.Rectangle((int)(0.5 * sourceimage.Width), (int)(0.9 * sourceimage.Height), (int)(0.4 * sourceimage.Width), sourceimage.Height - (int)(0.9 * sourceimage.Height)), System.Drawing.Imaging.ImageLockMode.ReadWrite, bt.PixelFormat);

                        UnmanagedImage ChuKyImage  = new UnmanagedImage(cloneBitmapChuKyCV);
                        Bitmap         ChuKyTitile = ChuKyImage.ToManagedImage();
                        ChuKyTitile = Crop(ChuKyTitile);
                        filePath    = rootPath + nameFile + ".bmp";
                        if (!System.IO.File.Exists(filePath))
                        {
                            FileStream output_ChuKy = new FileStream((rootPath + nameFile + ".bmp"), FileMode.Create, FileAccess.ReadWrite);
                            ChuKyTitile.Save(output_ChuKy, System.Drawing.Imaging.ImageFormat.Jpeg);
                            output_ChuKy.Dispose();
                            output_ChuKy.Close();
                        }

                        bt.UnlockBits(cloneBitmapChuKyCV);
                        Bitmap ChuKyCVBit = (Bitmap)Bitmap.FromFile((rootPath + nameFile + ".bmp"));
                        ChuKyCV = GetText(ChuKyCVBit);

                        // cắt nơi nhận

                        nameFile = nameFielCV[0] + "NoiNhanCV";
                        BitmapData cloneBitmapNoiNhanCV;
                        if (!kt)
                        {
                            cloneBitmapNoiNhanCV = bt.LockBits(new System.Drawing.Rectangle(0, (int)(0.8 * (sourceimage.Height)), (int)(0.5 * sourceimage.Width), sourceimage.Height - (int)(0.8 * sourceimage.Height) - 50), System.Drawing.Imaging.ImageLockMode.ReadWrite, bt.PixelFormat);
                        }
                        else
                        {
                            cloneBitmapNoiNhanCV = bt.LockBits(new System.Drawing.Rectangle(0, (int)(0.6 * (sourceimage.Height - 10)), (int)(0.5 * sourceimage.Width), sourceimage.Height - (int)(0.6 * sourceimage.Height) - 50), System.Drawing.Imaging.ImageLockMode.ReadWrite, bt.PixelFormat);
                        }

                        UnmanagedImage NoiNhanImage  = new UnmanagedImage(cloneBitmapNoiNhanCV);
                        Bitmap         NoiNhanTitile = NoiNhanImage.ToManagedImage();
                        NoiNhanTitile = Crop(NoiNhanTitile);
                        filePath      = rootPath + nameFile + ".bmp";
                        if (!System.IO.File.Exists(filePath))
                        {
                            FileStream output_NoiNhan = new FileStream((rootPath + nameFile + ".bmp"), FileMode.Create);
                            NoiNhanTitile.Save(output_NoiNhan, System.Drawing.Imaging.ImageFormat.Jpeg);
                            output_NoiNhan.Dispose();
                            output_NoiNhan.Close();
                        }

                        Bitmap NoiNhanCVBit = (Bitmap)Bitmap.FromFile((rootPath + nameFile + ".bmp"));
                        NoiNhanCV = GetText(NoiNhanCVBit);
                        bt.UnlockBits(cloneBitmapChuKyCV);
                    }
                }
                //Lưu thông tin vừa cắt vào cơ sở dữ liệu
                row data = new row();
                //NoiSoanCV, SoCV, TieuDeCV, NoiDungCV, NoiNhanCV, ChuKyCV;
                data.from_org        = NoiSoanCV;
                data.number_dispatch = SoCV;
                data.title           = TieuDeCV;
                data._abstract       = NoiDungCV;
                data.to_org          = NoiNhanCV;
                data.name_signer     = ChuKyCV;
                data.attach_file     = file.FileName;
                try
                {
                    db.rows.Add(data);
                    db.SaveChanges();

                    return(RedirectToAction("List", "CongVan"));
                }
                catch (Exception e)
                {
                    string x = e.InnerException.ToString();
                    return(RedirectToAction("Index"));
                }
            }

            return(View());
        }
Beispiel #26
0
 private void pdf_to_img(save_progress progress, System.Windows.Forms.Form dlg, string fileType)
 {
     try
     {
         Aspose.Pdf.Document document = null;
         int num = 0;
         if (fileType == ".pdf")
         {
             document = this.pdf_doc;
             num      = 0;
         }
         else if ((fileType == ".doc") || (fileType == ".docx"))
         {
             document = this.doc_to_pdf(progress, dlg, 0);
             num      = 50;
         }
         else if ((fileType == ".xls") || (fileType == ".xlsx"))
         {
             document = this.xls_to_pdf(progress, dlg, 0);
             num      = 50;
         }
         else if ((fileType == ".ppt") || (fileType == ".pptx"))
         {
             document = this.ppt_to_pdf(progress, dlg, 0);
             num      = 50;
         }
         if (document != null)
         {
             try
             {
                 JpegDevice device = new JpegDevice(new Resolution(300), 100);
                 if (progress != null)
                 {
                     dlg.Invoke(progress, new object[] { num });
                 }
                 for (int i = 1; i <= document.Pages.Count; i++)
                 {
                     device.Process(document.Pages[i], this.global_config.target_dic + i.ToString() + this.get_suffix());
                     if (progress != null)
                     {
                         if (num == 50)
                         {
                             dlg.Invoke(progress, new object[] { ((i * 50) / document.Pages.Count) + 50 });
                         }
                         else
                         {
                             dlg.Invoke(progress, new object[] { (i * 100) / document.Pages.Count });
                         }
                     }
                 }
             }
             catch (Exception)
             {
                 return;
             }
             if (progress != null)
             {
                 dlg.Invoke(progress, new object[] { 100 });
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }