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_Office.Model.EditTools.Bates;
namespace PDF_Office.Helper
{
public static class HomePageEditHelper
{
///
/// 获取所需要分文档份数
///
/// 文档总页数
/// 平均几页分为一个文档
/// 最后文档的页数的引用 例如11页文档每3页为一份PDF,3,3,3,2,remainder=2
///
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;
}
///
/// 获取平均每个文档的页数
///
/// 文档总页数
/// 平均几页分为一个文档
/// 引用,截至第几位文档比后面文档多一 例如11页文档 分为3份 4,4,3 remainder为2 第一个文档和第二文档比后续文档多一
///
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 PageIndexLists = new List();
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)
.Replace("<>", m + "/" + d + "/" + yy)
.Replace("<>", m + "/" + d + "/" + yyyy)
.Replace("<>", mm + "/" + dd + "/" + yy)
.Replace("<>", mm + "/" + dd + "/" + yyyy)
.Replace("<>", d + "/" + m + "/" + yy)
.Replace("<>", d + "/" + m + "/" + yyyy)
.Replace("<>", dd + "/" + mm + "/" + yy)
.Replace("<>", dd + "/" + mm + "/" + yyyy)
.Replace("<>", mm + "/" + yy)
.Replace("<>", mm + "/" + yyyy)
.Replace("<>", m + "." + d + "." + yy)
.Replace("<>", m + "." + d + "." + yyyy)
.Replace("<>", mm + "." + dd + "." + yy)
.Replace("<>", mm + "." + dd + "." + yyyy)
.Replace("<>", mm + "." + yy)
.Replace("<>", mm + "." + yyyy)
.Replace("<>", d + "." + m + "." + yy)
.Replace("<>", d + "." + m + "." + yyyy)
.Replace("<>", dd + "." + mm + "." + yy)
.Replace("<>", dd + "." + mm + "." + yyyy)
.Replace("<>", yy + "-" + mm + "-" + dd)
.Replace("<>", yyyy + "-" + mm + "-" + dd)
.Replace("<<1 of n>>", "<<1>>" + " of " + Document.PageCount)
.Replace("<<1/n>>", "<<1>>" + "/" + Document.PageCount)
.Replace("<>", "Page" + "<<1>>")
.Replace("<>", "Page " + "<<1>>" + " of " + Document.PageCount);
return str;
}
}
}