Click here to Skip to main content
15,745,335 members
Articles / Programming Languages / XML
Posted 6 Oct 2006


65 bookmarked

Converting Microsoft Word Document to PDF format using (Portable)

Rate me:
Please Sign up or sign in to vote.
3.67/5 (18 votes)
6 Oct 2006CPOL5 min read
An article on using Portable to convert a Word document to PDF without requiring you to install on client machines.

Convert Microsoft Word Documents to PDF using



This article explains a way to use Portable to convert a Microsoft Word Document to PDF Format. The purpose of using Portable is not having to install on client machines. The operation is very simple, we just execute Portable - as if we were running it from the command line - from our code, with some arguments that indicate it to run a macro which handles the conversion.

To my knowledge, there are two articles that explain how to do this conversion, on CodeProject:

The former is a very complicated way and you have to install MS-Office. You would have this installed anyway if you are working with Word documents though; the second one requires that you have installed, which is not that bad but I wanted to avoid the task of installing it by using an XCopy kind of method.


Before running the demo or your application using the code, you need to download and extract Portable into the same directory the application resides in. Version 2.0.3 or later should work fine due to a bug that has been fixed, and allows us to run Portable hidden. After you have done that, you will need to add the following macro.

The macro

Execute OpenOfficePortable.exe inside the OpenOfficePortable\ directory where you extracted the files; the first time you run it, a wizard will show up. Follow the instructions, you don't need to register for the application to work. After you've done that you should see the main window.

Choose Tools->Macros->Organize Macros-> Basic main window

Click "Organizer..." and then create a new library within the tab Libraries, name it "ConversionLibrary"

Create the new library

Change to the Modules tab, select "ConversionLibrary", and create a new module called "PDFConversion"

create the new module

Once you've done that, click the Edit button to open the macro editor. The default is to already have a macro called Main. You can replace it or leave it. Paste the following code into the editor, save and close:

