public bool ConvertPDF2EPS(string inConvertFilePath, string inNewFileTargetPath, double inFirstPageToConvert, double inLastPageToConvert) { // logger.Info("inConvertFilePath = " + inConvertFilePath + ", inNewFileTargetPath = " + inNewFileTargetPath + // ", inFirstPageToConvert = " + inFirstPageToConvert + ", inLastPageToConvert = " + inLastPageToConvert); bool conversionSucceed; // Make the conversion. FileConverter fileConvertor = InstancesManager.GetObject(InstancesManager.ConversionType.PDF2EPS); conversionSucceed = fileConvertor.ConvertPDF2EPS(inConvertFilePath, inNewFileTargetPath, inFirstPageToConvert, inLastPageToConvert); InstancesManager.PutObject(InstancesManager.ConversionType.PDF2EPS, fileConvertor); return(conversionSucceed); }
/// <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); }