public bool ConvertPDF2JPG(string inConvertFilePath, string inNewFileTargetFolderPath, double inResolutionX, double inResolutionY, double inGraphicsAlphaBitsValue, double inTextAlphaBitsValue, double inQuality) { // logger.Info("inConvertFilePath = " + inConvertFilePath + ", inNewFileTargetFolderPath = " + inNewFileTargetFolderPath + // ", inResolutionX = " + inResolutionX + ", inResolutionY = " + inResolutionY + ", inGraphicsAlphaBitsValue = " + inGraphicsAlphaBitsValue + // ", inTextAlphaBitsValue = " + inTextAlphaBitsValue + ", inQuality = " + inQuality); bool conversionSucceed; CheckJPGParamValidation(inResolutionX, inResolutionY, inGraphicsAlphaBitsValue, inTextAlphaBitsValue, inQuality); // Make the conversion. FileConverter fileConvertor = InstancesManager.GetObject(InstancesManager.ConversionType.PDF2JPG); conversionSucceed = fileConvertor.ConvertPDF2JPG(inConvertFilePath, inNewFileTargetFolderPath, inResolutionX, inResolutionY, inGraphicsAlphaBitsValue, inTextAlphaBitsValue, inQuality); InstancesManager.PutObject(InstancesManager.ConversionType.PDF2JPG, fileConvertor); // Rename JPG names to the correct page counter. RenameImagesNames(inNewFileTargetFolderPath, inConvertFilePath, "jpg"); return(conversionSucceed); }
/// <summary> /// Walking traverse all folders under inRoot looking for PDF files need to convert to JPG. /// </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 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); }