Convert DOC (Word 97-2003) file to PDF file using C# and .NET


Modern business applications often require integrated document conversion capabilities across multiple formats. A particularly popular task is converting Microsoft Word documents (DOC) to the universal and widely used PDF format. This is essential for ensuring compatibility, protecting content, and easily distributing information. In this overview, we'll take a detailed look at how to implement this functionality in C# and .NET using the powerful component PDF Metamorphosis .NET from SautinSoft SDK.

Practical applications and use cases:

  • Document workflow automation: integration into corporate systems for automatic document conversion before sending or archiving.
  • Online services: creating web applications that allow users to upload DOC files and download PDF versions.
  • Compatibility: converting non-standard or legacy formats to PDF that can be viewed on any device.
  • Information security: PDF files are easier to protect with passwords and are not editable.

Programmers and business developers constantly use DOC-to-PDF conversion within automated systems, particularly in the following areas:

  • Document management and corporate documentation management.
  • Report and schedule generation.
  • Educational platforms for publishing materials.
  • Ensuring legal liability when distributing documents.
The number of requests depends on the scale of the project, but any large system requires automated conversion, highlighting the urgency of the task.

Input file:

convert doc file to pdf input

Output result:

convert doc file to pdf output

Complete code

using System;
using System.IO;
using System.Collections;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
			// Before starting, we recommend to get a free key:
            // https://sautinsoft.com/start-for-free/
            
            // Apply the key here:
			// SautinSoft.PdfMetamorphosis.SetLicense("...");

            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();

            if (p != null)
            {
                string docPath = @"..\..\..\example.doc";
                string pdfPath = Path.ChangeExtension(docPath, ".pdf");

                // 2. Convert DOC file to PDF file
                if (p.DocToPdfConvertFile(docPath, pdfPath) == 0)
					System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfPath) { UseShellExecute = true });
                else
                {
                    System.Console.WriteLine("Conversion failed!");
                    Console.ReadLine();
                }
            }
        }
    }
}

Download

Imports System
Imports System.IO

Namespace Sample
    Friend Class Test

        Shared Sub Main(ByVal args() As String)
			' Before starting, we recommend to get a free key:
            ' https://sautinsoft.com/start-for-free/
            
            ' Apply the key here:
			' SautinSoft.PdfMetamorphosis.SetLicense("...");

            Dim p As New SautinSoft.PdfMetamorphosis()

            If p IsNot Nothing Then
                Dim docPath As String = "..\..\..\example.doc"
                Dim pdfPath As String = Path.ChangeExtension(docPath, ".pdf")

                ' 2. Convert DOC file to PDF file
                If p.DocToPdfConvertFile(docPath, pdfPath) = 0 Then
					System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(pdfPath) With {.UseShellExecute = True})
                Else
                    System.Console.WriteLine("Conversion failed!")
                    Console.ReadLine()
                End If
            End If
        End Sub
    End Class
End Namespace

Download


If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below:


Captcha

Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.