Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 549823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:13:26+00:00 2026-05-13T11:13:26+00:00

I am looking for a library which will allow me to render text and

  • 0

I am looking for a library which will allow me to render text and graphics output onto a PDF document. (Cairo is certainly an option.) I would like to know how OpenOffice writes PDF files to see if I could use the same library. What library is being used by OpenOffice for PDF export?

Edit: I am looking for a C or C++ library.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:13:26+00:00Added an answer on May 13, 2026 at 11:13 am

    I looked everywhere to find out how to export any document to PDF using OpenOffice. I finally found a buried post in the OpenOffice forums that got me 90% there. Here is my 100% solution. Works with OpenOffice 3.1. You must install OpenOffice to use this code. You must include references to cli_basetypes, cli_cppuhelper, cli_oootypes, cli_ure, cli_uretypes. These dll references are found in the OpenOffice SDK. Sorry, but this is in C#.. not C/C++. HTH someone.

    using unoidl.com.sun.star.lang;
    using unoidl.com.sun.star.uno;
    using unoidl.com.sun.star.bridge;
    using unoidl.com.sun.star.frame;
    using unoidl.com.sun.star.beans;
    
    public static void ConvertToPDF(string inputFile, string outputFile)
            {
                if (ConvertExtensionToFilterType(Path.GetExtension(inputFile)) == null)
                    throw new InvalidProgramException("Unknown file type for OpenOffice. File = " + inputFile);
    
                StartOpenOffice();
    
                //Get a ComponentContext
                unoidl.com.sun.star.uno.XComponentContext xLocalContext =
                   uno.util.Bootstrap.bootstrap();
                //Get MultiServiceFactory
                unoidl.com.sun.star.lang.XMultiServiceFactory xRemoteFactory =
                   (unoidl.com.sun.star.lang.XMultiServiceFactory)
                   xLocalContext.getServiceManager();
                //Get a CompontLoader
                XComponentLoader aLoader =
                   (XComponentLoader)xRemoteFactory.createInstance("com.sun.star.frame.Desktop");
                //Load the sourcefile
    
                XComponent xComponent = null;
                try
                {
                    xComponent = initDocument(aLoader,
                       PathConverter(inputFile), "_blank");
                    //Wait for loading
                    while (xComponent == null)
                    {
                        System.Threading.Thread.Sleep(1000);
                    }
    
                    // save/export the document
                    saveDocument(xComponent, inputFile, PathConverter(outputFile));
    
                }
                catch { throw; }
                finally { xComponent.dispose(); }
    
            }
    
            private static void StartOpenOffice()
            {
                Process[] ps = Process.GetProcessesByName("soffice.exe");
                if (ps != null)
                {
                    if (ps.Length > 0)
                        return;
                    else
                    {
                        Process p = new Process();
                        p.StartInfo.Arguments = "-headless -nofirststartwizard";
                        p.StartInfo.FileName = "soffice.exe";
                        p.StartInfo.CreateNoWindow = true;
                        bool result = p.Start();
                        if (result == false)
                            throw new InvalidProgramException("OpenOffice failed to start.");
                    }
                }
                else
                {
                    throw new InvalidProgramException("OpenOffice not found.  Is OpenOffice installed?");
                }
            }
    
            private static XComponent initDocument(XComponentLoader aLoader, string file, string target)
            {
                PropertyValue[] openProps = new PropertyValue[1];
                openProps[0] = new PropertyValue();
                openProps[0].Name = "Hidden";
                openProps[0].Value = new uno.Any(true);
    
    
                XComponent xComponent = aLoader.loadComponentFromURL(
                   file, target, 0,
                   openProps);
    
                return xComponent;
            }
    
    
            private static void saveDocument(XComponent xComponent, string sourceFile, string destinationFile)
            {
                PropertyValue[] propertyValues = new PropertyValue[2];
                propertyValues = new PropertyValue[2];
                // Setting the flag for overwriting 
                propertyValues[1] = new PropertyValue();
                propertyValues[1].Name = "Overwrite";
                propertyValues[1].Value = new uno.Any(true);
                //// Setting the filter name 
                propertyValues[0] = new PropertyValue();
                propertyValues[0].Name = "FilterName";
                propertyValues[0].Value = new uno.Any(ConvertExtensionToFilterType(Path.GetExtension(sourceFile)));
                ((XStorable)xComponent).storeToURL(destinationFile, propertyValues);
    
            }
    
    
            private static string PathConverter(string file)
            {
                if (file == null || file.Length == 0)
                    throw new NullReferenceException("Null or empty path passed to OpenOffice");
    
                return String.Format("file:///{0}", file.Replace(@"\", "/"));
    
            }
    
            public static string ConvertExtensionToFilterType(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 ".ods":
                        return "calc_pdf_Export";
                    case ".ppt":
                    case ".pptx":
                    case ".odp":
                        return "impress_pdf_Export";
    
                    default: return null;
                }
            }
    
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 405k
  • Answers 405k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Do the following sudo /Developer/Library/uninstall-devtools –mode=all (This will uninstall the… May 15, 2026 at 5:41 am
  • Editorial Team
    Editorial Team added an answer I'm not sure if this is what you are trying… May 15, 2026 at 5:41 am
  • Editorial Team
    Editorial Team added an answer It seems likely that memcache (which is implemented on the… May 15, 2026 at 5:41 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.