DDDN.OdtToHtml
0.25.1.211
See the version list below for details.
dotnet add package DDDN.OdtToHtml --version 0.25.1.211
NuGet\Install-Package DDDN.OdtToHtml -Version 0.25.1.211
<PackageReference Include="DDDN.OdtToHtml" Version="0.25.1.211" />
paket add DDDN.OdtToHtml --version 0.25.1.211
#r "nuget: DDDN.OdtToHtml, 0.25.1.211"
// Install DDDN.OdtToHtml as a Cake Addin #addin nuget:?package=DDDN.OdtToHtml&version=0.25.1.211 // Install DDDN.OdtToHtml as a Cake Tool #tool nuget:?package=DDDN.OdtToHtml&version=0.25.1.211
DDDN.OdtToHtml
OdtToHtml is a .NET Standard/Core library for converting ODT documents (Open Document Text Format) into responsive HTML/CSS.
How to use
Nuget package
Simply add the DDDN.OdtToHtml nuget package reference to your project.
Build requirements
You can download the code and compile the library using Visual studio 2017 and the .NET Core 2.x SDK.
Sample application
Please have a look at the DDDN.OdtToHtml.Samples ASP.NET Core 2.0 sample application.
Sample code
The following example shows how to call the Convert
method within a MVC controller action method, in order to get the HTML/CSS from an ODT document saved somewhere in the www root folder.
// id is the ODT document file name without the suffix
public IActionResult Open(string id)
{
// subdirectory name where the ODT document content files like images will be stored
const string contentSubDirname = "content";
// structure returned by the Convert method with the converted data
OdtConvertedData convertedData = null;
// generating path to the ODT document that will be converted
var odtFileInfo = _hostingEnvironment.WebRootFileProvider.GetFileInfo(Path.Combine("odt", id));
// settings for the Convert method
var odtConvertSettings = new OdtConvertSettings
{
RootElementTagName = "article", // root HTML tag that will contain the converted HTML
RootElementId = "article_id", // the id attribute value of the root HTML tag (optional)
RootElementClassNames = "article_class", // the class attribute value of the root HTML tag (optional)
LinkUrlPrefix = $"/{contentSubDirname}", // here you can provide a prefix for all content links to match your environment requirements
DefaultTabSize = "2rem" // the default value for tabs (not tab stops)
};
// open the ODT document from the file system and call the Convert method to get the HTML/CSS
using (IOdtFile odtFile = new OdtFile(odtFileInfo.PhysicalPath))
{
convertedData = new OdtConvert().Convert(odtFile, odtConvertSettings);
}
ViewData["ArticleHtml"] = convertedData.Html; // move the generated HTML to the razor view
ViewData["ArticleCss"] = convertedData.Css; // move the generated CSS to the razor view
var usedFontFamilies = convertedData.UsedFontFamilies; // all font families used in CSS/HTML useful for font links
var pageInfo = convertedData.PageInfo; // contains the document sheet's dimensions and margins
var documentFirstHeader = convertedData.DocumentFirstHeader; // the "text only" content of the first document header for preview purposes
var documentFirstParagraph = convertedData.DocumentFirstParagraph; // the "text only" content of the first document paragraph for preview purposes
// write the content (like images) of the ODT document to the file system to make it available to the web browser
foreach (var articleContent in convertedData.EmbedContent)
{
var contentLink = Path.Combine(_hostingEnvironment.WebRootPath, contentSubDirname, articleContent.LinkName);
System.IO.File.WriteAllBytes(contentLink, articleContent.Data);
}
return View();
}
Development
OdtToHtml has been developed as a part of the CrossBlog ASP.NET Core blog engine. With CrossBlog you can write your blog using the office/word processing application of your choice and of course using the ODT document format. But it can of course also be used otherwise.
Dependencies
There are no package or code dependencies other than the .NETStandard 2.0 libraries.
Missing features
- all canvas/shapes features
- outline functionality (only lists at the moment)
- TOC formatting
- correct text flow around images and other content
Contact me if something important is missing or doesn't work properly.
License
The source code is mostly licensed under GNU General Public License, version 2 of the license. Please refer to the source code file headers for detailed licensing information.
Version history
0.25.1.211 (alpha)
- improved rendering of list styles and list fonts
- improved text decorations
- added anchor links for the document TOC
- the conversion now also returns a CSS property value list with all used font families
0.2.18.1 (alpha)
- first alpha release
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.27.10.301-alpha | 1,235 | 10/30/2018 |
0.26.2.111-alpha | 850 | 2/11/2018 |
0.26.2.102-alpha | 836 | 2/10/2018 |
0.25.1.211 | 4,328 | 1/21/2018 |
0.2.18.1 | 1,137 | 1/18/2018 |
alpha release