예제 #1
0
        /// <summary>
        /// Walking traverse all folders under inRoot looking for PDF files need to convert to PNG.
        /// </summary>
        /// <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>
        private bool WalkDirectoryTreePDF2PNG(FileConverter inFileConvertor,
                                              System.IO.DirectoryInfo inRoot,
                                              string inTargetFolderPath,
                                              string inConvertFileWildCard,
                                              bool inDeleteSourcePDF,
                                              bool inSearchSubFolders,
                                              bool inSameTargetFolder,
                                              double inResolutionX,
                                              double inResolutionY,
                                              double inGraphicsAlphaBitsValue,
                                              double inTextAlphaBitsValue)
        {
            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.ConvertPDF2PNG(file.FullName, inTargetFolderPath, inResolutionX, inResolutionY, inGraphicsAlphaBitsValue, inTextAlphaBitsValue);
                    if (!fileConversion)
                    {
                        return(false);
                    }

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


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

                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.
                            WalkDirectoryTreePDF2PNG(inFileConvertor, dirInfo, newPath, inConvertFileWildCard, inDeleteSourcePDF, inSearchSubFolders, inSameTargetFolder, inResolutionX, inResolutionY, inGraphicsAlphaBitsValue, inTextAlphaBitsValue);
                        }
                        else
                        {
                            // Recursive call for each subdirectory.
                            WalkDirectoryTreePDF2PNG(inFileConvertor, dirInfo, dirInfo.FullName, inConvertFileWildCard, inDeleteSourcePDF, inSearchSubFolders, inSameTargetFolder, inResolutionX, inResolutionY, inGraphicsAlphaBitsValue, inTextAlphaBitsValue);
                        }
                    }
                }
            }

            return(true);
        }
예제 #2
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);
        }
예제 #3
0
 /// <summary>
 /// Return used FileConvertor to ConcurrentBag collection by conversion type.
 /// </summary>
 /// <param name="inConversionType"></param>
 /// <param name="inFileConvertor"></param>
 static public void PutObject(ConversionType inConversionType, FileConverter inFileConvertor)
 {
     GetConverterInstancesByType(inConversionType).Add(inFileConvertor);
 }