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

Using PDF to DOCX Converter

This topic shows how to use the PdfToDocxConverter with examples that demonstrate common use cases for converting PDF files to DOCX format.

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 PDF document to DOCX. The source PDF 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 PDF file
var converter = new PdfToDocxConverter("business-plan.pdf");

// Convert PDF to DOCX
converter.Convert("business-plan.docx");
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 PdfToDocxConverter("business-plan.pdf")

        ' Convert PDF to DOCX
        converter.Convert("business-plan.docx")
    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 PdfToDocxConverter("business-plan.pdf")

    // Convert PDF to DOCX
    converter.Convert("business-plan.docx")
    0

Sample input file: Download business-plan.pdf

PDF Load Options

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

Convert Protected PDF to DOCX

The following example shows how to convert protected PDF file and save it to unprotected DOCX 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 PdfToDocxConverter("protected.pdf", options =>
{
    options.Password = "12345";
});

// Convert PDF to DOCX
converter.Convert("unprotected.docx");
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 PdfToDocxConverter("protected.pdf", Sub(options)
            options.Password = "12345"
        End Sub)

        ' Convert PDF to DOCX
        converter.Convert("unprotected.docx")
    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 PdfToDocxConverter("protected.pdf", fun options ->
        options.Password <- "12345"
    )

    // Convert PDF to DOCX
    converter.Convert("unprotected.docx")
    0

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

Expected output: Download unprotected.docx

Flatten Fields in Form-Fillable PDF

The following example shows how to convert a form‑fillable PDF into static content by flattening form fields.

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);

// Flatten form fields through load options
var converter = new PdfToDocxConverter("form-fields.pdf", options =>
{
    options.FlattenAllFields = true;
});

// Convert PDF to DOCX
converter.Convert("flattened.docx");
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)

        ' Flatten form fields through load options
        Dim converter As New PdfToDocxConverter("form-fields.pdf", Sub(options)
            options.FlattenAllFields = True
        End Sub)

        ' Convert PDF to DOCX
        converter.Convert("flattened.docx")
    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)

    // Flatten form fields through load options
    let converter = new PdfToDocxConverter("form-fields.pdf", fun options ->
        options.FlattenAllFields <- true
    )
    
    // Convert PDF to DOCX
    converter.Convert("flattened.docx")
    0

Sample input: Download form-fields.pdf (Fillable PDF)

Expected output: Download flattened.docx

Convert PDF with Annotations to DOCX without Annotations

By default, annotations are added to the output DOCX file, see this with-annotations.pdf (text HOME BASED PROFESSIONAL SERVICES is highlighted) as an example of PDF file with annotations.

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

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 annotations using HidePdfAnnotations
var converter = new PdfToDocxConverter("with-annotations.pdf", options =>
{
    options.HidePdfAnnotations = true;
});

// Convert PDF to DOCX
converter.Convert("no-annotations.docx");
Imports System
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)

        ' Hide annotations using HidePdfAnnotations
        Dim converter As New PdfToDocxConverter("with-annotations.pdf", Sub(options)
                                                                             options.HidePdfAnnotations = True
                                                                         End Sub)

        ' Convert PDF to DOCX
        converter.Convert("no-annotations.docx")
    End Sub
End Module
open System
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)

    // Hide annotations using HidePdfAnnotations
    let converter = 
        new PdfToDocxConverter("with-annotations.pdf", fun options ->
            options.HidePdfAnnotations <- true
        )

    // Convert PDF to DOCX
    converter.Convert("no-annotations.docx")

    0 // return an integer exit code

Sample input: Download with-annotations.pdf (Contains highlight annotations)

Expected output: Download no-annotations.docx (Annotations hidden)

Word Processing Convert Options

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

Convert PDF to Password-Protected DOCX

You can protect the output DOCX with a password by setting the Password property in WordProcessingConvertOptions 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 PdfToDocxConverter("business-plan.pdf");

// Convert to password-protected DOCX
converter.Convert("protected.docx", 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 PdfToDocxConverter("business-plan.pdf")

        ' Convert to password-protected DOCX
        converter.Convert("protected.docx", 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 PdfToDocxConverter("business-plan.pdf")

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

    0

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

Convert PDF to DOCX with A4 Page Size

You can specify the page size for the output DOCX file using the PageSize property in WordProcessingConvertOptions class.

The following example shows how to convert a PDF file to DOCX with A4 page size:

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

// 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 PdfToDocxConverter("business-plan.pdf");

// Convert to DOCX with A4 page size
converter.Convert("a4-size.docx", convertOptions =>
{
    convertOptions.PageSize = PageSize.A4;
});
Imports GroupDocs.Conversion.LowCode
Imports GroupDocs.Conversion.Options.Convert

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 PdfToDocxConverter("business-plan.pdf")

        ' Convert to DOCX with A4 page size
        converter.Convert("a4-size.docx", Sub(convertOptions)
            convertOptions.PageSize = PageSize.A4
        End Sub)
    End Sub
End Module
open System
open GroupDocs.Conversion.LowCode
open GroupDocs.Conversion.Options.Convert

[<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 PdfToDocxConverter("business-plan.pdf")

    // Convert to DOCX with A4 page size
    converter.Convert("a4-size.docx", fun convertOptions ->
        convertOptions.PageSize <- PageSize.A4
    )

    0 // return exit code

Expected output: Download a4-size.docx (A4 page size)