diff --git a/.gitignore b/.gitignore index 3620d6b..f687930 100644 --- a/.gitignore +++ b/.gitignore @@ -249,3 +249,4 @@ ModelManifest.xml /uwp/src/Imageshack/cloundes/cloundes/Model/Appid.cs /uwp/src/VarietyHiggstGushed/VarietyHiggstGushed/_pkginfo.txt /uwp/control/BitStamp/BitStamp/AppxPackages/ +/wpf/dotnetCampus.WPF/Lib diff --git a/wpf/WordPageToImages/App.xaml b/wpf/WordPageToImages/App.xaml new file mode 100644 index 0000000..f22c48f --- /dev/null +++ b/wpf/WordPageToImages/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/wpf/WordPageToImages/App.xaml.cs b/wpf/WordPageToImages/App.xaml.cs new file mode 100644 index 0000000..168dfb2 --- /dev/null +++ b/wpf/WordPageToImages/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace WordPageToImages +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/wpf/WordPageToImages/AssemblyInfo.cs b/wpf/WordPageToImages/AssemblyInfo.cs new file mode 100644 index 0000000..2211234 --- /dev/null +++ b/wpf/WordPageToImages/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly:ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/wpf/WordPageToImages/Icon.png b/wpf/WordPageToImages/Icon.png new file mode 100644 index 0000000..bd4cd9d Binary files /dev/null and b/wpf/WordPageToImages/Icon.png differ diff --git a/wpf/WordPageToImages/MainWindow.xaml b/wpf/WordPageToImages/MainWindow.xaml new file mode 100644 index 0000000..81aab07 --- /dev/null +++ b/wpf/WordPageToImages/MainWindow.xaml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/wpf/WordPageToImages/MainWindow.xaml.cs b/wpf/WordPageToImages/MainWindow.xaml.cs new file mode 100644 index 0000000..e2a21b1 --- /dev/null +++ b/wpf/WordPageToImages/MainWindow.xaml.cs @@ -0,0 +1,81 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Windows; +using Microsoft.Office.Interop.Word; +using Path = System.IO.Path; +using Window = System.Windows.Window; + +namespace WordPageToImages +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + + private void ConvertWordPageToImages(FileInfo wordFile, DirectoryInfo outputFolder) + { + var applicationClass = new ApplicationClass(); + //applicationClass.Visible = false; 默认值就是 false 值 + var folder = outputFolder.FullName; + + // 截图使用只读方式打开,这里传入的要求是绝对路径 + Document document = applicationClass.Documents.Open(wordFile.FullName, ReadOnly: true); + + var count = 0; + + foreach (Microsoft.Office.Interop.Word.Window documentWindow in document.Windows) + { + var documentWindowPanes = documentWindow.Panes; + for (var index = 0; index < documentWindowPanes.Count; index++) + { + Pane documentWindowPane = documentWindowPanes[index + 1]; + var pagesCount = documentWindowPane.Pages.Count; + for (int i = 0; i < pagesCount; i++) + { + var page = documentWindowPane.Pages[i + 1]; + Console.WriteLine($"{page.Width};{page.Height}"); + count++; + var file = Path.Combine(folder, $"{count}.png"); + + var bits = page.EnhMetaFileBits; + using (var ms = new MemoryStream((byte[]) (bits))) + { + var image = System.Drawing.Image.FromStream(ms); + image.Save(file); + } + //page.SaveAsPNG(file); // System.Runtime.InteropServices.COMException: '该方法无法用于对那个对象。' + } + } + } + + document.Close(); + applicationClass.Quit(); + } + + private void Grid_OnDrop(object sender, DragEventArgs e) + { + try + { + var data = (string[]?) e.Data.GetData(DataFormats.FileDrop); + if (data is not null) + { + var wordFile = data[0]; + var folder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); + ConvertWordPageToImages(new FileInfo(wordFile), Directory.CreateDirectory(folder)); + + Process.Start("explorer", $" \"{folder}\" "); + } + } + catch (Exception exception) + { + Debug.WriteLine(exception); + } + } + } +} diff --git a/wpf/WordPageToImages/WordPageToImages.csproj b/wpf/WordPageToImages/WordPageToImages.csproj new file mode 100644 index 0000000..160740d --- /dev/null +++ b/wpf/WordPageToImages/WordPageToImages.csproj @@ -0,0 +1,19 @@ + + + + WinExe + net5.0-windows + enable + true + true + + + + + + + + + + + diff --git a/wpf/WordPageToImages/WordPageToImages.sln b/wpf/WordPageToImages/WordPageToImages.sln new file mode 100644 index 0000000..49412ca --- /dev/null +++ b/wpf/WordPageToImages/WordPageToImages.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WordPageToImages", "WordPageToImages.csproj", "{4505645A-A27E-49FB-AEE2-0EABED734A60}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4505645A-A27E-49FB-AEE2-0EABED734A60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4505645A-A27E-49FB-AEE2-0EABED734A60}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4505645A-A27E-49FB-AEE2-0EABED734A60}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4505645A-A27E-49FB-AEE2-0EABED734A60}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal