Click here to Skip to main content
11,920,156 members (58,148 online)
Click here to Skip to main content
Add your own
alternative version


65 bookmarked

Converting Microsoft Word Document to PDF format using (Portable)

, 6 Oct 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
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)


About the Author

Web Developer
Mexico Mexico
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionDll OpenOffice Pin
Member 1068396524-Mar-14 8:09
memberMember 1068396524-Mar-14 8:09 
Questionvery nice work Pin
Member 391328327-Feb-14 3:47
memberMember 391328327-Feb-14 3:47 
QuestionOpen Office Size Reduction Pin
renegade0912-Oct-13 23:48
memberrenegade0912-Oct-13 23:48 
AnswerRe: Open Office Size Reduction Pin
cirovladimir3-Oct-13 13:46
membercirovladimir3-Oct-13 13:46 
GeneralRe: Open Office Size Reduction Pin
renegade0916-Oct-13 23:32
memberrenegade0916-Oct-13 23:32 
QuestionException in macros Pin
Member 995352819-Sep-13 3:35
memberMember 995352819-Sep-13 3:35 
GeneralExcelent Pin
Member 786715526-Jun-13 19:42
memberMember 786715526-Jun-13 19:42 
QuestionRunning a Script to Convert PDF Pin
byronsteffan17-Jun-13 2:44
memberbyronsteffan17-Jun-13 2:44 
QuestionConversion of DOCX Documents Pin
byronsteffan12-Jun-13 4:32
memberbyronsteffan12-Jun-13 4:32 
AnswerRe: Conversion of DOCX Documents Pin
cirovladimir12-Jun-13 9:08
membercirovladimir12-Jun-13 9:08 
GeneralRe: Conversion of DOCX Documents Pin
byronsteffan17-Jun-13 2:02
memberbyronsteffan17-Jun-13 2:02 
QuestionSessions are expired Pin
rajapalavesam11-Jan-12 1:41
memberrajapalavesam11-Jan-12 1:41 
QuestionApplication logged out Pin
rajapalavesam10-Jan-12 19:19
memberrajapalavesam10-Jan-12 19:19 
BugApplication logged out Pin
rajapalavesam10-Jan-12 19:17
memberrajapalavesam10-Jan-12 19:17 
QuestionError - Expected ")" Pin
Lectrician4-Jan-12 6:35
memberLectrician4-Jan-12 6:35 
AnswerRe: Error - Expected ")" Pin
ciro_vladimir4-Jan-12 13:54
memberciro_vladimir4-Jan-12 13:54 
GeneralRe: Error - Expected ")" Pin
Lectrician5-Jan-12 6:44
memberLectrician5-Jan-12 6:44 
QuestionImages in word file does't processed Pin
Ravi Mori8-Sep-11 20:47
memberRavi Mori8-Sep-11 20:47 
AnswerRe: Images in word file does't processed Pin
ciro_vladimir9-Sep-11 8:19
memberciro_vladimir9-Sep-11 8:19 
GeneralProblem with code bar in document Pin
Feferes.net7-Oct-10 12:45
memberFeferes.net7-Oct-10 12:45 
Generalproblem Using in Web Application [modified] Pin
Tyrone_dude20-Jan-10 2:37
memberTyrone_dude20-Jan-10 2:37 
GeneralRe: problem Using in Web Application Pin
Charles Kong18-Feb-10 4:32
memberCharles Kong18-Feb-10 4:32 
GeneralRe: problem Using in Web Application Pin
ciro_vladimir18-Feb-10 4:39
memberciro_vladimir18-Feb-10 4:39 
Generalproblem on window server 2008 Pin
shailendra118718-Jan-10 0:22
membershailendra118718-Jan-10 0:22 
GeneralRe: problem on window server 2008 Pin
ciro_vladimir18-Jan-10 5:13
memberciro_vladimir18-Jan-10 5:13 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151120.1 | Last Updated 6 Oct 2006
Article Copyright 2006 by cirovladimir
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid