Converting Office files to PDF Format using a Web Services based interface

Posted at: 16:44 on 02 December 2009 by Muhimbi

Web-Services-Icon One of the key changes introduced with the release of the Muhimbi PDF Converter Server Platform and API 3.0 is the ability to convert typical Office files via a web services based interface. This makes it very simple to convert typical Office files to PDF format from your own .NET, Java or any other web services capable environment.

This post describes the key features of the web services based interface and provides a simple example describing how to convert a document to PDF format. Source code for a more comprehensive demo is available for download as well. Feel free to contact us if you have any questions.


Let’s make sure all prerequisites are in place before we start our tutorial.

  1. Download the PDF Converter Server Platform.
  2. Install it in-line with chapter 2 of the included Administration Guide.


Key Features

Key Features of the Muhimbi Server Platform are:

  1. Convert popular document types to PDF or XPS format with near perfect fidelity. At the time of writing support is available for MS-Word, PowerPoint, Excel, InfoPath, Visio and MS-Publisher, but by the time you are reading this additional document formats may have been added.
  2. Scalable architecture that allows multiple conversions to run in parallel.
  3. Runs as a Windows Service. No need to install or configure IIS or other web service frameworks.
  4. Convert password protected documents.
  5. Apply security settings to generated PDF files including encryption, password protection and multiple levels of PDF Security options to prevent users from printing documents or copy a document’s content.
  6. Generate a regular PDF file or a file in PDF/A format.
  7. Generate high resolution PDF Files optimised for printing or normal resolution files optimised for use on screen.
  8. Dynamically refresh a document’s content before generating the PDF. Ideal for merging content from SharePoint custom columns into your PDF file.
  9. Control how to deal with hidden / selected content such as PowerPoint Slides and Excel worksheets. 

In addition to the features described above, the MDCS software stack also contains a layer of functionality to control concurrency, request queuing and watchdog services to deal with unresponsive and runaway processes. More detail can be found in the brochure.

Object Model

Although the Object Model exposed by the web service is easy to understand, the system provides very powerful functionality and fine grained control to specify how the PDF file is generated.

As outlined in the image below, the web service contains 3 methods:


  • Convert: Convert the file in the sourceFile byte array using the specified openOptions and conversionSettings. The generated PDF or XPS file is returned as a byte array as well.
  • GetConfiguration: Retrieve information about which converters are supported and the associated file extensions. Consider calling this service once to retrieve a list of valid file extensions and check if a file is supported before it is submit to the web service. This will prevent a lot of redundant traffic and will increase scalability.
  • GetDiagnostics: Run a diagnostics test that carries out an internal end-to-end test for each supported document type. Call this method to check if the service and all prerequisites have been deployed correctly.

The full object model is available in the following diagram. Click to enlarge it.


PDF Converter Web Service Class Diagram. Click to enlarge.

Simple example code

The following sample shows the minimum steps required to convert a document to PDF format. In our example we are using Visual Studio and C#, but any environment that can invoke web services should be able to access the required functionality. Note that the WSDL can be found at http://localhost:41734/Muhimbi.DocumentConverter.WebService/?wsdl. A Java based example is installed alongside the product and discussed in the User & Developer Guide.

This example does not explicitly set ConversionSettings.Format. As a result the file is converted to the default PDF format. It is possible to convert files to other file formats as well by setting this property to a value of the OutputFormat enumeration. For details see this blog post.

  1. Start a new Visual Studio project and use the project type of your choice. In this example we are using a standard .net 3.0 project of type Windows Forms Application. Name it ‘Simple PDF Converter Sample’.
  2. Add a TextBox and Button control button to the form. Accept the default names of textBox1 and button1.
  3. In the Solution Explorer window, right-click References and select Add Service Reference.
  4. In the Address box enter the WSDL address listed in the introduction of this section. If the MDCS is located on a different machine then substitute localhost with the server’s name.
  5. Accept the default Namespace of ServiceReference1 and click the OK button to generate the proxy classes.
  6. Double click Button1 and replace the content of the entire code file with the following:   
