1. Home
  2. /
  3. GroupDocs.Conversion.LowCode
  4. /
  5. Developer Guide
  6. /
  7. Using DOC to PDF Converter

Using DOC to PDF Converter

This topic shows how to use the DocToPdfConverter with examples that demonstrate common use cases for converting DOC files to PDF.

Prerequisites

Refer to the Developer Guide to learn how to set up your environment and run code examples in this section.

You can also check two related topics on Loading Source Documents and Saving Converted Documents to learn how to specify input and output documents.

Basic Example

The following example shows the most common use case for converting DOC document to PDF. The source DOC file is loaded from a current folder. The converted file is saved to the same folder.

using System;
using GroupDocs.Conversion.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply the license
License.Set(publicKey, privateKey);

// Create a converter for the DOC file
var converter = new DocToPdfConverter("business-plan.doc");

// Convert DOC as PDF
converter.Convert("business-plan.pdf");
Imports System
Imports GroupDocs.Conversion.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply the license
        License.Set(publicKey, privateKey)

        ' Create a converter from file path
        Dim converter As New DocToPdfConverter("business-plan.doc")

        ' Convert DOC to PDF
        converter.Convert("business-plan.pdf")
    End Sub
End Module
open System
open GroupDocs.Conversion.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply the license
    License.Set(publicKey, privateKey)

    // Create a converter from file path
    let converter = new DocToPdfConverter("business-plan.doc")

    // Convert DOC to PDF
    converter.Convert("business-plan.pdf")
    0

Sample input file: Download business-plan.doc

DOC Load Options

This section covers only the main scenarios. You also refer to the API references for the WordProcessingLoadOptions for a complete list of options that you can specify.

Convert Protected DOC to PDF

The following example shows how to convert protected DOC file and save it to unprotected PDF file.

In case you do not specify password for protected document PasswordRequiredException is going to be thrown.

using System;
using GroupDocs.Conversion.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply license
License.Set(publicKey, privateKey);

// Provide password through load options
var converter = new DocToPdfConverter("protected.doc", options =>
{
    options.Password = "12345";
});

// Convert DOC to PDF
converter.Convert("not-protected.pdf");
Imports GroupDocs.Conversion.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply license
        License.Set(publicKey, privateKey)

        ' Provide password through load options
        Dim converter As New DocToPdfConverter("protected.doc", Sub(options)
            options.Password = "12345"
        End Sub)

        ' Convert DOC to PDF
        converter.Convert("not-protected.pdf")
    End Sub
End Module
open System
open GroupDocs.Conversion.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")
    
    // Apply license
    License.Set(publicKey, privateKey)

    // Provide password through load options
    let converter = new DocToPdfConverter("protected.doc", fun options ->
        options.Password <- "12345"
    )
    
    // Convert DOC to PDF
    converter.Convert("not-protected.pdf")
    0

Sample input: Download protected.doc (Password: 12345)

Convert DOC with Tracked Changes to PDF

By default, tracked changes are converted and displayed in the output PDF document. See this tracked-changes.pdf that includes the list of changes.

The following example shows how to convert a DOC file that contains tracked changes and save a clean PDF file without those revisions.

using System;
using GroupDocs.Conversion.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply license
License.Set(publicKey, privateKey);

// Hide tracked changes through load options
var converter = new DocToPdfConverter("tracked-changes.doc", options =>
{
    options.HideWordTrackedChanges = true;
});

// Convert DOC to PDF
converter.Convert("clean.pdf");
Imports GroupDocs.Conversion.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply license
        License.Set(publicKey, privateKey)

        ' Hide tracked changes through load options
        Dim converter As New DocToPdfConverter("tracked-changes.doc", Sub(options)
            options.HideWordTrackedChanges = True
        End Sub)

        ' Convert DOC to PDF
        converter.Convert("clean.pdf")
    End Sub
End Module
open System
open GroupDocs.Conversion.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply license
    License.Set(publicKey, privateKey)

    // Hide tracked changes through load options
    let converter = new DocToPdfConverter("tracked-changes.doc", fun options ->
        options.HideWordTrackedChanges <- true
    )

    // Convert DOC to PDF
    converter.Convert("clean.pdf")
    0

Sample input: Download tracked-changes.doc (Contains revisions)

Expected output: Download clean.pdf (Tracked changes hidden)

Convert DOC with Comments to PDF without Comments

By default, comments are added to the output PDF file, see this with-comments.pdf as an example of PDF file with comments.

The following example shows how to convert a DOC file that contains comments and save a PDF file without comments.

using System;
using GroupDocs.Conversion.LowCode;
using GroupDocs.Conversion.Options.Load;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply license
License.Set(publicKey, privateKey);

// Hide comments using CommentDisplayMode
var converter = new DocToPdfConverter("with-comments.doc", options =>
{
    options.CommentDisplayMode = WordProcessingCommentDisplay.Hidden;
});

// Convert DOC to PDF
converter.Convert("no-comments.pdf");
Imports GroupDocs.Conversion.LowCode
Imports GroupDocs.Conversion.Options.Load

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply license
        License.Set(publicKey, privateKey)

        ' Hide comments using CommentDisplayMode
        Dim converter As New DocToPdfConverter("with-comments.doc", Sub(options)
            options.CommentDisplayMode = WordProcessingCommentDisplay.Hidden
        End Sub)

        ' Convert DOC to PDF
        converter.Convert("no-comments.pdf")
    End Sub
