Beispiel #1
0
 /// <summary>
 /// Returns available FileConvertor from ConcurrentBag collection by conversion type (if there is any).
 /// Otherwise create one and return it.
 /// </summary>
 /// <param name="inConversionType"></param>
 /// <returns></returns>
 public static FileConverter GetObject(ConversionType inConversionType)
 {
     FileConverter fileConverter;
     if (!GetConverterInstancesByType(inConversionType).TryTake(out fileConverter))
         fileConverter = new FileConverter(inConversionType);
     return fileConverter;
 }
Beispiel #2
0
        /// <summary>
        /// Walking traverse all folders under inRoot looking for PDF files need to convert to JPG.
        /// </summary>
        /// <param name="inFileConvertor"></param>
        /// <param name="inRoot"></param>
        /// <param name="inTargetFolderPath"></param>
        /// <param name="inConvertFileWildCard"></param>
        /// <param name="inDeleteSourcePDF"></param>
        /// <param name="inSearchSubFolders"> If true traverse each sub-folders and convert them, except if one of the sub-folders is the target folder. </param>
        /// <param name="inSameTargetFolder"> If false create new sub folder under target folder path with the same name as the root sub-folder. </param>
        /// <param name="inResolutionX"></param>
        /// <param name="inResolutionY"></param>
        private bool WalkDirectoryTreePDF2JPG(FileConverter inFileConvertor, 
            System.IO.DirectoryInfo inRoot,
            string inTargetFolderPath,
            string inConvertFileWildCard,
            bool inDeleteSourcePDF,
            bool inSearchSubFolders,
            bool inSameTargetFolder,
            double inResolutionX,
            double inResolutionY,
            double inGraphicsAlphaBitsValue,
            double inTextAlphaBitsValue,
            double inQuality)
        {
            bool fileConversion;

            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;

            // First, process all the files directly under this folder
            files = inRoot.GetFiles(inConvertFileWildCard);

            if (files != null)
            {
                foreach (System.IO.FileInfo file in files)
                {
                    // Make file conversion.
                    fileConversion = inFileConvertor.ConvertPDF2JPG(file.FullName, inTargetFolderPath, inResolutionX, inResolutionY, inGraphicsAlphaBitsValue, inTextAlphaBitsValue, inQuality);
                    if (!fileConversion)
                        return false;

                    //Delete old files.
                    if (inDeleteSourcePDF)
                        FileDelete(file.FullName);

                    // Rename JPG names to the correct page counter.
                    RenameImagesNames(inTargetFolderPath, file.FullName, "jpg");
                }

                if (inSearchSubFolders)
                {
                    // Now find all the subdirectories under this directory.
                    subDirs = inRoot.GetDirectories();
                    foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                    {
                        // In case the target folder is sub directory of the converted folder don't check it.
                        if (inTargetFolderPath.Contains(dirInfo.FullName))
                            continue;
                        if (!inSameTargetFolder)
                        {
                            //Create a new sub folder under target folder path
                            string newPath = System.IO.Path.Combine(inTargetFolderPath, dirInfo.Name);
                            //Create the sub folder
                            System.IO.Directory.CreateDirectory(newPath);
                            //Recursive call for each subdirectory.
                            WalkDirectoryTreePDF2JPG(inFileConvertor, dirInfo, newPath, inConvertFileWildCard, inDeleteSourcePDF, inSearchSubFolders, inSameTargetFolder, inResolutionX, inResolutionY, inGraphicsAlphaBitsValue, inTextAlphaBitsValue, inQuality);
                        }
                        else
                        {
                            // Recursive call for each subdirectory.
                            WalkDirectoryTreePDF2JPG(inFileConvertor, dirInfo, dirInfo.FullName, inConvertFileWildCard, inDeleteSourcePDF, inSearchSubFolders, inSameTargetFolder, inResolutionX, inResolutionY, inGraphicsAlphaBitsValue, inTextAlphaBitsValue, inQuality);
                        }

                    }
                }

            }

            return true;
        }
Beispiel #3
0
 /// <summary>
 /// Return used FileConvertor to ConcurrentBag collection by conversion type.
 /// </summary>
 /// <param name="inConversionType"></param>
 /// <param name="inFileConvertor"></param>
 public static void PutObject(ConversionType inConversionType, FileConverter inFileConvertor)
 {
     GetConverterInstancesByType(inConversionType).Add(inFileConvertor);
 }
Beispiel #4
0
        /// <summary>
        /// Walking traverse all folders under inRoot looking for PDF files need to convert to EPS.
        /// </summary>
        /// <param name="inFileConvertor"></param>
        /// <param name="inRoot"></param>
        /// <param name="inTargetFolderPath"></param>
        /// <param name="inConvertFileWildCard"></param>
        /// <param name="inDeleteSourcePDF"></param>
        /// <param name="inSearchSubFolders"> If true traverse each sub-folders and convert them, except if one of the sub-folders is the target folder. </param>
        /// <param name="inSameTargetFolder"> If false create new sub folder under target folder path with the same name as the root sub-folder. </param>
        /// <param name="inFirstPageToConvert"></param>
        /// <param name="inLastPageToConvert"></param>
        /// <returns></returns>
        private bool WalkDirectoryTreePDF2EPS(FileConverter inFileConvertor, System.IO.DirectoryInfo inRoot, string inTargetFolderPath, string inConvertFileWildCard,
            bool inDeleteSourcePDF, bool inSearchSubFolders, bool inSameTargetFolder, double inFirstPageToConvert, double inLastPageToConvert)
        {
            bool fileConversion;

            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;

            // First, process all the files directly under this folder
            files = inRoot.GetFiles(inConvertFileWildCard);

            if (files != null)
            {
                foreach (System.IO.FileInfo file in files)
                {
                    // Create converted EPS path.
                    string convertedEPSPath = inTargetFolderPath + "\\" + Path.GetFileNameWithoutExtension(file.FullName) + ".eps";

                    // Make file conversion.
                    fileConversion = inFileConvertor.ConvertPDF2EPS(file.FullName, convertedEPSPath, inFirstPageToConvert, inLastPageToConvert);
                    if (!fileConversion)
                        return false;

                    //Delete old files.
                    if (inDeleteSourcePDF)
                        FileDelete(file.FullName);
                }

                if (inSearchSubFolders)
                {
                    // Now find all the subdirectories under this directory.
                    subDirs = inRoot.GetDirectories();
                    foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                    {
                        // In case the target folder is sub directory of the converted folder don't check it.
                        if (inTargetFolderPath.Contains(dirInfo.FullName))
                            continue;

                        if (!inSameTargetFolder)
                        {
                            //Create new sub folder under target folder path
                            string newPath = System.IO.Path.Combine(inTargetFolderPath, dirInfo.Name);
                            //Create the sub folder
                            System.IO.Directory.CreateDirectory(newPath);
                            //Recursive call for each subdirectory.
                            WalkDirectoryTreePDF2EPS(inFileConvertor, dirInfo, newPath, inConvertFileWildCard, inDeleteSourcePDF, inSearchSubFolders, inSameTargetFolder, inFirstPageToConvert, inLastPageToConvert);
                        }
                        else
                        {
                            // Recursive call for each subdirectory.
                            WalkDirectoryTreePDF2EPS(inFileConvertor, dirInfo, dirInfo.FullName, inConvertFileWildCard, inDeleteSourcePDF, inSearchSubFolders, inSameTargetFolder, inFirstPageToConvert, inLastPageToConvert);
                        }

                    }
                }

            }

            return true;
        }