|
@@ -18,6 +18,9 @@ using Prism.Events;
|
|
|
using ComPDFKitViewer.PdfViewer;
|
|
|
using PDF_Office.EventAggregators;
|
|
|
using PDFSettings;
|
|
|
+using PDF_Office.Model.EditTools.Bates;
|
|
|
+using PDF_Office.Model.EditTools.Background;
|
|
|
+using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrayNotify;
|
|
|
|
|
|
namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageBackground
|
|
|
{
|
|
@@ -26,11 +29,14 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
|
|
|
#region 参数和属性
|
|
|
private List<string> fileNames;
|
|
|
|
|
|
+ public BackgroundInfo BackgroundInfo;
|
|
|
|
|
|
private CPDFDocument tempDocument;
|
|
|
|
|
|
public string PageNumber = "";
|
|
|
|
|
|
+ private CPDFBackground background;
|
|
|
+
|
|
|
public IRegionManager backgroundRegion;
|
|
|
public IEventAggregator eventAggregator;
|
|
|
|
|
@@ -184,6 +190,30 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private string createGridSpan = "1";
|
|
|
+ public string CreateGridSpan
|
|
|
+ {
|
|
|
+ get { return createGridSpan; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref createGridSpan, value);
|
|
|
+ RaisePropertyChanged();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Visibility createGridSpanVisibility = Visibility.Visible;
|
|
|
+ public Visibility CreateGridSpanVisibility
|
|
|
+ {
|
|
|
+ get { return createGridSpanVisibility; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref createGridSpanVisibility, value);
|
|
|
+ RaisePropertyChanged();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
#region 委托声明
|
|
@@ -228,10 +258,14 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
|
|
|
EnumTemplateListOrCreate enumTemplateListOrCreate = enumTemplateListOrCreateunicode.Status;
|
|
|
if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
|
|
|
{
|
|
|
+ CreateGridSpan = "1";
|
|
|
+ CreateGridSpanVisibility = Visibility.Visible;
|
|
|
EnterSelectedContent(TemplateListBaseName);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ CreateGridSpan = "2";
|
|
|
+ CreateGridSpanVisibility = Visibility.Collapsed;
|
|
|
EnterSelectedContent(CreateBaseName);
|
|
|
}
|
|
|
}
|
|
@@ -239,6 +273,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
|
|
|
{
|
|
|
NavigationParameters param = new NavigationParameters();
|
|
|
param.Add(ParameterNames.PDFViewer, PDFViewer);
|
|
|
+ param.Add("ViewModel", this);
|
|
|
if (SelectedContentName == TemplateListBaseName)
|
|
|
{
|
|
|
param.Add("CurrentCreateModName", CurrentCreateMod);
|
|
@@ -286,6 +321,8 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
|
|
|
param.Add("BackgroundItem", backgroundItem);
|
|
|
backgroundRegion.RequestNavigate(BackgroundSettingsRegionName, CreateBaseName, param);
|
|
|
BackgroundSettingsVisible = Visibility.Visible;
|
|
|
+ CreateGridSpan = "2";
|
|
|
+ CreateGridSpanVisibility = Visibility.Collapsed;
|
|
|
}
|
|
|
|
|
|
private void create()
|
|
@@ -295,34 +332,72 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
|
|
|
BackgroundGridIsEnabled = "False";
|
|
|
foreach (var filename in fileNames)
|
|
|
{
|
|
|
- // FileInfo fileinfo = new FileInfo(filename);
|
|
|
- // string OutputPath = fileinfo.DirectoryName;
|
|
|
- // char[] enumerationSeparator = new char[] { ',' };
|
|
|
- // char[] rangeSeparator = new char[] { '-' };
|
|
|
- // List<int> PageIndexLists = new List<int>();
|
|
|
- // CPDFDocument document = CPDFDocument.InitWithFilePath(filename);
|
|
|
- // if (document == null)
|
|
|
- // {
|
|
|
- // PDFDataTable.Rows[fileNamesIndex]["FileState"] = "文件出错";
|
|
|
- // continue;
|
|
|
- // }
|
|
|
- // if (!CommonHelper.GetPagesInRange(ref PageIndexLists, "1-" + document.PageCount.ToString(), document.PageCount, enumerationSeparator, rangeSeparator))
|
|
|
- // { //TODO
|
|
|
- // Trace.WriteLine("输入不对");
|
|
|
- // MessageBoxEx.Show("输入不对");
|
|
|
- // return;
|
|
|
- // }
|
|
|
-
|
|
|
- // document.Release();
|
|
|
- PDFDataTable.Rows[fileNamesIndex]["FilePageRangeSelectIndex"] = "2";
|
|
|
+ FileInfo fileinfo = new FileInfo(filename);
|
|
|
+ string OutputPath = fileinfo.DirectoryName;
|
|
|
+ char[] enumerationSeparator = new char[] { ',' };
|
|
|
+ char[] rangeSeparator = new char[] { '-' };
|
|
|
+ List<int> PageIndexLists = new List<int>();
|
|
|
+ CPDFDocument document = CPDFDocument.InitWithFilePath(filename);
|
|
|
+ if (document == null)
|
|
|
+ {
|
|
|
+ PDFDataTable.Rows[fileNamesIndex]["FileState"] = "文件出错";
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ CreateBackground(document);
|
|
|
+ document.WriteToFilePath(filename + "_Background.pdf");
|
|
|
+ // if (!CommonHelper.GetPagesInRange(ref PageIndexLists, "1-" + document.PageCount.ToString(), document.PageCount, enumerationSeparator, rangeSeparator))
|
|
|
+ // { //TODO
|
|
|
+ // Trace.WriteLine("输入不对");
|
|
|
+ // MessageBoxEx.Show("输入不对");
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // document.Release();
|
|
|
+ //PDFDataTable.Rows[fileNamesIndex]["FilePageRangeSelectIndex"] = "2";
|
|
|
PDFDataTable.Rows[fileNamesIndex]["FileState"] = "完成";
|
|
|
- PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeText"] = "2";
|
|
|
- PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeSelectIndex"] = "2";
|
|
|
+ //PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeText"] = "2";
|
|
|
+ //PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeSelectIndex"] = "2";
|
|
|
PDFCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "完成";
|
|
|
fileNamesIndex++;
|
|
|
}
|
|
|
BackgroundGridIsEnabled = "True";
|
|
|
}
|
|
|
+
|
|
|
+ public void CreateBackground(CPDFDocument document)
|
|
|
+ {
|
|
|
+ if (BackgroundInfo != null)
|
|
|
+ {
|
|
|
+ background = document.GetBackground();
|
|
|
+ if (BackgroundInfo.BackgroundType == C_Background_Type.BG_TYPE_COLOR)
|
|
|
+ {
|
|
|
+ background.SetBackgroundType(C_Background_Type.BG_TYPE_COLOR);
|
|
|
+ background.SetColor(BackgroundInfo.Color);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ background.SetBackgroundType(C_Background_Type.BG_TYPE_IMAGE);
|
|
|
+ background.SetImage(BackgroundInfo.ImageArray, BackgroundInfo.ImageWidth, BackgroundInfo.ImageHeight, ComPDFKit.Import.C_Scale_Type.fitCenter);
|
|
|
+ }
|
|
|
+ if (!BackgroundInfo.IsRelativeScale)
|
|
|
+ {
|
|
|
+ background.SetScale(1);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ background.SetScale((float)(BackgroundInfo.Scale / 100));
|
|
|
+ }
|
|
|
+ background.SetRotation((float)((BackgroundInfo.Rotation / 180) * Math.PI));
|
|
|
+ background.SetOpacity((byte)(((float)BackgroundInfo.Opacity / 100) * 255));
|
|
|
+ background.SetVertalign(BackgroundInfo.Vertalign);
|
|
|
+ background.SetHorizalign(BackgroundInfo.Horizalign);
|
|
|
+ background.SetXOffset(BackgroundInfo.HorizOffset);
|
|
|
+ background.SetYOffset(BackgroundInfo.VertOffset);
|
|
|
+ background.SetAllowsPrint(true);
|
|
|
+ background.SetAllowsView(true);
|
|
|
+ background.SetPages(getFilePageRange(document, PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeText"].ToString(), PDFCurrentDataTable.Rows[fileNamesIndex]["FilePageRangeSelectIndex"].ToString()));
|
|
|
+ background.Update();
|
|
|
+ }
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
#region 批量处理逻辑函数
|
|
@@ -450,6 +525,46 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcess
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 更新Currentlistview显示
|
|
|
+ /// pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)
|
|
|
+ /// </summary>
|
|
|
+ public void updateFilesPageRange(string pagerangetext = "1", string pagerangeselectindex = "0")
|
|
|
+ {
|
|
|
+ for (int i = 0; fileNames.Count > i; i++)
|
|
|
+ {
|
|
|
+
|
|
|
+ PDFDataTable.Rows[i]["FilePageRangeText"] = pagerangetext;
|
|
|
+ PDFDataTable.Rows[i]["FilePageRangeSelectIndex"] = pagerangeselectindex;
|
|
|
+ PDFCurrentDataTable.Rows[i]["FilePageRangeText"] = pagerangetext;
|
|
|
+ PDFCurrentDataTable.Rows[i]["FilePageRangeSelectIndex"] = pagerangeselectindex;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 获取文件列表单个文件对应的页码范围
|
|
|
+ /// document 文档对象 pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)
|
|
|
+ /// </summary>
|
|
|
+ public string getFilePageRange(CPDFDocument document, string pagerangetext = "1", string pagerangeselectindex = "0")
|
|
|
+ {
|
|
|
+ string filePageRange = "1";
|
|
|
+ EditToolsHelper.GetPageRange(int.Parse(pagerangeselectindex), document, ref filePageRange, pagerangetext);
|
|
|
+ return filePageRange;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取文件列表单个文件对应的页码范围
|
|
|
+ /// document 文档对象 pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)
|
|
|
+ /// </summary>
|
|
|
+ public bool isEvenPage(CPDFDocument document)
|
|
|
+ {
|
|
|
+ bool isevenpage = false;
|
|
|
+ if (document.PageCount > 1)
|
|
|
+ {
|
|
|
+ isevenpage = true;
|
|
|
+ }
|
|
|
+ return isevenpage;
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 逆序int类型集合
|
|
|
/// </summary>
|