End Module
open System
open GroupDocs.Conversion.LowCode
open GroupDocs.Conversion.Options.Load

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply license
    License.Set(publicKey, privateKey)

    // Hide comments using CommentDisplayMode
    let converter = new DocToPdfConverter("with-comments.doc", fun options ->
        options.CommentDisplayMode <- WordProcessingCommentDisplay.Hidden
    )

    // Convert DOC to PDF
    converter.Convert("no-comments.pdf")
    0

Sample input: Download with-comments.doc (Contains comments)

Expected output: Download no-comments.pdf (Comments hidden)

PDF Convert Options

The examples in this section shows how you can adjust the output using PdfConvertOptions.

Convert Specific DOC Pages to PDF

To convert only a portion of the document instead of all pages. You can specify which pages to include in the output PDF using the Pages property of PdfConvertOptions class.

As an alternative you can use PageNumber to specify the page number to start conversion from and PagesCount to set number of pages to convert starting from PageNumber.

The following example shows how to convert the first three pages of a DOC file to PDF:

using System;
using System.Collections.Generic;
using GroupDocs.Conversion.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply license
License.Set(publicKey, privateKey);

// Create the converter
var converter = new DocToPdfConverter("business-plan.doc");

// Save first three pages to PDF
converter.Convert("pages-1-2-3.pdf", (convertOptions) => {
    convertOptions.Pages = new List<int> { 1, 2, 3 };
});
Imports System
Imports System.Collections.Generic
Imports GroupDocs.Conversion.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey As String = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey As String = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply license
        License.Set(publicKey, privateKey)

        ' Create the converter
        Dim converter As New DocToPdfConverter("business-plan.doc")

        ' Save first three pages to PDF
        converter.Convert("pages-1-2-3.pdf", Sub(convertOptions)
                                                convertOptions.Pages = New List(Of Integer) From {1, 2, 3}
                                            End Sub)
    End Sub
End Module
open System
open System.Collections.Generic
open GroupDocs.Conversion.LowCode

[<EntryPoint>]
let main argv =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply license
    License.Set(publicKey, privateKey)

    // Create the converter
    let converter = new DocToPdfConverter("business-plan.doc")

    // Save first three pages to PDF
    converter.Convert("pages-1-2-3.pdf", fun convertOptions ->
        convertOptions.Pages <- List<int>([1; 2; 3])
    )

    0 // return exit code

Expected output: Download pages-1-2-3.pdf

Convert DOC to Password-Protected PDF

You can protect the output PDF with a password by setting the Password property in PdfConvertOptions class.

using System;
using GroupDocs.Conversion.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply license
License.Set(publicKey, privateKey);

// Create the converter
var converter = new DocToPdfConverter("business-plan.doc");

// Convert to password-protected PDF
converter.Convert("protected.pdf", convertOptions =>
{
    convertOptions.Password = "12345";
});
Imports GroupDocs.Conversion.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply license
        License.Set(publicKey, privateKey)

        ' Create the converter
        Dim converter As New DocToPdfConverter("business-plan.doc")

        ' Convert to password-protected PDF
        converter.Convert("protected.pdf", Sub(convertOptions)
            convertOptions.Password = "12345"
        End Sub)
    End Sub
End Module
open System
open GroupDocs.Conversion.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply license
    License.Set(publicKey, privateKey)

    // Create the converter
    let converter = new DocToPdfConverter("business-plan.doc")

    // Convert to password-protected PDF
    converter.Convert("protected.pdf", fun convertOptions ->
        convertOptions.Password <- "12345"
    )

    0

Expected output: Download protected.pdf (Password: 12345)

Convert DOC to PDF/A Format

You can convert DOC to PDF/A format by setting the PdfFormat property in PdfOptions class.

using System;
using GroupDocs.Conversion.Options.Convert;
using GroupDocs.Conversion.LowCode;

// Load license keys
var publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");
var privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");

// Apply license
License.Set(publicKey, privateKey);

// Create the converter
var converter = new DocToPdfConverter("business-plan.doc");

// Convert to PDF/A format
converter.Convert("archived.pdf", convertOptions =>
{
    convertOptions.PdfOptions.PdfFormat = PdfFormats.PdfA_1A;
});
Imports GroupDocs.Conversion.Options.Convert
Imports GroupDocs.Conversion.LowCode

Module Program
    Sub Main()
        ' Load license keys
        Dim publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
        Dim privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

        ' Apply license
        License.Set(publicKey, privateKey)

        ' Create the converter
        Dim converter As New DocToPdfConverter("business-plan.doc")

        ' Convert to PDF/A format
        converter.Convert("archived.pdf", Sub(convertOptions)
            convertOptions.PdfOptions.PdfFormat = PdfFormats.PdfA_1A
        End Sub)
    End Sub
End Module
open System
open GroupDocs.Conversion.Options.Convert
open GroupDocs.Conversion.LowCode

[<EntryPoint>]
let main _ =
    // Load license keys
    let publicKey = Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")
    let privateKey = Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")

    // Apply license
    License.Set(publicKey, privateKey)

    // Create the converter
    let converter = new DocToPdfConverter("business-plan.doc")

    // Convert to PDF/A format
    converter.Convert("archived.pdf", fun convertOptions ->
        convertOptions.PdfOptions.PdfFormat <- PdfFormats.PdfA_1A
    )

    0

Expected output: Download archived.pdf (PDF/A format)