Ask Your Question

Programmatic method to extract file extension association with filters? [closed]

asked 2012-10-30 17:04:01 +0200

S. Lock gravatar image

Hi, I'm using C# to automate LibreOffice to convert documents into PDFs via the export filters. Is there a nice programmatic way to assign the export filter to a particular file type extensions? Currently my code looks like this:

        switch (extension)
            case ".doc":
            case ".docx":
            case ".txt":
            case ".rtf":
            case ".html":
            case ".htm":
            case ".xml":
            case ".odt":
            case ".wps":
            case ".wpd":
            case ".lwp":
                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";

                return null;

Obviously LibreOffice supports much more file extension than that, but was wondering if there a way to extract it via code, rather than "hard coding" with a switch statement like this.

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Alex Kemp
close date 2015-11-01 14:20:32.717833


The method you use will vary according to platform (GNU/Linux, MacOS, Windows, etc.) and sometimes even the desktop environment (Gnome, KDE, etc.) What platform / desktop environment are you using?

oweng gravatar imageoweng ( 2013-04-03 01:22:13 +0200 )edit

@S. Lock -- still looking for an answer here?

qubit gravatar imagequbit ( 2013-04-27 20:25:01 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2013-05-21 12:15:46 +0200

oweng gravatar image

This answer is not a solution, but it should hopefully point you in the right direction. The files containing the output filters can be found here or in /filter/source/config/fragments/filters/ if you download a copy of the source code. In simplistic terms you can extract a list of supported file extensions by running a regular expression over the files in this directory e.g.,

$ grep -hre "Extensions" /filter/source/config/fragments/types/ | grep -o "<value>.*</value>"

That will give you raw (non-type associated) output for all supported file types (including graphics formats) as shown in this file for v4.0.3.3. Obviously a more programmatic interrogation method would be required to pull out only document file types and in the groupings (writer, calc, etc. file types) you require. This is the general approach I would take.

edit flag offensive delete link more

Question Tools


Asked: 2012-10-30 17:04:01 +0200

Seen: 535 times

Last updated: May 21 '13