DDDN.OdtToHtml 0.25.1.211

Open Document Text Format (ODT) to HTML Converter

There is a newer prerelease version of this package available.
See the version list below for details.
Install-Package DDDN.OdtToHtml -Version 0.25.1.211
dotnet add package DDDN.OdtToHtml --version 0.25.1.211
<PackageReference Include="DDDN.OdtToHtml" Version="0.25.1.211" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DDDN.OdtToHtml --version 0.25.1.211
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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

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

Release Notes

alpha release

  • .NETStandard 2.0

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
0.27.10.301-alpha 135 10/30/2018
0.26.2.111-alpha 233 2/11/2018
0.26.2.102-alpha 218 2/10/2018
0.25.1.211 319 1/21/2018
0.2.18.1 375 1/18/2018