REM  *****  BASIC  *****
Sub ConvertWordToPDF( cSourceFile , cDestinationFile)
   cURL = ConvertToURL( cSourceFile )
   ' Open the document.
   ' Just blindly assume that the document
   ' is of a type that OOo will
   '  correctly recognize and open -- 
   '   without specifying an import filter.

   oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, _
          Array(MakePropertyValue( "Hidden", True ),) )

   cURL = ConvertToURL( cDestinationFile )
   ' Save the document using a filter.   
   oDoc.storeToURL( cURL, _
     Array(MakePropertyValue( "FilterName", "writer_pdf_Export" ),)
   oDoc.close( True )
End Sub

Function MakePropertyValue( Optional cName As String, _
         Optional uValue ) As
   Dim oPropertyValue As New
   If Not IsMissing( cName ) Then
      oPropertyValue.Name = cName
   If Not IsMissing( uValue ) Then
      oPropertyValue.Value = uValue
   MakePropertyValue() = oPropertyValue
End Function 

The original macro was found in the forum.

I modified it to fit my needs, so can you.

Now you should be able to run the demo application or your own application. If you've done this, you probably have noticed an Portable splash screen. To disable this behavior, read the Hiding Portable splash screen section below. If you used different names for the library, module, macro, directory of Portable or the executable name; you should change those values in the application configuration file (UsingOpenOffice.exe.config in the demo).


If you are using the code in your own application, you must add an application configuration file with the next keys in the appSettings section, or an exception will be thrown.

<?xml version="1.0" encoding="utf-8" ?>
        <add key="PortableOpenOfficeDirectory" 
        <add key="PortableOpenOfficeExecutable" 
        <add key="PortableOpenOfficeConversionLibrary" 
        <add key="PortableOpenOfficeConversionModule" 
        <add key="PortableOpenOfficeConversionFunction" 

Hiding Portable splash screen

To hide the Portable splash screen, copy the file OpenOfficePortable.ini from the OpenOfficePortable\Other\OpenOfficePortableSource directory to
OpenOfficePortable\ and edit it changing the value of DisableSplashScreen=false to DisableSplashScreen=true. I've also changed the value of WaitForOpenOffice=false to WaitForOpenOffice=true. Read the documentation of Portable for more options.

Copy and modify the configuration file



There are known issues on using Portable, you should read at least this article. If you can run Portable and do the conversion manually, chances for the code to run properly are better.

Long Paths and Odd Characters - doesn't like running from overly long paths. So, while it will work directly from your desktop... if you have it within a subdirectoy on your desktop, it will probably fail claiming that some files are corrupted. also doesn't like certain characters like dollar signs in the path. This is why it's best to have the OpenOfficePortable directory in the root of your drive, or within a PortableApps directory in the root of your drive. The exact length is being determined and the next release of the launcher will check for this.

So, try to locate your application or the demo in a short path so that the Portable path is for example: c:\Program Files\Your Company\Your Program\OpenOfficePortable will probably work, but if you try something like: C:\Documents and Settings\Your User\My Documents\Visual Studio Projects\Your Project\bin\Debug\OpenOfficePortable will probably fail.

Using the code

After you've done everything that is required - downloaded Portable and extracted it into the same folder of the application, added the macro and configured the application and the Portable configuration files if needed - you may use the code simply by adding the file OpenOffice.cs to your project or adding a reference to the DLL and then calling it in the following manner:

//using PortableOpenOffice;//uncomment this if you added a reference to the dll

Points of Interest

Even though this article explains how to use Portable to convert a Microsoft Word Document to PDF Format, it could be used to do many other conversions. You only need to modify the macro used in this example. Even without modifying the macro, you could do conversions from any supported format to PDF because we relied - not specifying any import filter in the macro - that the document would be recognized and opened by the


This document presented a very simple way to convert Microsoft Word Document to PDF format. All the real work is done by so be sure to visit their site and read the license on their software. You should also visit this website which has done a great work on doing many applications portable (for us not having to install software).


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Web Developer
Mexico Mexico
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

QuestionNeed help Pin
Member 1463793229-Oct-19 0:50
Member 1463793229-Oct-19 0:50 
QuestionDll OpenOffice Pin
Member 1068396524-Mar-14 7:09
Member 1068396524-Mar-14 7:09 
Questionvery nice work Pin
Member 391328327-Feb-14 2:47
Member 391328327-Feb-14 2:47 
QuestionOpen Office Size Reduction Pin
renegade0912-Oct-13 22:48
renegade0912-Oct-13 22:48 
AnswerRe: Open Office Size Reduction Pin
cirovladimir3-Oct-13 12:46
cirovladimir3-Oct-13 12:46 
GeneralRe: Open Office Size Reduction Pin
renegade0916-Oct-13 22:32
renegade0916-Oct-13 22:32 
QuestionException in macros Pin
kranthi_01319-Sep-13 2:35
kranthi_01319-Sep-13 2:35 
GeneralExcelent Pin
keplerk26-Jun-13 18:42
keplerk26-Jun-13 18:42 
QuestionRunning a Script to Convert PDF Pin
byronsteffan17-Jun-13 1:44
byronsteffan17-Jun-13 1:44 
QuestionConversion of DOCX Documents Pin
byronsteffan12-Jun-13 3:32
byronsteffan12-Jun-13 3:32 
AnswerRe: Conversion of DOCX Documents Pin
cirovladimir12-Jun-13 8:08
cirovladimir12-Jun-13 8:08 
GeneralRe: Conversion of DOCX Documents Pin
byronsteffan17-Jun-13 1:02
byronsteffan17-Jun-13 1:02 
QuestionSessions are expired Pin
rajapalavesam11-Jan-12 0:41
rajapalavesam11-Jan-12 0:41 
QuestionApplication logged out Pin
rajapalavesam10-Jan-12 18:19
rajapalavesam10-Jan-12 18:19 
BugApplication logged out Pin
rajapalavesam10-Jan-12 18:17
rajapalavesam10-Jan-12 18:17 
QuestionError - Expected ")" Pin
Lectrician4-Jan-12 5:35
Lectrician4-Jan-12 5:35 
AnswerRe: Error - Expected ")" Pin
cirovladimir4-Jan-12 12:54
cirovladimir4-Jan-12 12:54 
GeneralRe: Error - Expected ")" Pin
Lectrician5-Jan-12 5:44
Lectrician5-Jan-12 5:44 
QuestionImages in word file does't processed Pin
Ravi Mori8-Sep-11 19:47
Ravi Mori8-Sep-11 19:47 
AnswerRe: Images in word file does't processed Pin
cirovladimir9-Sep-11 7:19
cirovladimir9-Sep-11 7:19 
GeneralProblem with code bar in document Pin
Feferes.net7-Oct-10 11:45
Feferes.net7-Oct-10 11:45 
Generalproblem Using in Web Application [modified] Pin
Tyrone_dude20-Jan-10 1:37
Tyrone_dude20-Jan-10 1:37 
GeneralRe: problem Using in Web Application Pin
Charles Kong18-Feb-10 3:32
Charles Kong18-Feb-10 3:32 
GeneralRe: problem Using in Web Application Pin
cirovladimir18-Feb-10 3:39
cirovladimir18-Feb-10 3:39 
Generalproblem on window server 2008 Pin
shailendra118717-Jan-10 23:22
shailendra118717-Jan-10 23:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.