Getting Started |
This topic contains the following sections:
WordGlue is designed to be extensible to any file format. Most of the time all you need to do is read one document and save as another.
We provide pre-built interfaces for export to common formats like PDF, XPS and SVG and for use with System.Drawing and WPF.
WordGlue interfaces easily with ABCpdf. All you need to do is ensure that WordGlue is installed and then use normal ABCpdf calls.
However WordGlue is designed to be extensible to allow export to any file format and using any technology - all you need to do is implement a simple interface - IRenderingContext.
As well as reading Word files and exporting them to other formats you can customize this process. For example you may wish to modify the document to customize your output for different audiences.
The examples and code snippets in this section show how to accomplish above.
The Examples folder under the WordGlue menu item contains complete projects.
There are a number of ways to reference WordGlue.
Most simply you can right click on the "References" section of your project and select "Manage NuGet Packages...". Then search for and reference WorldGlue - available on NuGet.org.
If you have run the full WordGlue MSI installer, the DLLs are placed in the GAC, so under .NET 4 you can add a reference simply by looking in the 'Assemblies > Extensions' section of the Reference Manager. Right click on 'References' in your project and 'Add Reference' - you will see WordGlue towards the bottom of the extensions list. In .NET 5 and later versions there is no GAC, so you need to use one of the other mechanisms for that.
Alternatively you can select the actual DLL. Right click on the "References" section of your project and select "Add Project Refererence...". Click on the "Browse..." button which will pop up a file selection dialog which you can use to choose the DLL.
There are different DLLs for .NET 4.X, .NET 5.0, .NET 6.0, .NET 7.0, .NET 8.0, .NET 9.0 and .NET 10.0 named WordGlue4.dll, WordGlue4.NET5.dll, WordGlue4.NET6.dll.... These are installed in folders under the WordGlue menu item.
You will probably want to add a using WebSupergoo.WordGlue4; statement for convenient access to the main namespace.
Alternatively you can reference it explicitly in your code.
static class Program { static void Main() { using(var doc = new WebSupergoo.WordGlue4.Doc("test.docx")) doc.SaveAs("output.pdf"); } }
There are other subsidiary namespaces in WordGlue for Layout, Rendering and Utilities though these are used less commonly.
Most of the time it is convenient to install WordGlue using the standard installer or NuGet package.
However WordGlue can be xcopy deployed by copying the WordGlue DLL into the bin directory.
There are different DLLs for .NET 4.X, .NET 5.0, .NET 6.0, .NET 7.0, .NET 8.0, .NET 9.0, .NET 10.0 and .NET Core. These are named WordGlue4.dll, WordGlue4.NET5.dll, WordGlue4.NET6.dll etc and WordGlue4.Core.dll respectively. These may be found in folders under the WordGlue menu item.
WordGlue is an AnyCPU build so it will work happily on either x86 or x64 systems in either 32 or 64 bit modes.
To insert your license, put the following in your application's initialization code:
// This method may throw InvalidLicenseException WebSupergoo.WordGlue4.Utilities.Settings.InstallLicense("your-license-code-here");
Different project types require different setups and these notes may help if you hit any problems.
Sometimes you may need to add references to elements like ConfigurationManager, Packaging, System.Drawing and PresentationCore.
If you need to do this you will know it because you will get exceptions saying that they are not available.
System.Configuration.ConfigurationManager, System.IO.Packaging and System.Drawing.Common can be obtained as NuGet packages.
You will also need to open the project properties and set the "Target OS" to be Windows.
If you are missing PresentationCore you will need to adjust your .csproj project. Currently Visual Studio does not support this so it has to be done by hand using a text editor. You need to insert a UseWPF tag as follows.
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net10.0-windows</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <UseWPF>true</UseWPF> </PropertyGroup> <ItemGroup> <PackageReference Include="System.Configuration.ConfigurationManager" Version="10.0.0" /> <PackageReference Include="System.IO.Packaging" Version="10.0.0" /> <PackageReference Include="WordGlue" Version="4.1.0.0" /> </ItemGroup> ...
Different project types require different setups and these notes may help if you hit any problems.
Sometimes you may need to add references to elements like ConfigurationManager, Packaging and PresesentationCore.
If you need to do this you will know it because you will get exceptions saying that they are not available.
System.Configuration.ConfigurationManager and System.IO.Packaging can be obtained as NuGet packages.
For PresentationCore and System.Drawing you just need to open the project properties and target Windows.
For WPF you will need to adjust your project to add a tag. Currently Visual Studio does not support this so it has to be done by hand using a text editor. You need to insert a UseWPF tag as follows.
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0-windows</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <UseWPF>true</UseWPF> </PropertyGroup> <ItemGroup> <PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0" /> <PackageReference Include="System.IO.Packaging" Version="8.0.0" /> <PackageReference Include="WordGlue" Version="4.0.0.0" /> </ItemGroup> ...
Older environments can be particularly idiosyncratic and these notes may help if you hit any problems.
Sometimes you may need to add references to elements like ConfigurationManager, Packaging and PresesentationCore.
If you need to do this you will know it because you will get exceptions saying that they are not available.
System.Configuration.ConfigurationManager and System.IO.Packaging can be obtained as NuGet packages. You may find you need to use pre-release versions dependent on the .NET Core version you are using.
For PresentationCore, System.Drawing and WPF you will need to adjust your project to add the SDK and a reference. Currently Visual Studio does not support this so it has to be done by hand using a text editor. You need to insert a UseWPF tag and reference the desktop SDK as follows.
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.0</TargetFramework> <UseWPF>true</UseWPF> </PropertyGroup> ...