Exemplo n.º 1
0
        /// <summary>
        /// Extract images from PDF and compress into a cbr archive
        /// </summary>
        private void ConvertPdfToCbr(string currentFile)
        {
            evnt_UpdateFileName(this, e);
            //creating directory for extraction
            string tempFileName = Path.GetFileName(currentFile);

            temporaryDir = currentFile;
            temporaryDir = temporaryDir.Replace(tempFileName, Path.GetFileNameWithoutExtension(currentFile));

            // replace with new output
            var SourceFolder = DataAccess.Instance.g_WorkingDir.Replace(Path.GetFileName(DataAccess.Instance.g_WorkingDir), "");

            temporaryDir = temporaryDir.Replace(SourceFolder, DataAccess.Instance.g_Output_dir + "\\");

            //if the directory already exist, delete it
            if (Directory.Exists(temporaryDir))
            {
                Directory.Delete(temporaryDir, true);
            }
            Directory.CreateDirectory(temporaryDir);


            int divider;

            if (_ReduceSize)
            {
                divider = 50;
            }
            else
            {
                divider = 80;
            }


            var result = PdfFunctions.PDF_ExportImage(currentFile, temporaryDir, divider, _CheckImagesPages, _JoinImages);

            if (result.ImagesAfterMerge != result.Pages)
            {
                evnt_ErrorNotify(this, string.Format("{0} : {1} images for {2} pages!", currentFile, result.ImagesAfterMerge, result.Pages));
            }

            if (DataAccess.Instance.g_Processing)
            {
                //compress files in a zip
                if (_ReduceSize)
                {
                    CompressImage();
                }

                string savedfile = temporaryDir + ".cbz";


                using (ZipFile zip = new ZipFile())
                {
                    zip.AddDirectory(temporaryDir);
                    // zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G");
                    zip.Save(savedfile);
                }

                //waiting the new sharpcompress release to fix it

                /*  using (var archive = ZipArchive.Create())
                 * {
                 *    archive.AddAllFromDirectory(temporaryDir);
                 *    archive.SaveTo(savedfile, CompressionType.None);
                 * }*/
            }


            //delete the temp dir
            if (Directory.Exists(temporaryDir))
            {
                Directory.Delete(temporaryDir, true);
            }



            //if we are converting a single file and not a directory we are done, so i reset values and clean the UI
            if (IsSingleFile)
            {
                DataAccess.Instance.g_Processing  = false;
                DataAccess.Instance.g_WorkingFile = string.Empty;
                evnt_UpdateFileName(this, e);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Extract images from PDF and compress into a cbr archive
        /// </summary>
        private void CompressSingleFile()
        {
            evnt_UpdateFileName(this, e);
            //creating directory for extraction
            string tempFileName = Path.GetFileName(DataAccess.Instance.g_WorkingFile);
            string temporaryDir = DataAccess.Instance.g_WorkingFile;

            temporaryDir = temporaryDir.Replace(tempFileName, Path.GetFileNameWithoutExtension(DataAccess.Instance.g_WorkingFile));

            //if the directory already exist, delete it
            if (Directory.Exists(temporaryDir))
            {
                Directory.Delete(temporaryDir, true);
            }
            Directory.CreateDirectory(temporaryDir);


            int divider;

            if (_ReduceSize)
            {
                divider = 50;
            }
            else
            {
                divider = 80;
            }


            if (PdfFunctions.PDF_ExportImage(DataAccess.Instance.g_WorkingFile, temporaryDir, divider))
            {
                if (DataAccess.Instance.g_Processing)
                {
                    //compress files in a zip
                    if (_ReduceSize)
                    {
                        CompressImage();
                    }

                    string savedfile = temporaryDir + ".cbz";


                    using (ZipFile zip = new ZipFile())
                    {
                        zip.AddDirectory(temporaryDir);
                        // zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G");
                        zip.Save(savedfile);
                    }

                    //waiting the new sharpcompress release to fix it

                    /*  using (var archive = ZipArchive.Create())
                     * {
                     *    archive.AddAllFromDirectory(temporaryDir);
                     *    archive.SaveTo(savedfile, CompressionType.None);
                     * }*/


                    //update progress bar
                    DataAccess.Instance.g_curProgress = 0;
                    evnt_UpdateCurBar();
                }
            }
            else //error exporting the images
            {
                //update progress bar
                DataAccess.Instance.g_curProgress = 0;
                evnt_UpdateCurBar();
            }
            //delete the temp dir
            if (Directory.Exists(temporaryDir))
            {
                Directory.Delete(temporaryDir, true);
            }



            //if we are converting a single file and not a directory we are done, so i reset values and clean the UI
            if (IsSingleFile)
            {
                DataAccess.Instance.g_Processing  = false;
                DataAccess.Instance.g_WorkingFile = string.Empty;
                evnt_UpdateFileName(this, e);
            }
        }