using PDF_Office.Model.PDFTool; using PDF_Office.Properties; using PDFSettings; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PDF_Office.Helper { /// /// 预设需求:远程控制对PDF工具进行排序 /// public enum PDFToolType { /// /// 普通工具 /// Normal, /// /// 常用工具 /// Common, /// ///付费工具 /// Payment, /// /// 优势工具 /// Advantage, /// /// 无需打开文档 /// NoNeedToOpenDoc } public enum PDFFnType { Split, Extract, Insert, Compress, Merge, Print, Security, ConvertPDF, PDFToWord, PDFToExcel, PDFToPPT, ImageToPDF, OCR, WaterMark, HeaderFooter, BatesNumbers, Batch, Background, CompareDoc } /// /// PDF工具初始化类型 /// internal class PDFToolsInit { public ToolItem toolItem { get; private set; } public PDFToolsInit() { toolItem = new ToolItem(); } /// /// 图标 /// public void SetImagePath(string path) { toolItem.FnImg = path; } /// /// 初始化UI显示内容 /// public void SetContent(string fnName,string fnInfo) { toolItem.FnName = fnName; toolItem.FnInfo = fnInfo; } /// /// 初始化功能 /// public void SetFnType(PDFFnType fnType) { toolItem.FnType = fnType; } } public class PDFToolsHelper { public List AllTools = null; public List QuickTools = null; public List MoreTools = null; private static PDFToolsHelper pDFToolsHelper; public const int QuickToolCount = 8;//快捷工具显示的个数 public static PDFToolsHelper GetInstance() { if (pDFToolsHelper == null) pDFToolsHelper = new PDFToolsHelper(); return pDFToolsHelper; } private PDFToolsHelper() { InitPDFTools(); } private void InitPDFTools() { AllTools = new List(); QuickTools = new List(); MoreTools = new List(); //测试代码 //Settings.Default.AllPDFToolsList.Clear(); //Settings.Default.QuickPDFToolsList.Clear(); //Settings.Default.Save(); InitAllTools(); InitQuickTools(); InitMoreTools(); // ContianNewTools(); } private void InitAllTools() { var split = new PDFToolsInit(); split.SetFnType(PDFFnType.Split); split.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/split.png"); split.SetContent("拆分", "Batch convert, compress, secure, watermark PDFs."); var extract = new PDFToolsInit(); extract.SetFnType(PDFFnType.Extract); extract.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/extract.png"); extract.SetContent("提取", "Batch convert, compress, secure, watermark PDFs."); var insert = new PDFToolsInit(); insert.SetFnType(PDFFnType.Insert); insert.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/insert.png"); insert.SetContent("插入", "Batch convert, compress, secure, watermark PDFs."); var compress = new PDFToolsInit(); compress.SetFnType(PDFFnType.Compress); compress.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/compress.png"); compress.SetContent("压缩", "Batch convert, compress, secure, watermark PDFs."); var merge = new PDFToolsInit(); merge.SetFnType(PDFFnType.Merge); merge.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/merge.png"); merge.SetContent("合并", "Batch convert, compress, secure, watermark PDFs."); var print = new PDFToolsInit(); print.SetFnType(PDFFnType.Print); print.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/print.png"); print.SetContent("打印", "Batch convert, compress, secure, watermark PDFs."); var security = new PDFToolsInit(); security.SetFnType(PDFFnType.Security); security.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/security.png"); security.SetContent("安全", "Batch convert, compress, secure, watermark PDFs."); var convertPDF = new PDFToolsInit(); convertPDF.SetFnType(PDFFnType.ConvertPDF); convertPDF.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/convert.png"); convertPDF.SetContent("转档PDF", "Batch convert, compress, secure, watermark PDFs."); var pDFToWord = new PDFToolsInit(); pDFToWord.SetFnType(PDFFnType.PDFToWord); pDFToWord.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/pdf-to-word.png"); pDFToWord.SetContent("PDF转Word", "Batch convert, compress, secure, watermark PDFs."); var pDFToExcel = new PDFToolsInit(); pDFToExcel.SetFnType(PDFFnType.PDFToExcel); pDFToExcel.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/pdf-to-excel.png"); pDFToExcel.SetContent("PDF转Excel", "Batch convert, compress, secure, watermark PDFs."); var pDFToPPT = new PDFToolsInit(); pDFToPPT.SetFnType(PDFFnType.PDFToPPT); pDFToPPT.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/pdf-to-ppt.png"); pDFToPPT.SetContent("PDF转PPT", "Batch convert, compress, secure, watermark PDFs."); var imageToPDF = new PDFToolsInit(); imageToPDF.SetFnType(PDFFnType.ImageToPDF); imageToPDF.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/image.png"); imageToPDF.SetContent("图片转PDF", "Batch convert, compress, secure, watermark PDFs."); var oCR = new PDFToolsInit(); oCR.SetFnType(PDFFnType.OCR); oCR.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/ocr.png"); oCR.SetContent("OCR", "Batch convert, compress, secure, watermark PDFs."); var waterMark = new PDFToolsInit(); waterMark.SetFnType(PDFFnType.WaterMark); waterMark.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/watermark.png"); waterMark.SetContent("水印", "Batch convert, compress, secure, watermark PDFs."); var headerFooter = new PDFToolsInit(); headerFooter.SetFnType(PDFFnType.HeaderFooter); headerFooter.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/header&footer.png"); headerFooter.SetContent("页眉页脚", "Batch convert, compress, secure, watermark PDFs."); var batesNumbers = new PDFToolsInit(); batesNumbers.SetFnType(PDFFnType.BatesNumbers); batesNumbers.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/batesnumbers.png"); batesNumbers.SetContent("贝茨Bates码", "Batch convert, compress, secure, watermark PDFs."); var batch = new PDFToolsInit(); batch.SetFnType(PDFFnType.Batch); batch.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/batch.png"); batch.SetContent("批量处理", "Batch convert, compress, secure, watermark PDFs."); var background = new PDFToolsInit(); background.SetFnType(PDFFnType.Background); background.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/background.png"); background.SetContent("背景", "Batch convert, compress, secure, watermark PDFs."); var compareDoc = new PDFToolsInit(); compareDoc.SetFnType(PDFFnType.CompareDoc); compareDoc.SetImagePath(@"pack://application:,,,/Resources/HomeIcon/PDFTools/compress.png"); compareDoc.SetContent("文件对比", "Batch convert, compress, secure, watermark PDFs."); AllTools.Add(split.toolItem); AllTools.Add(extract.toolItem); AllTools.Add(insert.toolItem); AllTools.Add(compress.toolItem); AllTools.Add(merge.toolItem); AllTools.Add(print.toolItem); AllTools.Add(security.toolItem); AllTools.Add(convertPDF.toolItem); AllTools.Add(pDFToWord.toolItem); AllTools.Add(pDFToExcel.toolItem); AllTools.Add(pDFToPPT.toolItem); AllTools.Add(imageToPDF.toolItem); AllTools.Add(oCR.toolItem); AllTools.Add(waterMark.toolItem); AllTools.Add(headerFooter.toolItem); AllTools.Add(batesNumbers.toolItem); AllTools.Add(batch.toolItem); AllTools.Add(background.toolItem); AllTools.Add(compareDoc.toolItem); } /// /// 检查是否为新增工具 /// private void ContianNewTools() { var cacheList = Settings.Default.AllPDFToolsList; foreach (var item in AllTools) { ToolItem toolItem = null; foreach (var cacheItem in cacheList) { var strFnTye = Enum.GetName(typeof(PDFFnType), item.FnType); if (cacheItem.FnTypeStr != strFnTye && cacheItem.IsNewTool == true) { toolItem = item; break; } } if(toolItem != null && toolItem.IsNewTool == true) { CacheToolItem cacheTool = new CacheToolItem(); cacheTool.IsNewTool = true; cacheTool.ToolTypeId = toolItem.ToolTypeId; cacheTool.ToolTypeStr = Enum.GetName(typeof(PDFToolType), toolItem.ToolType); cacheTool.FnTypeStr = Enum.GetName(typeof(PDFFnType), toolItem.FnType); Settings.Default.AllPDFToolsList.Add(cacheTool); } } Settings.Default.Save(); } /// /// 快捷工具 /// private void InitQuickTools() { var cacheList = Settings.Default.AllPDFToolsList; if (cacheList == null) cacheList = new AllPDFToolsList(); if(cacheList.Count > 0) { int currentCount = 0; foreach (var cacheItem in cacheList) { if (cacheItem.ToolLayOutType == 1 && currentCount < QuickToolCount) { foreach (var allItem in AllTools) { if (cacheItem.FnTypeStr == Enum.GetName(typeof(PDFFnType), allItem.FnType)) { allItem.IsQuickTool = true; var index = QuickTools.FindIndex(t => t.ToolTypeId > allItem.ToolTypeId); if (index == -1) { allItem.ToolTypeId = cacheItem.ToolTypeId; QuickTools.Add(allItem); } else { allItem.ToolTypeId = index; QuickTools.Insert(index, allItem); } currentCount++; break; } } } } } else { //当所有工具大于等于快捷工具显示的个数时 if (AllTools.Count >= QuickToolCount) { for (int i = 0; i < QuickToolCount; i++) { AllTools[i].ToolTypeId = i; AllTools[i].IsQuickTool = true; QuickTools.Add(AllTools[i]); } } else { for (int i = 0; i < AllTools.Count; i++) { AllTools[i].ToolTypeId = i; AllTools[i].IsQuickTool = true; QuickTools.Add(AllTools[i]); } } SaveAllTools(); } } private void SaveAllTools() { var cacheList = Settings.Default.AllPDFToolsList; foreach (var item in AllTools) { CacheToolItem cacheItem = new CacheToolItem(); cacheItem.ToolLayOutType = (item.IsQuickTool == true ? 1 : 0); cacheItem.IsNewTool = item.IsNewTool; cacheItem.ToolTypeId = item.ToolTypeId; cacheItem.ToolTypeStr = Enum.GetName(typeof(PDFToolType), item.ToolType); cacheItem.FnTypeStr = Enum.GetName(typeof(PDFFnType), item.FnType); cacheList.Add(cacheItem); } Settings.Default.Save(); } private void InitMoreTools() { int currentCount = 0; foreach (var allItem in AllTools) { if (allItem.IsQuickTool == false) { allItem.ToolTypeId = currentCount; MoreTools.Add(allItem); currentCount++; } } } public void SaveCacheList() { var cacheLists = Settings.Default.AllPDFToolsList; CacheToolItem cacheItem = null; foreach (var item in AllTools) { cacheItem = cacheLists.Find(t => t.FnTypeStr == Enum.GetName(typeof(PDFFnType), item.FnType)); if (cacheItem != null) { cacheItem.ToolTypeId = item.ToolTypeId; cacheItem.ToolLayOutType = (item.IsQuickTool == true ? 1 : 0); } } Settings.Default.Save(); } } }