using System;
using System.IO;
using System.ServiceModel;
using System.Windows.Forms;
using Simple_PDF_Converter_Sample.ServiceReference1;
namespace Simple_PDF_Converter_Sample
    public partial class Form1 : Form
        // ** The URL where the Web Service is located. Amend host name if needed.
        string SERVICE_URL = "http://localhost:41734/Muhimbi.DocumentConverter.WebService/";
        public Form1()
        private void button1_Click(object sender, EventArgs e)
            DocumentConverterServiceClient client = null;
                // ** Determine the source file and read it into a byte array.
                string sourceFileName = textBox1.Text;
                byte[] sourceFile = File.ReadAllBytes(sourceFileName);
                // ** Open the service and configure the bindings
                client = OpenService(SERVICE_URL);
                //** Set the absolute minimum open options
                OpenOptions openOptions = new OpenOptions();
                openOptions.OriginalFileName = Path.GetFileName(sourceFileName);
                openOptions.FileExtension = Path.GetExtension(sourceFileName);
                // ** Set the absolute minimum conversion settings.
                ConversionSettings conversionSettings = new ConversionSettings();
                conversionSettings.Fidelity = ConversionFidelities.Full;
                conversionSettings.Quality = ConversionQuality.OptimizeForPrint;
                // ** Carry out the conversion.
                byte[] convFile = client.Convert(sourceFile, openOptions, conversionSettings);
                // ** Write the converted file back to the file system with a PDF extension.
                string destinationFileName = Path.GetDirectoryName(sourceFileName) + @"\" +
                                             Path.GetFileNameWithoutExtension(sourceFileName) +
                                             "." + conversionSettings.Format;
                using (FileStream fs = File.Create(destinationFileName))
                    fs.Write(convFile, 0, convFile.Length);
                MessageBox.Show("File converted to " + destinationFileName);
            catch (FaultException<WebServiceFaultException> ex)
                MessageBox.Show("FaultException occurred: ExceptionType: " + 
            catch (Exception ex)
        /// <summary>
        /// Configure the Bindings, endpoints and open the service using the specified address.
        /// </summary>
        /// <returns>An instance of the Web Service.</returns>
        public static DocumentConverterServiceClient OpenService(string address)
            DocumentConverterServiceClient client = null;
                BasicHttpBinding binding = new BasicHttpBinding();
                // ** Use standard Windows Security.
                binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
                binding.Security.Transport.ClientCredentialType = 
                // ** Increase the Timeout to deal with (very) long running requests.
                binding.SendTimeout = TimeSpan.FromMinutes(30);
                binding.ReceiveTimeout = TimeSpan.FromMinutes(30);
                // ** Set the maximum document size to 40MB
                binding.MaxReceivedMessageSize = 50*1024*1024;
                binding.ReaderQuotas.MaxArrayLength = 50 * 1024 * 1024;
                binding.ReaderQuotas.MaxStringContentLength = 50 * 1024 * 1024;
                // ** Specify an identity (any identity) in order to get it past .net3.5 sp1
                EndpointIdentity epi = EndpointIdentity.CreateUpnIdentity("unknown");
                EndpointAddress epa = new EndpointAddress(new Uri(address), epi);
                client = new DocumentConverterServiceClient(binding, epa);
                return client;
            catch (Exception)
        /// <summary>
        /// Check if the client is open and then close it.
        /// </summary>
        /// <param name="client">The client to close</param>
        public static void CloseService(DocumentConverterServiceClient client)
            if (client != null && client.State == CommunicationState.Opened)

Providing the project and all controls are named as per the steps above, it should compile without errors. Run it, enter the full path to the source file, e.g. an MS-Word document, and click the button to start the conversion process. The conversion may take a few second depending on the complexity of the document.

Note that In this example we are programmatically configuring the WCF Bindings and End Points. If you wish you can use a declarative approach using the config file.

Download the source code including a compiled binary.

Complex sample code

In order to carry out internal testing we have developed an application that can be used to control each end every function exposed by the web services. The full source code as well as a compiled binary can be downloaded below.

Note that although the test harness works well and can be used to batch convert a large number of documents, this is not commercial grade code. Use at your own risk.


Download the source code including a compiled binary.

Final notes

If you wish to access the PDF Converter from your own custom SharePoint code, you may want to consider using our high level Wrapper methods. If you are not using the wrapper methods then please make sure you are invoking the web service from a user who has privileges to do so. By wrapping the code in SPSecurity.RunWithElevatedPrivileges you will automatically connect using an account in the WSS_WPG windows group, which has access by default.


Labels: , , , ,


  • Hi.
    Is there a way to convert to PDF with "Document showing markup" option enabled?
    This applies to Word documents where "Track changes" is enabled.


    By Blogger Roman, At 22 January, 2010 19:05  

  • Hi Romitch,

    This will be added to the next version (3.2). The issue tracking number is #757.

    If you want to receive a notification when that version is released then please sign up to our mailing list, RSS feed or both at

    By Blogger Muhimbi, At 25 January, 2010 10:25  

  • Hi,
    with this type of solution how do I activate the license?
    Could be possible install only PDF Converter windows service on a separate machine without Muhimbi.PDFConverter.wsp SharePoint side?


    By Blogger Unknown, At 26 January, 2010 08:29  

  • Hi Simone,

    That is correct. Just install the service and connect to the webservice as described in this article. Read section 2.2.4 of the Administration Guide for details on how to install the license.

    Drop a line if you need further assistance.

    By Blogger Muhimbi, At 26 January, 2010 08:43  

  • Ok,
    Thanks. I just sent an urgent email enquiry at

    By Blogger Unknown, At 26 January, 2010 09:10  

  • i'm running the above sample code in my local host. but i get a "Access denied" from convert stage.

    any ideas?

    stack trace:

    Server stack trace:
    at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
    at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
    at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Exception rethrown at [0]:
    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
    at Simple_PDF_Converter_Sample.ServiceReference1.DocumentConverterService.Convert(Byte[] sourceFile, OpenOptions openOptions, ConversionSettings conversionSettings)
    at Simple_PDF_Converter_Sample.ServiceReference1.DocumentConverterServiceClient.Convert(Byte[] sourceFile, OpenOptions openOptions, ConversionSettings conversionSettings) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\Simple_PDF_Converter_Sample\Simple_PDF_Converter_Sample\Service References\ServiceReference1\Reference.cs:line 992
    at Simple_PDF_Converter_Sample.Form1.button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\Simple_PDF_Converter_Sample\Simple_PDF_Converter_Sample\Form1.cs:line 42

    By Anonymous Anonymous, At 18 February, 2010 04:33  

  • Regarding the 'access denied' message. The Document Conversion Service checks if the account invoking the web service is allowed to invoke it.

    Please update the group names used for authentication in the config file as mentioned in the prerequisites section of this post. Details can be found in section 2.3.2 of the Administration Guide.

    Alternatively switch to Anonymous access, which is explained in the same section of the Admin Guide.

    I hope this helps. If you need further assistance then feel free to leave a message here or contact us using any of the means in the Contact Us link at the top right of this page.

    By Blogger Muhimbi, At 18 February, 2010 09:49  

  • Hi
    does PDF converter need Microsoft Word installed on the machine?
    i noticed when i ran the above code WINWORD.EXE came up on the task manager and dissapeared.
    my input file was a Word2007 XML file. i thought Muhimbi PDF converter is independent of Microsoft Word ?

    By Anonymous Anonymous, At 19 February, 2010 00:28  

  • Hi AJ,

    That is correct. You need the relevant office application in order to guarantee perfect conversion fidelity. We have put a considerable amount of effort into our framework to ensure Office behaves well and resources are properly managed.

    So far we have many happy customers and to the best of my knowledge no Office related problems.

    In the future we may provide PDF Conversion that doesn't require office on the conversion server, but the available options are not mature enough.

    By Blogger Muhimbi, At 19 February, 2010 08:38  

  • Can it be used to convert InfoPath forms existing on a SharePoint server? I have a requirement where I need to take the server side InfoPath form (which sits as an XML file) and convert it to PDF. Will that be possible with this Web Service way?

    By Anonymous Anonymous, At 29 April, 2010 09:54  

  • Yes, the product can be used to convert SharePoint based as well as file system based InfoPath forms.

    Have a look at the following product page as well as all the associated blog articles:

    By Blogger Muhimbi, At 29 April, 2010 10:11  

  • Would it be possible to combine a number of different word/excel files into ONE pdf file? For example, submit 3 word files and an excel spreadsheet.
    If so, what control would there be over the order that the documents were rendered, and what control would there be over the name of the compiled pdf when it is created?

    By Anonymous Dave Walmsley, At 18 May, 2010 08:00  

  • Hi Dave,

    It is possible to do that, but a little bit of programming work is required from your side. Assuming you will be using the Web Service in combination with the .net platform then you could consider the following:

    1. Convert the individual documents to PDF using web service calls as outlined in this post.

    2. Use your favourite PDF editing library, or use the one that ships as part of the Muhimbi PDF Converter, to merge the PDF files together into a single PDF. For some example code see the part of the code that deals with loading documents and the 'ImportPageRange' command in the following post:

    Naturally you will have full control over the file name.

    If you intend to do this from SharePoint or a Java based environment, or have any questions, then contact us on We are really responsive and normally reply within minutes.

    By Blogger Muhimbi, At 18 May, 2010 08:14  

  • Does anyone know how I could convert PDF into InfoPath?

    By Anonymous Anonymous, At 02 September, 2010 18:34  

  • I know it is possible to submit the contents of a PDF form to a SharePoint library, but not how to convert a form to InfoPath. Have a chat with our friends on

    By Blogger Muhimbi, At 03 September, 2010 09:38  

  • Hi,

    Is there a way we can convert all the views in infopath form to PDF.


    By Anonymous Anonymous, At 14 September, 2010 19:08  

  • Yes, all views (and attachments if you wish) can be converted. See

    By Blogger Muhimbi, At 14 September, 2010 19:18  

  • Hi,

    I tried using "PDF Converting service" with sample code you provided on the site for converting my infopath form .It has multiple views(view1,view2,view3) but its converting only the default view(view1). I am not sure whats going wrong or did i am missing anything. If this feature works we would love to buy this product.


    By Anonymous Anonymous, At 14 September, 2010 21:34  

  • I assume you have looked at the links provided in the previous answer. There are 2 things you need to do:

    1. Name the views correctly so they are all exported
    2. Request the beta, as the article mentions, as this new functionality is not yet available in the public release.

    Feel free to contact us using the support link at the top of the page. We are very responsive and love to help.

    By Blogger Muhimbi, At 14 September, 2010 21:41  

  • Thanks. When can we expect the public release of this feature. I am more excited about this feature, we want this in our production.

    By Anonymous Anonymous, At 14 September, 2010 21:47  

  • We have quite a few people testing it and have yet to receive any reports of problems. Some are running it in their production environments.

    It will come out of beta mid next month while we are waiting for the documentation to be updated. I suggest you request the beta now and start implementing your solution so it is ready to go when it comes out of beta.

    By Blogger Muhimbi, At 14 September, 2010 22:01  

  • thanks for the info. One quick question, i still dont understand why we need change the name of the views. is there an option where we can configure what views to be converted ?. as we have so many infopath forms which we want to convert.


    By Anonymous Anonymous, At 15 September, 2010 15:30  

  • Perhaps it is best to continue these questions and answers on the post about dynamically selecting InfoPath views to export at

    Regardless, the answers really are all in that post already, but I'll summarise it in here as well:

    1. You don't have to rename the view if all you want to do is export the default view to PDF, which is the standard behaviour. You don't need to update any of your existing XSN files in order to be able to do this.

    2. If you know which view or views to export to PDF beforehand, and these views are always the same, then the easiest thing to do is to rename those views to start with '_MuhimbiView'. You will need to update the source XSN file to achieve this, but all XML files that use this XSN file will automatically be updated in one go.

    3. If you don't want to or can't rename the views then you can use the alternative approach of defining a (hidden) text field named '_MuhimbiViews' anywhere in your XSN file and populate it with a comma separated list of view names to export to PDF. You can even dynamically update this list from code or from a workflow by exporting this field as a SharePoint Column.

    If you have any suggestions for a more flexible way to implement this then please let us know, but as far as I am concerned the provided functionality pretty much allows you to do whatever it is you want to do.

    Alternatively, if your forms are all browser enabled then you can use the approach that uses Forms Server to carry out the PDF Conversion. It allows the view name to be specified on the URL so perhaps that suits your scenario better. For details see

    By Blogger Muhimbi, At 15 September, 2010 15:51  

  • Its amazing to see how quick your team is responding for all questions. I appreciate excellent support.


    By Anonymous Anonymous, At 15 September, 2010 16:03  

  • Thanks,

    We will do everything in our power to make it as easy as possible for you to hand over your money to us :-)

    And we like to help.

    By Blogger Muhimbi, At 15 September, 2010 16:16  

  • Hi,

    We really like the product and it looks like it will be able to solve our issues. One quick question what we really looking forward is, the way custom action "Convert to PDF" is implemented in sharepoint, can we add new custom action to "download to pdf" instead of converting to pdf and then download it. I really appreciate your input.


    By Anonymous Anonymous, At 15 September, 2010 23:13  

  • 'Download to PDF' has already been implemented as part of the post beta 2 release. It can be used from the context menu / ribbon similar to the current 'Convert to PDF' option or it can be accessed from a link as described in

    Contact support if you want to get your hands on it early.

    By Blogger Muhimbi, At 16 September, 2010 06:23  

  • @Romitch,

    The feature you have requested (Include tracked changes when exporting to PDF) is now available. Please contact if you wish access to the latest 'post 4.0' test version.

    By Blogger Muhimbi, At 22 November, 2010 17:15  

  • Is it possible to convert office files to pdf when just the Office Viewer components are installed (and not the full Office install)?

    By Blogger Joyceee, At 06 January, 2011 18:27  

  • Hi Joyceee,

    You don't need anything installed on the client machines, but if you intend to convert MS-Office files then you do need those applications installed on the server that hosts the Muhimbi Document Conversion Service. It Guearantees optimal Conversion Fidelity. The Office Viewer components won't suffice.

    By Blogger Muhimbi, At 06 January, 2011 19:18  

  • Could i use this to convert a web based infopath form and if so how would i convert a particular view of the form.

    By Anonymous Anonymous, At 11 May, 2011 10:07  

  • Many of our users are using exactly that scenario, for details see:

    More details can be found in the User Guide. If you need more information then please contact

    By Blogger Muhimbi, At 11 May, 2011 10:10  

  • Using "PDF Converter Services" alone, how do I merge a number of different word/excel files into ONE single pdf file?
    i.e. if I provide one word file, one Excel and one text file and it creates one PDF with all three documents in the same PDF file.
    Don't have sharepoint environment, so can't use any sharepoint product.

    Sanjay Jindal

    By Anonymous Sanjay Jindal, At 02 June, 2011 12:03  

  • Hi Sanjay,

    Convert and merge is part of the recently released 5.0. For details and sample code see

    By Blogger Muhimbi, At 02 June, 2011 12:11  

  • Hi,
    I want to break one pdf file to multiple pdf files because of size issues.
    I have multiple files (word, excel etc.), when i convert these files into pdf file the size is very big (around 25 mb). So I want to break this pdf file to multiple pdf files.

    Is it possible?.

    Shailendra Jain

    By Blogger Shailendra Jain, At 04 October, 2011 08:23  

  • Hi Shailendra,

    Splitting PDFs is possible in an upcoming version, please contact us at

    By Blogger Muhimbi, At 04 October, 2011 08:35  

  • Hi ... do we need to purchase license in order to use your web service ?

    By Blogger Dhaval Raval, At 11 October, 2011 19:37  

  • Hi Dhaval,

    The web service is not something we host on the public internet. You need to purchase the software and install it on your own servers.

    By Blogger Muhimbi, At 11 October, 2011 20:56  

  • Is there a way to convert infopath to PDF along with the version history. I need a final pdf with the current inforpath form.document along with previous iterations, metadata like changed by, time/date, what columns were changed, values changed etc. Thanks

    By Blogger Hemani, At 19 October, 2011 16:42  

  • Hi Hemani,

    We provide extensive support for InfoPath to PDF Conversion, see this range of articles:

    Your request is rather specific though and you will need to do a little bit of work to request the historical versions of the form and then call into our 'merge logic', see

    I hope this helps, otherwise contact us at

    By Blogger Muhimbi, At 19 October, 2011 16:46  

  • Hi!
    How can I convert xlsx to xls? conversionSettings.OutputFormat contains only two values - PDF or XPS, so I can't find the way to convert to xls.

    By Blogger Elis, At 10 July, 2012 11:01  

  • Hi Elis,

    You need to run version 6.0 of the software and refresh your webservice proxies. See

    By Blogger Muhimbi, At 10 July, 2012 11:15  

  • Hi,

    I am looking for something like this

    Annotation on TIFF and PDF
    TIFF to PDF
    Word to PDF
    RTF to PDF

    We deal with kind of big files usually 500 pages to 2000 pages of documents (TIFF, Word, RTF ...). All files are stored directly (stream) on to the database. So thing is we are trying to provide all these documents in PDF format after adding time stamp and our company name.

    Could you please let me know if you have a sample .net code to do that ?, may be one for Word and one for RTF ?

    Thank you

    By Blogger venu, At 20 July, 2012 06:44  

  • Hi Venu,

    I am not sure what you mean with annotation on TIFF, but the rest should be no problem. The blog post on this page contains sample code.

    More can be found at

    Feel free to contact if you have further questions.

    By Blogger Muhimbi, At 20 July, 2012 07:53  

  • I downloaded the demo and it's not working ... What can i do ??

    By Blogger Noha Basiony, At 07 February, 2013 09:47  

  • Hi Noha,

    "It is not working" is not a very detailed description :-). Please contact with a description of the problem you are experiencing. Please include relevant messages from the Windows Application Event log.

    Before contacting the support desk please double check that the software has been installed in line with Chapter 2 of the Administration Guide.

    By Blogger Muhimbi, At 07 February, 2013 09:56  

  • Does it support converting Docx with Content Controls to PDF?

    By Blogger pdude, At 19 November, 2015 08:30  

  • Content controls should work just fine, but if you want to run a quick test send a sample document to and we'll run it through.

    By Blogger Muhimbi, At 19 November, 2015 09:19  

  • hey

    After converting there is a guid in header of the document. is it possible to avoid this?

    By Blogger Unknown, At 20 April, 2020 13:00  

  • Not sure what you are referring to, please reach out to for assistance.

    By Blogger Muhimbi, At 20 April, 2020 13:03  

Post a Comment

Subscribe to Post Comments [Atom]

Subscribe to News feed