liyijie 2 vuotta sitten
vanhempi
commit
3b90bae10e

+ 1 - 0
PDF Office/PDF Office.csproj

@@ -1254,6 +1254,7 @@
     <Resource Include="Resources\PageEdit\Staff.png">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Resource>
+    <Resource Include="Resources\EditTools\watermark_bg.png" />
     <Content Include="source\AnalysisWord\Res\_rels\.rels">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content>

+ 0 - 1
PDF Office/ViewModels/EditTools/Watermark/WatermarkCreateBaseContentViewModel.cs

@@ -180,7 +180,6 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
                 CreateBaseVisible = Visibility.Visible;
                 EditBaseVisible = Visibility.Collapsed;
             }
-            EnterSelectedCreateMod(CurrentCreateModName);
             eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(CurrentCreateModName);
         }
     }

+ 2 - 1
PDF Office/ViewModels/EditTools/Watermark/WatermarkCreateFileContentViewModel.cs

@@ -402,8 +402,9 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             {
                 var watermarkItem = new WatermarkItem();
                 ConvertInfoToItem(ref watermarkItem, WatermarkInfo);
-                this.eventAggregator.GetEvent<SaveEditedWatermarkTemplateItemEvent>().Publish(watermarkItem);
+                
                 this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(EnumTemplateListOrCreate.StatusTemplate);
+                this.eventAggregator.GetEvent<SaveEditedWatermarkTemplateItemEvent>().Publish(watermarkItem);
             }
         }
 

+ 2 - 1
PDF Office/ViewModels/EditTools/Watermark/WatermarkCreateTextContentViewModel.cs

@@ -552,8 +552,9 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             {
                 var watermarkItem = new WatermarkItem();
                 ConvertInfoToItem(ref watermarkItem, WatermarkInfo);
-                this.eventAggregator.GetEvent<SaveEditedWatermarkTemplateItemEvent>().Publish(watermarkItem);
+                
                 this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(EnumTemplateListOrCreate.StatusTemplate);
+                this.eventAggregator.GetEvent<SaveEditedWatermarkTemplateItemEvent>().Publish(watermarkItem);
             }
         }
 

+ 1 - 0
PDF Office/ViewModels/EditTools/Watermark/WatermarkTemplateListBaseContentViewModel.cs

@@ -137,6 +137,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
                 EnterSelectedTemplateListMod(CurrentTemplateListModName);
                 eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Publish(CurrentTemplateListModName);
 
+
             }
         }
     }

+ 85 - 3
PDF Office/ViewModels/EditTools/Watermark/WatermarkTemplateListFileContentViewModel.cs

@@ -1,5 +1,6 @@
 using ComPDFKit.PDFDocument;
 using ComPDFKit.PDFPage;
+using ComPDFKit.PDFWatermark;
 using ComPDFKitViewer.PdfViewer;
 using PDF_Office.CustomControl;
 using PDF_Office.EventAggregators;
@@ -16,11 +17,16 @@ using Prism.Regions;
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.Drawing;
+using System.Drawing.Printing;
 using System.IO;
 using System.Linq;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
 
 namespace PDF_Office.ViewModels.EditTools.Watermark
 {
@@ -53,6 +59,13 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             set { SetProperty(ref _createTemplateVisible, value); }
         }
 
+        private ImageSource _imageSource;
+        public ImageSource ImageSource {
+
+            get { return _imageSource; }
+            set { SetProperty(ref _imageSource, value); }
+        }
+
         public DelegateCommand AddTemplateCommand { get; set; }
         public DelegateCommand<object> DeleteTemplateItemCommand { get; set; }
         public DelegateCommand<object> EditTemplateItemCommand { get; set; }
@@ -99,6 +112,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
                 if (Settings.Default.WatermarkTemplateList[temp].type == ComPDFKit.PDFWatermark.C_Watermark_Type.WATERMARK_TYPE_IMG)
                 {
                     watermarkModTextTemplateList.Add(Settings.Default.WatermarkTemplateList[temp]);
+                    
                 }
             }
             WatermarkModFileCollection = new ObservableCollection<WatermarkItem>(watermarkModTextTemplateList);
@@ -198,7 +212,7 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
                 }
             }
             var listBox = e as ListBox;
-            WatermarkItem WatermarkItem   = listBox.SelectedItem as WatermarkItem;
+            WatermarkItem WatermarkItem = listBox.SelectedItem as WatermarkItem;
             SendTemplateItemToDocument(WatermarkItem);
         }
 
@@ -219,9 +233,10 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
                         EditToolsHelper.ChooseFile(watermarkItem.imagepath, ref WatermarkInfo);
                     }
                 }
