|
@@ -21,6 +21,110 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
{
|
|
|
public class HomePagePictureToPDFDialogViewModel : BindableBase, IDialogAware
|
|
|
{
|
|
|
+ #region 文案
|
|
|
+
|
|
|
+ private string T_title;
|
|
|
+
|
|
|
+ public string T_Title
|
|
|
+ {
|
|
|
+ get { return T_title; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref T_title, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private string T_addFolder;
|
|
|
+
|
|
|
+ public string T_AddFolder
|
|
|
+ {
|
|
|
+ get { return T_addFolder; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref T_addFolder, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private string T_addFile;
|
|
|
+
|
|
|
+ public string T_AddFile
|
|
|
+ {
|
|
|
+ get { return T_addFile; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref T_addFile, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private string T_emptyContext;
|
|
|
+
|
|
|
+ public string T_EmptyContext
|
|
|
+ {
|
|
|
+ get { return T_emptyContext; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref T_emptyContext, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private string T_settings;
|
|
|
+
|
|
|
+ public string T_Settings
|
|
|
+ {
|
|
|
+ get { return T_settings; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref T_settings, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private string T_exportTitle;
|
|
|
+
|
|
|
+ public string T_ExportTitle
|
|
|
+ {
|
|
|
+ get { return T_exportTitle; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref T_exportTitle, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private string T_create;
|
|
|
+
|
|
|
+ public string T_Create
|
|
|
+ {
|
|
|
+ get { return T_create; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref T_create, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private string T_merge;
|
|
|
+
|
|
|
+ public string T_Merge
|
|
|
+ {
|
|
|
+ get { return T_merge; }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ SetProperty(ref T_merge, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void InitString()
|
|
|
+ {
|
|
|
+ T_Title = App.MainPageLoader.GetString("ImageToPDF_Title");
|
|
|
+ T_AddFolder = App.MainPageLoader.GetString("ImageToPDF_AddFolder");
|
|
|
+ T_AddFile = App.MainPageLoader.GetString("ImageToPDF_AddFile");
|
|
|
+ T_EmptyContext = App.MainPageLoader.GetString("ImageToPDF_EmptyContext");
|
|
|
+ T_Settings = App.MainPageLoader.GetString("ImageToPDF_Settings");
|
|
|
+ T_ExportTitle = App.MainPageLoader.GetString("ImageToPDF_ExportTitle");
|
|
|
+ T_Create = App.MainPageLoader.GetString("ImageToPDF_Create");
|
|
|
+ T_Merge = App.MainPageLoader.GetString("ImageToPDF_Merge");
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
#region 参数和属性
|
|
|
private List<string> fileNames;
|
|
|
|
|
@@ -31,7 +135,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
|
|
|
public List<int> fileNamesView = new List<int>();
|
|
|
|
|
|
- public HomePagePictureToPDFDialogModel pictureToPDFModel=new HomePagePictureToPDFDialogModel();
|
|
|
+ public HomePagePictureToPDFDialogModel pictureToPDFModel = new HomePagePictureToPDFDialogModel();
|
|
|
|
|
|
private string pictureToPDFGridIsEnabled = "True";
|
|
|
public string PictureToPDFGridIsEnabled
|
|
@@ -139,6 +243,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
#endregion
|
|
|
public HomePagePictureToPDFDialogViewModel(IDialogService dialogs)
|
|
|
{
|
|
|
+ InitString();
|
|
|
this.dialogs = dialogs;
|
|
|
ToPDFCommand = new DelegateCommand(topdf);
|
|
|
ADDPictureCommand = new DelegateCommand(addpicture);
|
|
@@ -152,7 +257,8 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
this.dialogs = dialogs;
|
|
|
}
|
|
|
#region 逻辑函数
|
|
|
- private void topdf() {
|
|
|
+ private void topdf()
|
|
|
+ {
|
|
|
PictureToPDFGridIsEnabled = "False";
|
|
|
if (pictureToPDFModel.Mode == HomePagePictureToPDFDialogModel.ToPDFFileMode.NewFiles)
|
|
|
{
|
|
@@ -164,7 +270,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
SaveSelectedPath = dlg.SelectedPath.Trim();
|
|
|
saveSelectedPath = SaveSelectedPath + "\\";
|
|
|
}
|
|
|
- else { PictureToPDFGridIsEnabled = "True"; return; }
|
|
|
+ else { PictureToPDFGridIsEnabled = "True"; return; }
|
|
|
fileNamesIndex = 0;
|
|
|
string fileName = "";
|
|
|
foreach (var filename in fileNames)
|
|
@@ -180,9 +286,9 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
}
|
|
|
CPDFDocument topdfdoc = CPDFDocument.CreateDocument();
|
|
|
FileInfo fileinfo = new FileInfo(filename);
|
|
|
- JpegInsertPage(ref topdfdoc, filename, fileinfo,img.Width,img.Height);
|
|
|
+ JpegInsertPage(ref topdfdoc, filename, fileinfo, img.Width, img.Height);
|
|
|
Trace.WriteLine("Path.GetTempPath():" + Path.GetTempPath());
|
|
|
- fileName = savefilename(filename,saveSelectedPath);
|
|
|
+ fileName = savefilename(filename, saveSelectedPath);
|
|
|
topdfdoc.WriteToFilePath(fileName);
|
|
|
topdfdoc.Release();
|
|
|
string file_size = (((float)fileinfo.Length) / 1024).ToString() + " K";
|
|
@@ -195,7 +301,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
}
|
|
|
if (pictureToPDFModel.Mode == HomePagePictureToPDFDialogModel.ToPDFFileMode.OneNewFile)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
CPDFDocument topdfdoc = CPDFDocument.CreateDocument();
|
|
|
int pageindex = 0;
|
|
|
FolderBrowserDialog folderDialog = new FolderBrowserDialog();
|
|
@@ -205,10 +311,11 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
string NewFileName = "";
|
|
|
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
{
|
|
|
- NewFileName=sfd.FileName;
|
|
|
+ NewFileName = sfd.FileName;
|
|
|
}
|
|
|
else { PictureToPDFGridIsEnabled = "True"; return; }
|
|
|
- foreach (var filename in fileNames) {
|
|
|
+ foreach (var filename in fileNames)
|
|
|
+ {
|
|
|
ImagesDataTable.Rows[fileNamesIndex]["FileState"] = "wait";
|
|
|
ImagesCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "wait";
|
|
|
Image img = Image.FromFile(filename);
|
|
@@ -219,7 +326,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
continue;
|
|
|
}
|
|
|
FileInfo fileinfo = new FileInfo(filename);
|
|
|
- JpegInsertPage(ref topdfdoc, filename, fileinfo,img.Width, img.Height, pageindex);
|
|
|
+ JpegInsertPage(ref topdfdoc, filename, fileinfo, img.Width, img.Height, pageindex);
|
|
|
pageindex++;
|
|
|
string file_size = (((float)fileinfo.Length) / 1024).ToString() + " K";
|
|
|
ImagesDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
|
|
@@ -239,7 +346,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
saveSelectedPath = dlg.SelectedPath.Trim();
|
|
|
saveSelectedPath = saveSelectedPath + "\\";
|
|
|
}
|
|
|
- else {PictureToPDFGridIsEnabled = "True"; return; }
|
|
|
+ else { PictureToPDFGridIsEnabled = "True"; return; }
|
|
|
CPDFDocument topdfdoc = CPDFDocument.InitWithFilePath(pictureToPDFModel.FilePath);
|
|
|
if (topdfdoc == null)
|
|
|
{
|
|
@@ -295,22 +402,22 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
ImagesCurrentDataTable.Rows[fileNamesIndex]["FileState"] = "complete";
|
|
|
fileNamesIndex++;
|
|
|
}
|
|
|
- string saveselectedpath = CommonHelper.CreateFilePath(saveSelectedPath + topdfdoc.FileName+".pdf");
|
|
|
+ string saveselectedpath = CommonHelper.CreateFilePath(saveSelectedPath + topdfdoc.FileName + ".pdf");
|
|
|
topdfdoc.WriteToFilePath(saveselectedpath);
|
|
|
System.Diagnostics.Process.Start("Explorer", "/select," + saveselectedpath);
|
|
|
topdfdoc.Release();
|
|
|
}
|
|
|
PictureToPDFGridIsEnabled = "True";
|
|
|
- fileNamesIndex=0;
|
|
|
+ fileNamesIndex = 0;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 设置保存后的文件名
|
|
|
/// </summary>
|
|
|
- public string savefilename(string filename,string filepath)
|
|
|
+ public string savefilename(string filename, string filepath)
|
|
|
{
|
|
|
FileInfo file = new FileInfo(filename);
|
|
|
- return CommonHelper.CreateFilePath(filepath + pictureToPDFModel.FrontFileNameLabel + file.Name.Replace(file.Extension,".pdf") + pictureToPDFModel.RearFileNameLabel);
|
|
|
+ return CommonHelper.CreateFilePath(filepath + pictureToPDFModel.FrontFileNameLabel + file.Name.Replace(file.Extension, ".pdf") + pictureToPDFModel.RearFileNameLabel);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
@@ -325,7 +432,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
dlg.Filter = "PDF|*.pdf;*.PDF;";
|
|
|
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
{
|
|
|
- SelectFileName=dlg.FileName;
|
|
|
+ SelectFileName = dlg.FileName;
|
|
|
pictureToPDFModel.FilePath = dlg.FileName;
|
|
|
ImageToPDFBtnIsEnable = "True";
|
|
|
}
|
|
@@ -376,7 +483,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
foreach (string app in apps)
|
|
|
{
|
|
|
var fi = new FileInfo(app);
|
|
|
- if (fi.Extension == ".png" || fi.Extension == ".jpg" || fi.Extension == ".jpeg" || fi.Extension ==".bmp"|| fi.Extension == ".gif"|| fi.Extension == ".tiff")
|
|
|
+ if (fi.Extension == ".png" || fi.Extension == ".jpg" || fi.Extension == ".jpeg" || fi.Extension == ".bmp" || fi.Extension == ".gif" || fi.Extension == ".tiff")
|
|
|
{
|
|
|
fileNames.Add(app);
|
|
|
}
|
|
@@ -396,10 +503,10 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
public void removepicturefiles()
|
|
|
{
|
|
|
FileNameNumber = fileNames.Count;
|
|
|
-
|
|
|
- //Trace.WriteLine(filenamesview);
|
|
|
- fileNames.Clear();
|
|
|
-
|
|
|
+
|
|
|
+ //Trace.WriteLine(filenamesview);
|
|
|
+ fileNames.Clear();
|
|
|
+
|
|
|
if (fileNames.Count < 1)
|
|
|
{
|
|
|
SetPictureToPDFGridIsEnabled = "False";
|
|
@@ -409,7 +516,8 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
updateListview("wait");
|
|
|
}
|
|
|
|
|
|
- public void removepicturefile() {
|
|
|
+ public void removepicturefile()
|
|
|
+ {
|
|
|
FileNameNumber = fileNames.Count;
|
|
|
Reverseorder(ref fileNamesView);
|
|
|
foreach (int filenamesview in fileNamesView)
|
|
@@ -443,18 +551,20 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
/// <summary>
|
|
|
/// 打开文件图片
|
|
|
/// </summary>
|
|
|
- public void openfiledialog(){
|
|
|
+ public void openfiledialog()
|
|
|
+ {
|
|
|
|
|
|
foreach (int filenamesview in fileNamesView)
|
|
|
{
|
|
|
- System.Diagnostics.Process.Start("Explorer", "/select," + fileNames[filenamesview]);
|
|
|
+ System.Diagnostics.Process.Start("Explorer", "/select," + fileNames[filenamesview]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 删除重复的文件
|
|
|
/// </summary>
|
|
|
- public void RemoveExcess(ref List<string> Filenames) {
|
|
|
+ public void RemoveExcess(ref List<string> Filenames)
|
|
|
+ {
|
|
|
List<string> filenames = new List<string>();
|
|
|
foreach (var fileName in Filenames)
|
|
|
{
|
|
@@ -472,7 +582,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
/// </summary>
|
|
|
public void Reverseorder(ref List<int> Numbers)
|
|
|
{
|
|
|
- Numbers=Numbers.OrderBy(a=>a).ToList();
|
|
|
+ Numbers = Numbers.OrderBy(a => a).ToList();
|
|
|
Numbers.Reverse();
|
|
|
}
|
|
|
|
|
@@ -480,7 +590,8 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
/// 更新listview显示
|
|
|
/// state 状态显示字符串
|
|
|
/// </summary>
|
|
|
- public void updateListview(string state) {
|
|
|
+ public void updateListview(string state)
|
|
|
+ {
|
|
|
updateCurrentListview();
|
|
|
DataTable imagesdatatable = new DataTable();
|
|
|
imagesdatatable.Columns.Add("FileName");
|
|
@@ -492,7 +603,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
string file_all = fileName;
|
|
|
FileInfo f = new FileInfo(file_all);
|
|
|
if (!f.Exists) { continue; }
|
|
|
- string file_size = (((float)f.Length)/1024).ToString()+" K";
|
|
|
+ string file_size = (((float)f.Length) / 1024).ToString() + " K";
|
|
|
imagesdatatable.Rows.Add(f.Name, file_size, ImagesCurrentDataTable.Rows[datatableindex]["FileState"]);
|
|
|
datatableindex++;
|
|
|
}
|
|
@@ -503,7 +614,7 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
/// 更新Currentlistview显示
|
|
|
/// pagerangetext 自定义页面范围字符串 pagerangeselectindex combobox下拉索引(0全部页面 1奇数页 2偶数页 3自定义页面)isevenpageisenabled 偶数页状态 state 状态显示字符串
|
|
|
/// </summary>
|
|
|
- public void updateCurrentListview( string state = "wait")
|
|
|
+ public void updateCurrentListview(string state = "wait")
|
|
|
{
|
|
|
if (fileNames.Count >= FileNameNumber)
|
|
|
{
|
|
@@ -592,25 +703,26 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
/// height page高
|
|
|
/// index 插入位置
|
|
|
/// </summary>
|
|
|
- private void JpegInsertPage(ref CPDFDocument topdfdoc,string filename, FileInfo fileinfo,int width,int height,int index=0) {
|
|
|
+ private void JpegInsertPage(ref CPDFDocument topdfdoc, string filename, FileInfo fileinfo, int width, int height, int index = 0)
|
|
|
+ {
|
|
|
|
|
|
string tempFileName = "";
|
|
|
- if (fileinfo.Extension == ".jpg"|| fileinfo.Extension == ".jpeg")
|
|
|
+ if (fileinfo.Extension == ".jpg" || fileinfo.Extension == ".jpeg")
|
|
|
{
|
|
|
topdfdoc.InsertPage(index, width, height, filename);
|
|
|
}
|
|
|
- else
|
|
|
+ else
|
|
|
{
|
|
|
tempFileName = Path.GetTempPath() + "pngtemp.jpg";
|
|
|
if (!PictureConverter.SaveJpeg(filename, tempFileName))
|
|
|
- {
|
|
|
+ {
|
|
|
MessageBoxEx.Show("图片格式有问题");
|
|
|
}
|
|
|
topdfdoc.InsertPage(index, width, height, tempFileName);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void CloseDialoge() { RequestClose?.Invoke(new DialogResult(ButtonResult.OK));}
|
|
|
+ public void CloseDialoge() { RequestClose?.Invoke(new DialogResult(ButtonResult.OK)); }
|
|
|
#endregion
|
|
|
|
|
|
#region 构架行为
|
|
@@ -629,12 +741,12 @@ namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs
|
|
|
|
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
|
{
|
|
|
- string[] filepath=null;
|
|
|
+ string[] filepath = null;
|
|
|
parameters.TryGetValue<string[]>(ParameterNames.FilePath, out filepath);
|
|
|
- if (filepath!=null)
|
|
|
+ if (filepath != null)
|
|
|
{
|
|
|
- fileNames=filepath.ToList();
|
|
|
-
|
|
|
+ fileNames = filepath.ToList();
|
|
|
+
|
|
|
updateListview("wait");
|
|
|
}
|
|
|
}
|