12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using ComPDFKit.PDFDocument;
- using Microsoft.Office.Interop.Word;
- using PDF_Office.Helper;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Task = System.Threading.Tasks.Task;
- namespace PDF_Office.Model.Dialog.ToolsDialogs
- {
- public class CompressDialogModel
- {
- CPDFDocument tempDocument = null;
- IntPtr compressingIntpr = IntPtr.Zero;
- public enum EnumQualityLevel {
- StatusLarge=100,
- StatusStandard=80,
- StatusDefault=40,
- StatusLittle =40,
- StatusMicro=10
- }
- public EnumQualityLevel CompressQuality { get; set; }
- public static string PageIndex { get; set; }
- public void CompressClear()
- {
- tempDocument.CompressFile_Cancel(compressingIntpr);
- App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed;
- }
- private int GetIndex(int pageindex)
- {
- App.mainWindowViewModel.Value = (pageindex + 1);
-
- if (App.mainWindowViewModel.Value == App.mainWindowViewModel.MaxValue) { App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Collapsed; }
- return 0;
- }
- public async void OnOpened(Prism.Services.Dialogs.DialogResult e)
- {
- if (e.Result == Prism.Services.Dialogs.ButtonResult.Cancel||e.Result==Prism.Services.Dialogs.ButtonResult.None) { return; }
- CPDFDocument doc = null;
- CPDFDocument.GetPageIndexDelegate indexDelegate = null;
- string filepath = "";
- string password = "";
- int compressquality = 45;
- doc = e.Parameters.GetValue<CPDFDocument>(ParameterNames.PDFDocument);
- filepath = e.Parameters.GetValue<string>(ParameterNames.FilePath);
- password = e.Parameters.GetValue<string>(ParameterNames.PassWord);
- compressquality = e.Parameters.GetValue<int>("compressDialogModel.CompressQuality");
- if (doc != null)
- {
- App.mainWindowViewModel.Value = 0;
- App.mainWindowViewModel.ProgressTitle = "Compressing";
- App.mainWindowViewModel.IsProcessVisible = System.Windows.Visibility.Visible;
- App.mainWindowViewModel.MaxValue = doc.PageCount;
- CPDFDocument document = CPDFDocument.InitWithFilePath(doc.FilePath);
- document.UnlockWithPassword(password);
- indexDelegate += GetIndex;
- compressingIntpr = document.CompressFile_Init(compressquality, indexDelegate);
- //GC.KeepAlive(indexDelegate);
- tempDocument = document;
- Trace.WriteLine("compressDialogModel.CompressQuality" + compressquality);
- App.mainWindowViewModel.ProcessCloseAction = CompressClear;
- if (await Task.Run<bool>(() => { return document.CompressFile_Start(compressingIntpr, filepath); })) { CommonHelper.ShowFileBrowser(filepath); }
-
- document.Release();
- }
- }
- }
-
- }
|