-                else {
+                else
+                {
                     watermarkInfo.WatermarkType = ComPDFKit.PDFWatermark.C_Watermark_Type.WATERMARK_TYPE_UNKWON;
-                    MessageBoxEx.Show("原路径为:"+ watermarkItem.imagepath+",该文件不存在");
+                    MessageBoxEx.Show("原路径为:" + watermarkItem.imagepath + ",该文件不存在");
                 }
                 watermarkInfo.WatermarkHorizalign = watermarkItem.horizalign;
                 watermarkInfo.WatermarkVertalign = watermarkItem.vertalign;
@@ -260,6 +275,73 @@ namespace PDF_Office.ViewModels.EditTools.Watermark
             eventAggregator.GetEvent<SetWatermarkEvent>().Publish(WatermarkInfo);
         }
 
+        public static BitmapSource ToBitmapSource(System.Drawing.Bitmap image)
+        {
+            IntPtr ptr = image.GetHbitmap();//obtain the Hbitmap
+            BitmapSource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap
+            (
+                ptr,
+                IntPtr.Zero,
+                Int32Rect.Empty,
+                System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()
+            );
+            return bs;
+        }
+
+
+        public async Task RenderBitmap(WatermarkItem WatermarkItem)
+        {
+            CPDFDocument newDoc = CPDFDocument.CreateDocument();
+            newDoc.InsertPage(0, 595, 842, null);
+            WatermarkInfo watermarkInfo=new WatermarkInfo();
+            ConvertItemToInfo(WatermarkItem, ref watermarkInfo);
+            CreateWatermark(newDoc, watermarkInfo);
+            CPDFPage page = newDoc.PageAtIndex(0, true);
+
+            byte[] bmp_data = new byte[(int)page.PageSize.Width * (int)page.PageSize.Height * 4];
+            Bitmap bitmap = await ToolMethod.RenderPageBitmap(newDoc, (int)(page.PageSize.Width * 1.4), (int)(page.PageSize.Height * 1.4), 0, true, true);
+            ImageSource = ToBitmapSource(bitmap);
+            newDoc.ReleasePages();
+        }
+
+        public void CreateWatermark(CPDFDocument document ,WatermarkInfo watermarkInfo)
+        {
+            if (watermarkInfo != null)
+            { 
+                document.DeleteWatermarks();
+                CPDFWatermark watermark;
+                if (watermarkInfo.WatermarkType == C_Watermark_Type.WATERMARK_TYPE_TEXT)
+                {
+                    watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_TEXT);
+                    watermark.SetText(watermarkInfo.Text);
+                    watermark.SetFontName(watermarkInfo.FontName);
+                    watermark.SetFontSize(watermarkInfo.TextSize);
+                    watermark.SetTextRGBColor(watermarkInfo.TextColor);
+                }
+                else
+                {
+                     watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
+                    if (watermarkInfo.ImageArray != null)
+                    {
+                        watermark.SetImage(watermarkInfo.ImageArray, watermarkInfo.ImageWidth, watermarkInfo.ImageHeight);
+                    }
+                    watermark.SetScale(0.1f);
+                }
+                watermark.SetRotation(watermarkInfo.Rotation);
+                watermark.SetOpacity(watermarkInfo.Opacity);
+                watermark.SetFront(watermarkInfo.IsFront);
+                watermark.SetVertalign(watermarkInfo.WatermarkVertalign);
+                watermark.SetHorizalign(watermarkInfo.WatermarkHorizalign);
+                watermark.SetFullScreen(watermarkInfo.Isfull);
+                watermark.SetVertOffset(watermarkInfo.VertOffset);
+                watermark.SetHorizOffset(watermarkInfo.HorizOffset);
+                watermark.SetHorizontalSpacing(watermarkInfo.HorizontalSpacing);
+                watermark.SetVerticalSpacing(watermarkInfo.VerticalSpacing);
+                watermark.SetPages("0");
+                Trace.WriteLine("IsCreateWatermark: " + watermark.CreateWatermark());
+                Trace.WriteLine("IsUpdateWatermark: " + watermark.UpdateWatermark());
+            }
+        }
 
 
         public bool IsNavigationTarget(NavigationContext navigationContext)

+ 1 - 1
PDF Office/Views/BottomToolContent.xaml

@@ -182,7 +182,7 @@
                 Margin="4"
                 Command="{Binding SetViewModeCommand}"
                 IsChecked="{Binding IsDoubleView}"
