Power Point Viewer for .NET Application

Power Point Viewer for .NET Application

Power point viewer through Open Office.

1) Install open office.

2) Following are the dll to be used that will be found in GAC MSIL

usingSystem.Threading;

usinguno.util;

usingunoidl.com.sun.star.lang;

usingunoidl.com.sun.star.uno;

usingunoidl.com.sun.star.bridge;

usingunoidl.com.sun.star.frame;

usingunoidl.com.sun.star.text;

usingunoidl.com.sun.star.beans;

usingunoidl.com.sun.star.util;

usinguno;

//com.sun.star.comp.

namespacePPT_Convertor

{

public class Class1

{

public static void ConvertToPPT(string inputFile, string outputFile)

{

if (ConvertExtensionToFilterType(Path.GetExtension(inputFile)) == null)

throw new InvalidProgramException(“Unknown file type for OpenOffice. File = ” + inputFile);

StartOpenOffice();

3)Get a ComponentContext of bootstrap

unoidl.com.sun.star.uno.XComponentContextxContext = Bootstrap.bootstrap();

4) Get MultiServiceFactory

XMultiServiceFactoryxRemoteFactory = (XMultiServiceFactory)xContext.getServiceManager();

5) Get a CompontLoader

XComponentLoaderaLoader =           (XComponentLoader)xRemoteFactory.createInstance(“com.sun.star.frame.Desktop”);            //Load the sourcefile

XComponentxComponent = null;

try

{

xComponent = InitDocument(aLoader,

PathConverter(inputFile), “_blank”);

6) Wait for it to load

while (xComponent == null)

{

Thread.Sleep(1000);

}

7) Save/export the document

SaveDocument(xComponent, inputFile, PathConverter(outputFile));

}

finally

{

if (xComponent != null) xComponent.dispose();

}

}

private static void StartOpenOffice()

{

varps = Process.GetProcessesByName(“soffice.exe”);

if (ps.Length != 0)

throw new InvalidProgramException(“OpenOffice is not installed?”);

if (ps.Length> 0)

return;

var p = new Process

{

StartInfo =

{

Arguments = “-headless -nofirststartwizard”,

FileName = “soffice.exe”,

CreateNoWindow = true                }

};

var result = p.Start();

if (result == false)

throw new InvalidProgramException(“OpenOffice failed to start.”);

}

private static void SaveDocument(XComponentxComponent, string sourceFile, string destinationFile)

{

varpropertyValues = new PropertyValue[2];

8) Setting the flag for overwriting

propertyValues[1] = new PropertyValue { Name = “Overwrite”, Value = new Any(true) };

propertyValues[0] = new PropertyValue

{

Name = “FilterName”,

Value = new Any(ConvertExtensionToFilterType(Path.GetExtension(sourceFile)))

};

((XStorable)xComponent).storeToURL(destinationFile, propertyValues);

}

private static XComponentInitDocument(XComponentLoaderaLoader, string file, string target)

{

varopenProps = new PropertyValue[1];

openProps[0] = new PropertyValue { Name = “Hidden”, Value = new Any(true) };

varxComponent = aLoader.loadComponentFromURL(

file, target, 0,

openProps);

returnxComponent;

}

private static string Converter(string file)

{

if (string.IsNullOrEmpty(file))

throw new NullReferenceException(“Null “);

9)Replace the files

returnString.Format(“file://”, file.Replace(@”\”, “/”));

}

10) Type of extension user wants

public static string Extension(string extension)

{

switch (extension)

{

case “.doc”:

case “.docx”:

case “.txt”:

case “.rtf”:

case “.html”:

case “.htm”:

case “.xml”:

case “.odt”:

case “.wps”:

case “.wpd”:

return “writer_pdf_Export”;

case “.xls”:

case “.xlsb”:

case “.xlsx”:

case “.ods”:

return “calc_pdf_Export”;

case “.ppt”:

case “.pptx”:

case “.odp”:

return “impress_pdf_Export”;

default:

return null;

}

}

}

}

Tags:
  • .NET application,
  • Power Point Viewer .NET,
  • Leave a Reply