123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using ComPDFKitViewer.PdfViewer;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Documents;
- using static System.Windows.Forms.VisualStyles.VisualStyleElement;
- using ComPDFKit.PDFDocument;
- using PDF_Master.Model.EditTools.Bates;
- namespace PDF_Master.Helper
- {
- public static class HomePageEditHelper
- {
- /// <summary>
- /// 获取所需要分文档份数
- /// </summary>
- /// <param name="pagecontent">文档总页数</param>
- /// <param name="averagepage">平均几页分为一个文档</param>
- /// <param name="remainder">最后文档的页数的引用 例如11页文档每3页为一份PDF,3,3,3,2,remainder=2</param>
- /// <returns></returns>
- public static int AverageSplitPages(int pagecontent, int averagepage, ref int remainder)
- {
- if (pagecontent <= 0)
- {
- remainder = 0;
- return 0;
- }
- if (pagecontent <= averagepage)
- {
- remainder = pagecontent;
- return 1;
- }
- if (pagecontent > averagepage)
- {
- if (pagecontent % averagepage == 0)
- {
- remainder = 0;
- return pagecontent / averagepage;
- }
- remainder = pagecontent % averagepage;
- return (pagecontent / averagepage) + 1;
- }
- remainder = 0;
- return -1;
- }
- /// <summary>
- /// 获取平均每个文档的页数
- /// </summary>
- /// <param name="pagecontent">文档总页数</param>
- /// <param name="averagedoc">平均几页分为一个文档</param>
- /// <param name="remainder">引用,截至第几位文档比后面文档多一 例如11页文档 分为3份 4,4,3 remainder为2 第一个文档和第二文档比后续文档多一</param>
- /// <returns></returns>
- public static int AverageSplitDocs(int pagecontent, int averagedoc, ref int remainder)
- {
- if (pagecontent <= 0)
- {
- remainder = 0;
- return 0;
- }
- if (pagecontent <= averagedoc)
- {
- remainder = 0;
- return 1;
- }
- if (pagecontent > averagedoc)
- {
- remainder = pagecontent % averagedoc;
- return pagecontent / averagedoc;
- }
- return 0;
- }
- public static void GetPagerange(string PageRangeSelectIndex, CPDFViewer currentViewer, ref string pageRange, string pageRangeText, bool currentpage = false, string currentPageRange="1")
- {
- if (!currentpage)
- {
- if (PageRangeSelectIndex == "0")
- {
- pageRange = "1-" + currentViewer.Document.PageCount.ToString();
- Trace.WriteLine(" extractModel.PageRange" + pageRange);
- }
- else if (PageRangeSelectIndex == "1")
- {
- pageRange = "1";
- for (int i = 3; i <= currentViewer.Document.PageCount; i += 2)
- pageRange = pageRange + "," + i;
- Trace.WriteLine(" extractModel.PageRange" + pageRange);
- }
- else if (PageRangeSelectIndex == "2")
- {
- pageRange = "2";
- for (int i = 4; i <= currentViewer.Document.PageCount; i += 2)
- pageRange = pageRange + "," + i;
- Trace.WriteLine(" extractModel.PageRange" + pageRange);
- }
- else if (PageRangeSelectIndex == "3")
- {
- if (pageRangeText != "")
- {
- pageRange = pageRangeText;
- }
- Trace.WriteLine(" extractModel.PageRange" + pageRange);
- }
- else { return; }
- }
- else
- {
- if (PageRangeSelectIndex == "0")
- {
- pageRange = "1-" + currentViewer.Document.PageCount.ToString();
- Trace.WriteLine(" extractModel.PageRange" + pageRange);
- }
- if (PageRangeSelectIndex == "1")
- {
- pageRange = currentPageRange;
- Trace.WriteLine(" extractModel.PageRange" + pageRange);
- }
- else if (PageRangeSelectIndex == "2")
- {
- pageRange = "1";
- for (int i = 3; i <= currentViewer.Document.PageCount; i += 2)
- pageRange = pageRange + "," + i;
- Trace.WriteLine(" extractModel.PageRange" + pageRange);
- }
- else if (PageRangeSelectIndex == "3")
- {
- pageRange = "2";
- for (int i = 4; i <= currentViewer.Document.PageCount; i += 2)
- pageRange = pageRange + "," + i;
- Trace.WriteLine(" extractModel.PageRange" + pageRange);
- }
- else if (PageRangeSelectIndex == "4")
- {
- if (pageRangeText != "")
- {
- pageRange = pageRangeText;
- }
- Trace.WriteLine(" extractModel.PageRange" + pageRange);
- }
- else { return; }
- }
- }
- public static string UpDataPageRange(int pagecount,string pagerange) {
- List<int> PageIndexLists = new List<int>();
- string str = "";
- if(CommonHelper.GetPagesInRange(ref PageIndexLists, pagerange, 9999, new char[] { ',' }, new char[] { '-' }))
- {
-
- foreach (var PageIndex in PageIndexLists) {
- int pageindex = PageIndex + 1;
- if (pageindex<= pagecount)
- {
- str = str + pageindex.ToString();
- str = str + ",";
- }
- }
- if(str=="")
- return str;
- return str.Remove(str.LastIndexOf(","),1);
- }
- return str;
- }
- public static string ReverseDate(string str,CPDFDocument Document)
- {
- string yyyy = DateTime.Now.ToString("yyyy");
- string yy = DateTime.Now.ToString("yy");
- string mm = DateTime.Now.ToString("MM");
- string m = DateTime.Now.ToString("%M");
- string dd = DateTime.Now.ToString("dd");
- string d = DateTime.Now.ToString("%d");
- str = str.Replace("<<m/d>>", m + "/" + d)
- .Replace("<<m/d/yy>>", m + "/" + d + "/" + yy)
- .Replace("<<m/d/yyyy>>", m + "/" + d + "/" + yyyy)
- .Replace("<<mm/dd/yy>>", mm + "/" + dd + "/" + yy)
- .Replace("<<mm/dd/yyyy>>", mm + "/" + dd + "/" + yyyy)
- .Replace("<<d/m/yy>>", d + "/" + m + "/" + yy)
- .Replace("<<d/m/yyyy>>", d + "/" + m + "/" + yyyy)
- .Replace("<<dd/mm/yy>>", dd + "/" + mm + "/" + yy)
- .Replace("<<dd/mm/yyyy>>", dd + "/" + mm + "/" + yyyy)
- .Replace("<<mm/yy>>", mm + "/" + yy)
- .Replace("<<mm/yyyy>>", mm + "/" + yyyy)
- .Replace("<<m.d.yy>>", m + "." + d + "." + yy)
- .Replace("<<m.d.yyyy>>", m + "." + d + "." + yyyy)
- .Replace("<<mm.dd.yy>>", mm + "." + dd + "." + yy)
- .Replace("<<mm.dd.yyyy>>", mm + "." + dd + "." + yyyy)
- .Replace("<<mm.yy>>", mm + "." + yy)
- .Replace("<<mm.yyyy>>", mm + "." + yyyy)
- .Replace("<<d.m.yy>>", d + "." + m + "." + yy)
- .Replace("<<d.m.yyyy>>", d + "." + m + "." + yyyy)
- .Replace("<<dd.mm.yy>>", dd + "." + mm + "." + yy)
- .Replace("<<dd.mm.yyyy>>", dd + "." + mm + "." + yyyy)
- .Replace("<<yy-mm-dd>>", yy + "-" + mm + "-" + dd)
- .Replace("<<yyyy-mm-dd>>", yyyy + "-" + mm + "-" + dd)
- .Replace("<<1 of n>>", "<<1>>" + " of " + Document.PageCount)
- .Replace("<<1/n>>", "<<1>>" + "/" + Document.PageCount)
- .Replace("<<Page 1>>", "Page" + "<<1>>")
- .Replace("<<Page 1 of n>>", "Page " + "<<1>>" + " of " + Document.PageCount);
- return str;
- }
- }
- }
|