1. Home
  2. /
  3. GroupDocs.Conversion.LowCode
  4. /
  5. Developer Guide
  6. /
  7. Saving Converted Documents

Saving Converted Documents

GroupDocs.Conversion.LowCode provides two ways to save converted documents: to a file or a stream. This allows you to use any output storage location.

In this topic, we use the DocxToPdfConverter class as an example. The same approach applies to other converter classes.

Convert Methods

Each converter class provides two Convert methods inherited from the base Converter class:

  • public void Convert(string filePath, Action<TConvertOptions> convertOptionsAction = null)
  • public void Convert(Stream targetStream, Action<TConvertOptions> convertOptionsAction = null)

The first method saves the converted file to a specified file path, and the second one saves it to a provided writable stream.
Both methods accept an optional second parameter that enables you to configure the convert options.

Example 1: Save to File Path

The following example shows how to save a converted PDF file to the business-plan.pdf file by specifying the relative file path.
The file is going to be saved in the current directory.

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 DOCX file
var converter = new DocxToPdfConverter("business-plan.docx");

// Convert DOCX 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 DocxToPdfConverter("business-plan.docx")

        ' Convert DOCX 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 DocxToPdfConverter("business-plan.docx")

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

Sample input file: Download business-plan.docx

Example 2: Save to Stream

This example demonstrates how to save the converted file to a Stream.

using System;
using System.IO;
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);

// Load DOCX file as stream
using var stream = File.OpenRead("business-plan.docx");

// Create a converter from stream
var converter = new DocxToPdfConverter(stream);

// Instantiate output file stream
using var convertedFile = File.Create("business-plan.pdf");

// Convert DOCX to PDF
converter.Convert(convertedFile);
Imports System
Imports System.IO
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)

        ' Load DOCX file as stream
        Using inputStream As FileStream = File.OpenRead("business-plan.docx"),
              outputStream As FileStream = File.Create("business-plan.pdf")

            ' Create a converter from stream
            Dim converter As New DocxToPdfConverter(inputStream)

            ' Convert DOCX to PDF
            converter.Convert(outputStream)
        End Using
    End Sub
End Module
open System
open System.IO
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)

    // Use 'use' bindings for automatic disposal
    use inputStream = File.OpenRead("business-plan.docx")
    use outputStream = File.Create("business-plan.pdf")

    // Create a converter from stream
    let converter = new DocxToPdfConverter(inputStream)

    // Convert DOCX to PDF
    converter.Convert(outputStream)

    0 // return exit code

Sample input file: Download business-plan.docx

Example 3: Set Convert Options

You can use optional convert options to adjust the output according to your requirements. Each converter has its own corresponding convert options.

The following code example shows how to set convert options to convert first three DOCX doucument pages to PDF file.

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

// Provide password through load options
var converter = new DocxToPdfConverter("business-plan.docx");

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

        ' Provide password through load options
        Dim converter As New DocxToPdfConverter("business-plan.docx")

        ' 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 DocxToPdfConverter("business-plan.docx")

    // 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

Additional Resources