Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

Printing Documents from C# using OpenOffice Writer

, 7 May 2008
Simple printing solution based on OpenOffice suite
odf_printing.zip
odf_printing
bin
Debug
ICSharpCode.SharpZipLib.dll
OdfPrinting.exe
sample.ods
sample.odt
ICSharpCode.SharpZipLib.dll
OdfPrinting.csproj.user
odf_printing_v2.zip
ICSharpCode.SharpZipLib.dll
OdfPrinting.exe
sample.ods
sample.odt
ICSharpCode.SharpZipLib.dll
OdfPrinting.csproj.user
odt_printing.zip
odt_printing
bin
Debug
ICSharpCode.SharpZipLib.dll
OdtPrinting.exe
sample.odt
ICSharpCode.SharpZipLib.dll
OdtPrinting.csproj.user
using System;
using System.Xml;
using System.Collections;

// Class for printing of odt files in OpenOffice
public class Odt : Odf
{
	OdtDocFields inputs;

	public Odt(string odtFile) : base(odtFile)
	{
	}

	#region Collections

	// Collection used to access document input fields
	public class OdtDocFields
	{
		private Odt odt;
		private Hashtable ht;
		private string[] fieldNames;

		public OdtDocFields(Odt odt)
		{
			this.odt = odt;
			this.ht = new Hashtable();
		}

		public int Count
		{
			get
			{
				return ht.Count;
			}
		}

		public string this[string fieldName]
		{
			get
			{
				return ((XmlNode)(ht[fieldName])).InnerText;
			}
			set
			{
				((XmlNode)(ht[fieldName])).InnerText = (string) value;
			}
		}

		public void AddNode(XmlNode node)
		{
			string desc = node.Attributes["text:description"].Value;
			ht[desc] = node;
		}

		public string[] FieldNames
		{
			get
			{
				if(fieldNames == null)
				{
					fieldNames = new string[ht.Count];
					ht.Keys.CopyTo(fieldNames, 0);
				}
				return fieldNames;
			}
		}
	}

	#endregion

	public OdtDocFields Inputs
	{
		get
		{
			return inputs;
		}
	}

	protected override string GetFileExt()
	{
		return "odt";
	}

	protected override string GetOoAppType()
	{
		return "writer";
	}

	private void PopulateInputs(XmlNode node)
	{
		if(node.Name == "text:text-input")
		{
			inputs.AddNode(node);
		}
		foreach(XmlNode child in node.ChildNodes)
		{
			PopulateInputs(child);
		}
	}

	public override void Load(string odtTemplateFile)
	{
		base.Load(odtTemplateFile);

		// Add all input fields in collection
		inputs = new OdtDocFields(this);
		PopulateInputs(doc.DocumentElement);
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License

Share

About the Author

psonek
Software Developer ODP-software spol. s r. o.
Czech Republic Czech Republic
Started programming on Z80. Later on PC i started playing with Linux and joined the DotGNU project. Here i implemented debugger and fixed a few easy bugs. I have also started project PortableStudio which will be DotGNU's IDE. At work i am developing ticket system for Czech Railways and systems for on board sales for Czech Airways.

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 7 May 2008
Article Copyright 2008 by psonek
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid