---
title: "C# Document Converter API for PDF conversion | Nutrient Document Converter Services"
canonical_url: "https://www.nutrient.io/guides/document-converter/document-converter-services/conversion/csharp-convert-to-office/"
md_url: "https://www.nutrient.io/guides/document-converter/document-converter-services/conversion/csharp-convert-to-office.md"
last_updated: "2026-05-23T00:08:18.015Z"
description: "Convert more than 100 file types to PDF or PDF to Microsoft Office and SVG using the C# Document Converter API — with fast and reliable integration for your applications or workflows."
---

# Convert PDF to MS Office with C#

This code uses the `OpenService` and `CloseService` methods from the PDF Converter API [`DocumentConverterServiceClient`](https://www.nutrient.io/guides/document-converter/document-converter-services/knowledge-base/open-and-close-documentconverterserviceclient/) sample code:

```csharp

        /// <summary>
        /// Perform PDF to DOCX on the supplied file, writing the result into the target folder.
        /// </summary>
        /// <param name="ServiceURL">URL endpoint for the PDF Converter service</param>
        /// <param name="sourceFileName">Source filename</param>
        /// <param name="targetFolder">Target folder to receive the output file</param>
        /// <param name="officeType">Office type for output</param>
        static void PDFToOffice(string ServiceURL, string sourceFileName, string targetFolder, OfficeTypes officeType)
        {
            DocumentConverterServiceClient client = null;
            try
            {
                // Create minimum `OpenOptions` object.
                OpenOptions openOptions = new OpenOptions();
                openOptions.OriginalFileName = Path.GetFileName(sourceFileName);

                // Create minimum `PatternHighlightSettings`.
                PDFToOfficeSettings pDFToOfficeSettings = new PDFToOfficeSettings();
                pDFToOfficeSettings.OfficeType = officeType;
                pDFToOfficeSettings.PageRange = "*";
                // Create target folder if required
                if (!Directory.Exists(targetFolder))
                {
                    Directory.CreateDirectory(targetFolder);
                }
                // ** Read the source file into a byte array.
                byte[] sourceFile = File.ReadAllBytes(sourceFileName);

                // ** Open the service and configure the bindings.
                client = OpenService(ServiceURL);

                // ** Carry out the conversion.
                byte[] result = client.PDFToOffice(sourceFile, openOptions, pDFToOfficeSettings);

                // ** Save the results
                if (result!= null)
                {
                    if (!Directory.Exists(targetFolder))
                    {
                        Directory.CreateDirectory(targetFolder);
                    }
                    string filename = Path.GetFileNameWithoutExtension(sourceFileName);
                    string destinationFileName = Path.GetFullPath(Path.Combine(targetFolder, filename + $".{pDFToOfficeSettings.OfficeType}"));
                    using (FileStream fs = File.Create(destinationFileName))
                    {
                        fs.Write(result, 0, result.Length);
                        fs.Close();
                    }
                    Console.WriteLine("File converted to " + destinationFileName);
                    // Open the destination file.
                    ProcessStartInfo psi = new ProcessStartInfo();
                    psi.FileName = destinationFileName;
                    psi.UseShellExecute = true;
                    Process.Start(psi);
                }
                else
                {
                    Console.WriteLine("Nothing returned");
                }
            }
            catch (FaultException<WebServiceFaultException> ex)
            {
                Console.WriteLine($"FaultException occurred: ExceptionType: {ex.Detail.ExceptionType.ToString()}");
                Console.WriteLine();
                Console.WriteLine($"Error Detail: {string.Join(Environment.NewLine, ex.Detail.ExceptionDetails)}");
                Console.WriteLine($"Error message: {ex.Message}");
                Console.WriteLine();
                Console.WriteLine($"Error reason: {ex.Reason}");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine(ex.Data.ToString());
            }
            finally
            {
                if (client!= null)
                {
                    CloseService(client);

                }
            }

        }

```
---

## Related pages

- [Convert PPTX to SVG with C#](/guides/document-converter/document-converter-services/conversion/csharp-convert-pptx-to-svg.md)
- [Convert documents effortlessly with .NET](/guides/document-converter/document-converter-services/conversion/dotnet-core-server.md)
- [Effortlessly convert files to PDF with C# .NET](/guides/document-converter/document-converter-services/conversion/csharp-server.md)
- [Convert PDF to SVG with C#](/guides/document-converter/document-converter-services/conversion/csharp-convert-to-svg.md)
- [Convert documents to PDF with C#](/guides/document-converter/document-converter-services/conversion/csharp.md)
- [Effortlessly convert documents with Java API](/guides/document-converter/document-converter-services/conversion/java-server.md)
- [Effortlessly convert documents to PDF using Java](/guides/document-converter/document-converter-services/conversion/java.md)
- [Convert 100+ file types to PDF with .NET](/guides/document-converter/document-converter-services/conversion/dotnet-core.md)
- [Effortless document conversion with our PHP API](/guides/document-converter/document-converter-services/conversion/php.md)
- [Convert documents to PDF with REST API](/guides/document-converter/document-converter-services/conversion.md)
- [Convert PDFs and documents using our JavaScript REST API](/guides/document-converter/document-converter-services/conversion/javascript.md)
- [Easily convert 100+ file types to PDF with PHP](/guides/document-converter/document-converter-services/conversion/php-server.md)
- [Convert PDFs and Documents Using Ruby on Your Server](/guides/document-converter/document-converter-services/conversion/ruby.md)

