Browse Source

compdfkit(win) - 新建PDF设置大小朝向窗口

weixiangjie 1 year ago
parent
commit
827255e9db

+ 59 - 0
Demo/Examples/Compdfkit_Tools/Common/CreateBlankPageSetting/CreateBlankPageSettingDialog.xaml

@@ -0,0 +1,59 @@
+<Window x:Class="Compdfkit_Tools.PDFControl.CreateBlankPageSettingDialog"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:local="clr-namespace:Compdfkit_Tools.PDFControl"
+        mc:Ignorable="d"
+        ResizeMode="NoResize"
+        ShowInTaskbar="False"
+        WindowStartupLocation="CenterScreen"
+        Title="Create a blank page" Height="432" Width="386">
+    <Window.Resources>
+        <ResourceDictionary>
+            <ResourceDictionary.MergedDictionaries>
+                <ResourceDictionary Source="../../Asset/Styles/RadioButtonStyle.xaml"></ResourceDictionary>
+            </ResourceDictionary.MergedDictionaries>
+        </ResourceDictionary>
+    </Window.Resources>
+    <Grid Margin="10,20,5,0">
+        <Grid.RowDefinitions>
+            <RowDefinition Height="154"></RowDefinition>
+            <RowDefinition Height="104"></RowDefinition>
+            <RowDefinition Height="40"></RowDefinition>
+        </Grid.RowDefinitions>
+        <Grid Background="White" Margin="20,0,0,0"  Panel.ZIndex="1" Height="20" HorizontalAlignment="Left" VerticalAlignment="Top">
+            <TextBlock Foreground="#001A4E" FontFamily="Segoe UI" Text="Select page size" FontWeight="DemiBold" FontSize="14"></TextBlock>
+        </Grid>
+        <Border Margin="0,10,7,12" BorderBrush="#33000000" BorderThickness="1">
+            <Grid Margin="10,10,10,10" VerticalAlignment="Center" Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Border}}}">
+                <Grid.RowDefinitions>
+                    <RowDefinition></RowDefinition>
+                    <RowDefinition></RowDefinition>
+                    <RowDefinition></RowDefinition>
+                </Grid.RowDefinitions>
+                <RadioButton x:Name="A3Rdo" Margin="0,10,0,0" VerticalAlignment="Center" FontFamily="Segoe UI" FontSize="14" Content="A3 (420*297mm)"></RadioButton>
+                <RadioButton Grid.Row="1" x:Name="A4Rdo" IsChecked="True" VerticalAlignment="Center" FontFamily="Segoe UI" FontSize="14" Content="A4 (210*297mm)"></RadioButton>
+                <RadioButton Grid.Row="2" x:Name="A5Rdo" Margin="0,0,0,10" VerticalAlignment="Center" FontFamily="Segoe UI" FontSize="14" Content="A5 (148*219mm)"></RadioButton>
+            </Grid>
+        </Border>
+        
+        <Grid Grid.Row="1" Background="White" Margin="20,0,0,0"  Panel.ZIndex="1" Height="20" HorizontalAlignment="Left" VerticalAlignment="Top">
+            <TextBlock Foreground="#001A4E" FontFamily="Segoe UI" Text="Select Page Orientation" FontWeight="DemiBold" FontSize="14"></TextBlock>
+        </Grid>
+        <Border Grid.Row="1" Margin="0,10,7,12" BorderBrush="#33000000" BorderThickness="1">
+            <Grid Margin="10" VerticalAlignment="Center" Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Border}}}">
+                <Grid.RowDefinitions>
+                    <RowDefinition></RowDefinition>
+                    <RowDefinition></RowDefinition>
+                </Grid.RowDefinitions>
+                <RadioButton x:Name="HorizontalRdo" Margin="0,10,0,0" VerticalAlignment="Center" FontFamily="Segoe UI" FontSize="14" Content="Orthogonal"></RadioButton>
+                <RadioButton Grid.Row="1" x:Name="VerticalRdo" Margin="0,0,0,10" IsChecked="True" VerticalAlignment="Center" FontFamily="Segoe UI" FontSize="14" Content="Vertically"></RadioButton>
+            </Grid>
+        </Border>
+        <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
+            <Button Content="Cancel" Width="112" Height="32" FontFamily="Segoe UI" FontSize="14" Click="Cancel_Click"></Button>
+            <Button Content="OK" Width="112" Height="32" FontFamily="Segoe UI" FontSize="14" Margin="10,0,10,0" Click="Confirm_Click"></Button>
+        </StackPanel>
+    </Grid>
+</Window>