-                Style="{StaticResource Radion_ButtonStyle}">
+                Style="{StaticResource Radion_ButtonStyle}" Cursor="Hand">
                 <Path Data="M0,15 L0,1 L11.807106,1 L16,5.39289312 L16,15 L0,15 Z M7.5,2 L1,2 L1,14 L7.5,14 L7.5,2 Z M10.999,2 L8.5,2 L8.5,14 L15,14 L15,5.999 L10.999999,6 L10.999,2 Z M11.999,2.64 L11.999,5 L14.236,4.999 L11.999,2.64 Z" Fill="Black" />
             </RadioButton>
             <RadioButton

+ 7 - 3
PDF Office/Views/EditTools/Watermark/WatermarkTemplateListFileContent.xaml

@@ -54,9 +54,13 @@
             <ListBox.ItemTemplate>
                 <DataTemplate DataType="{x:Type data:WatermarkItem}">
                     <StackPanel Name="itemPanel" >
-                        <Grid Height="160" Width=" 128" Background="Blue">
-                            <Label  Height="160" Width=" 128"></Label>
-                            <Label  Height="160" Width=" 128"></Label>
+                        <Grid Height="160" Width=" 128" >
+                            <Label  Height="160" Width=" 128"  >
+                                <Image Source="pack://application:,,,/Resources/EditTools/watermark_bg.png"></Image>
+                            </Label>
+                            <Label  Height="160" Width=" 128">
+                                <Image Source="{Binding ImageSource}"></Image>
+                            </Label>
                             <Button Name="EditTemplateBtn" Height="43" Width="63" HorizontalAlignment="Left" VerticalAlignment="Bottom" Click="EditTemplateBtn_Click"></Button>
                             <Button Name="DeleteTemplateBtn"  Height="43" Width="63" HorizontalAlignment="Right" VerticalAlignment="Bottom" Click="DeleteTemplateBtn_Click" >
                             </Button>

+ 12 - 0
PDF Office/Views/EditTools/Watermark/WatermarkTemplateListFileContent.xaml.cs

@@ -1,5 +1,8 @@
 using ComPDFKitViewer;
+using PDF_Office.ViewModels.Dialog.HomePageToolsDialogs;
 using PDF_Office.ViewModels.EditTools.Watermark;
+using System.Collections;
+using System.Diagnostics;
 using System.Windows;
 using System.Windows.Controls;
 
@@ -24,7 +27,16 @@ namespace PDF_Office.Views.EditTools.Watermark
 
         private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
+            IList list = FileWatermarkListbox.SelectedItems;
+            var lists = FileWatermarkListbox.Items;
+            System.Data.DataRowView a;
+            foreach (var item in list)
+            {
+                
+               Trace.WriteLine( lists.IndexOf(item));
+            }
             viewModel.SelectTemplateItemCommand?.Execute(sender);
+            FileWatermarkListbox.SelectedIndex = -1;
         }
 
         private void MenuEdit_Click(object sender, RoutedEventArgs e)

+ 7 - 3
PDF Office/Views/EditTools/Watermark/WatermarkTemplateListTextContent.xaml

@@ -54,9 +54,13 @@
             <ListBox.ItemTemplate>
                 <DataTemplate DataType="{x:Type data:WatermarkItem}">
                     <StackPanel Name="itemPanel" >
-                        <Grid Height="160" Width=" 128" Background="Blue">
-                            <Label  Height="160" Width=" 128"></Label>
-                            <Label  Height="160" Width=" 128"></Label>
+                        <Grid Height="160" Width=" 128">
+                            <Label  Height="160" Width=" 128"  >
+                                <Image Source="pack://application:,,,/Resources/EditTools/watermark_bg.png"></Image>
+                            </Label>
+                            <Label  Height="160" Width=" 128">
+                                <Image Source="{Binding WatermarkImageSource}"></Image>
+                            </Label>
                             <Button Name="EditTemplateBtn" Height="43" Width="63" HorizontalAlignment="Left" VerticalAlignment="Bottom" Click="EditTemplateBtn_Click"></Button>
                             <Button Name="DeleteTemplateBtn"  Height="43" Width="63" HorizontalAlignment="Right" VerticalAlignment="Bottom" Click="DeleteTemplateBtn_Click" >
                             </Button>

+ 2 - 0
PDF Office/Views/EditTools/Watermark/WatermarkTemplateListTextContent.xaml.cs

@@ -26,6 +26,8 @@ namespace PDF_Office.Views.EditTools.Watermark
         private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
             viewModel.SelectTemplateItemCommand?.Execute(sender);
+
+            TextWatermarkListbox.SelectedIndex = -1;
         }
 
         private void MenuEdit_Click(object sender, RoutedEventArgs e)