Exemplo n.º 1
0
        public bool ConvertPDF2PNG(string inConvertFilePath,
                                   string inNewFileTargetFolderPath,
                                   double inResolutionX,
                                   double inResolutionY,
                                   double inGraphicsAlphaBitsValue,
                                   double inTextAlphaBitsValue)
        {
            //          logger.Info("inConvertFilePath = " + inConvertFilePath + ", inNewFileTargetFolderPath = " + inNewFileTargetFolderPath +
            //                      ", inResolutionX = " + inResolutionX + ", inResolutionY = " + inResolutionY + ", inGraphicsAlphaBitsValue = " + inGraphicsAlphaBitsValue +
            //                      ", inTextAlphaBitsValue = " + inTextAlphaBitsValue + ");

            bool conversionSucceed;

            CheckBaseParamsValidation(inResolutionX, inResolutionY, inGraphicsAlphaBitsValue, inTextAlphaBitsValue);

            // Make the conversion.
            FileConverter fileConvertor = InstancesManager.GetObject(InstancesManager.ConversionType.PDF2PNG);

            conversionSucceed = fileConvertor.ConvertPDF2PNG(inConvertFilePath, inNewFileTargetFolderPath, inResolutionX, inResolutionY, inGraphicsAlphaBitsValue, inTextAlphaBitsValue);
            InstancesManager.PutObject(InstancesManager.ConversionType.PDF2PNG, fileConvertor);

            // Rename PNG names to the correct page counter.
            RenameImagesNames(inNewFileTargetFolderPath, inConvertFilePath, "png");


            return(conversionSucceed);
        }
Exemplo n.º 2
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);
        }