+ 55 - 0
Demo/Examples/Compdfkit_Tools/Common/CreateBlankPageSetting/CreateBlankPageSettingDialog.xaml.cs

@@ -0,0 +1,55 @@
+using System;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Forms.VisualStyles;
+
+namespace Compdfkit_Tools.PDFControl;
+
+public class BlankPageSetting
+{
+    public Size Size { get; set; } = new(210, 297);
+    public Orientation Orientation { get; set; } = Orientation.Vertical;
+}
+
+public partial class CreateBlankPageSettingDialog : Window
+{
+    public event EventHandler<BlankPageSetting> CreateBlankPage;
+    public CreateBlankPageSettingDialog()
+    {
+        InitializeComponent();
+    }
+
+    private void Cancel_Click(object sender, RoutedEventArgs e)
+    {
+        Close();
+    }
+
+    private void Confirm_Click(object sender, RoutedEventArgs e)
+    {
+        var blankPageSetting = new BlankPageSetting
+        {
+            Size = GetSettingSize(),
+            Orientation = GetSettingOrientation()
+        };
+        CreateBlankPage?.Invoke(this, blankPageSetting);
+        Close();
+    }
+    
+    private Orientation GetSettingOrientation()
+    {
+        return HorizontalRdo.IsChecked == true ? Orientation.Horizontal : Orientation.Vertical;
+    }
+
+    private Size GetSettingSize()
+    {
+        if(A3Rdo.IsChecked == true)
+            return new Size(297, 420);
+        if(A4Rdo.IsChecked == true)
+            return new Size(210, 297);
+        if(A5Rdo.IsChecked == true)
+            return new Size(148, 219);
+
+        return new Size(210, 297);
+        
+    }
+}

+ 4 - 0
Demo/Examples/Compdfkit_Tools/Compdfkit_Tools.csproj

@@ -141,6 +141,9 @@
     <Compile Include="Common\Convert\TagToBoolConverter.cs" />
     <Compile Include="Common\Convert\WindowStateToPathConverter.cs" />
     <Compile Include="Common\Convert\WindowStateToThicknessConverter.cs" />
+    <Compile Include="Common\CreateBlankPageSetting\CreateBlankPageSettingDialog.xaml.cs">
+      <DependentUpon>CreateBlankPageSettingDialog.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Common\DeviceSerial\DeviceSerialControl.xaml.cs">
       <DependentUpon>DeviceSerialControl.xaml</DependentUpon>
     </Compile>
@@ -660,6 +663,7 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>
+    <Page Include="Common\CreateBlankPageSetting\CreateBlankPageSettingDialog.xaml" />
     <Page Include="Common\DeviceSerial\DeviceSerialControl.xaml" />
     <Page Include="Common\PasswordControl\PasswordBoxControl.xaml" />
     <Page Include="Common\HomePage\FeaturesListControl.xaml">

+ 16 - 1
Demo/Examples/PDFViewer/MainWindow.xaml.cs

@@ -122,12 +122,27 @@ namespace PDFViewer
             }
             else if (args.OperationType == FileOperationType.CreateNewFile)
             {
+                BlankPageSetting blankPageSetting = new BlankPageSetting();
+                CreateBlankPageSettingDialog createBlankPageSettingDialog = new CreateBlankPageSettingDialog()
+                {
+                    Owner = this
+                };
+                createBlankPageSettingDialog.CreateBlankPage += (o, setting) =>
+                {
+                    blankPageSetting = setting;
+                };
+                createBlankPageSettingDialog.ShowDialog();
+                
                 TabItemExt tabItem = new TabItemExt();
                 MainPage viewPage = new MainPage();
                 CPDFDocument document = CPDFDocument.CreateDocument();
                 document.SetInfo(new CPDFInfo
                 { Author = Properties.Settings.Default.DocumentAuthor, Creator = "ComPDFKit", CreationDate = DateTime.Now.ToString(),Subject="Document", Producer="ComPDFKit" , Keywords="Document", Version="1.11.0"});
-                document.InsertPage(0, 210, 273, "");
+                document.InsertPage(0, blankPageSetting.Size.Width, blankPageSetting.Size.Height, "");
+                if(blankPageSetting.Orientation == Orientation.Horizontal)
+                {
+                    document.RotatePage(0, 1);
+                }
                 viewPage.CheckExistBeforeOpenFileEvent -= ViewPage_CheckExistBeforeOpenFileEvent;
                 viewPage.FileChangeEvent -= ViewPage_FileChangeEvent;
                 viewPage.AfterSaveAsFileEvent -= ViewPage_AfterSaveAsFileEvent;