123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- using ComPDFKit.PDFWatermark;
- using PDF_Master.Model;
- using PDF_Master.Model.EditTools.Watermark;
- using Prism.Commands;
- using Prism.Mvvm;
- using Prism.Regions;
- using Prism.Services.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Media.Imaging;
- using System.Windows.Resources;
- namespace PDF_Master.ViewModels.Dialog.ServiceDialog
- {
- public class SubscriptionDialogViewModel : BindableBase, IDialogAware
- {
- public string Title => "";
- private WatermarkInfo watermarkInfo;
- private CPDFWatermark watermark;
- private ViewContentViewModel viewContentViewModel;
- public event Action<IDialogResult> RequestClose;
- #region 文案
- #endregion
- private string _uristore = "https://www.pdfreaderpro.com/windows/store/permanent";
- public string Uristore
- {
- get { return _uristore; }
- set
- {
- SetProperty(ref _uristore, value);
- }
- }
- public DelegateCommand LinkstoreCommand { get; set; }
- public DelegateCommand WarermarkSavingCommand { get; set; }
-
- private void InitString()
- {
-
- }
- public SubscriptionDialogViewModel(IRegionManager regionManager, IDialogService dialogService)
- {
- LinkstoreCommand = new DelegateCommand(Linkstore);
- WarermarkSavingCommand = new DelegateCommand(WarermarkSaving);
- InitString();
- }
- private void Linkstore()
- {
- Process.Start(new ProcessStartInfo(Uristore));
- }
- private void WarermarkSaving()
- {
- //string imagePath = "pack://application:,,,/PDF Master;component/Resources/Service/Warermark.png";
- //string imagePath = "D:/PDF Office/PDF Office/Resources/Service/Warermark.png";
- //Uri imageUri = new Uri(imagePath);
- //BitmapImage bitmapImage = new BitmapImage(imageUri);
- //byte[] imageArray;
- //using (MemoryStream memoryStream = new MemoryStream())
- //{
- // PngBitmapEncoder encoder = new PngBitmapEncoder();
- // encoder.Frames.Add(BitmapFrame.Create(bitmapImage));
- // encoder.Save(memoryStream);
- // imageArray = memoryStream.ToArray();
- //}
- //long imageSize = imageArray.Length;
- //int imageWidth = bitmapImage.PixelWidth;
- //int imageHeight = bitmapImage.PixelHeight;
- Uri resourceUri = new Uri("pack://application:,,,/PDF Master;component/Resources/Service/Warermark.png");
- StreamResourceInfo resourceInfo = Application.GetResourceStream(resourceUri);
- if (resourceInfo != null)
- {
- using (Stream stream = resourceInfo.Stream)
- {
- BitmapFrame frame = null;
- int width = 0;
- int height = 0;
- BitmapDecoder decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
- if (decoder != null && decoder.Frames.Count > 0)
- {
- frame = decoder.Frames[0];
- }
- if (frame != null)
- {
- var ImageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
- width = frame.PixelWidth;
- height = frame.PixelHeight;
- frame.CopyPixels(ImageArray, frame.PixelWidth * 4, 0);
- watermark = viewContentViewModel.PDFViewer.Document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
- watermark.SetImage(ImageArray, width, height);
- watermark.SetScale(1);
- watermark.SetRotation(0);
- watermark.SetOpacity(255);
- watermark.SetFront(false);
- watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_TOP);
- watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_LEFT);
- watermark.SetFullScreen(false);
- watermark.SetVertOffset(0);
- watermark.SetHorizOffset(0);
- watermark.SetHorizontalSpacing(0);
- watermark.SetVerticalSpacing(0);
- string setpages = $"0-{viewContentViewModel.PDFViewer.Document.PageCount.ToString()}";
- watermark.SetPages(setpages);
- watermark.UpdateWatermark();
- viewContentViewModel.PDFViewer.Document.ReleasePages();
- viewContentViewModel.PDFViewer.ReloadDocument();
- //viewContentViewModel.saveFile();
- Close();
- }
-
- }
-
- }
-
- }
- public void Close()
- {
- RequestClose?.Invoke(new Prism.Services.Dialogs.DialogResult(ButtonResult.Cancel));
- }
- public bool CanCloseDialog()
- {
- return true;
- }
- public void OnDialogClosed()
- {
- }
- public void OnDialogOpened(IDialogParameters parameters)
- {
- parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
- }
- }
- }
|