1. Home
  2. /
  3. GroupDocs.Merger.LowCode
  4. /
  5. Developer Guide
  6. /
  7. Loading Source Documents

Loading Source Documents

Every plugin takes its source document in the constructor, either as a file path or as a Stream.

Load a Document from a File Path

Pass the path of the source document. A relative path is resolved against the current directory. The following example splits out the first two pages of a PDF document loaded from a file.

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

// Load the source document from a file path
var splitter = new SplitPdf("business-plan.pdf", new[] { 1, 2 });

// Save one document per page
splitter.Save("output/page.pdf");
Imports System
Imports GroupDocs.Merger.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)

        ' Load the source document from a file path
        Dim splitter As New SplitPdf("business-plan.pdf", {1, 2})

        ' Save one document per page
        splitter.Save("output/page.pdf")
    End Sub
End Module
open System
open GroupDocs.Merger.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)

    // Load the source document from a file path
    let splitter = SplitPdf("business-plan.pdf", [| 1; 2 |])

    // Save one document per page
    splitter.Save("output/page.pdf")
    0

Expected output: Download pages.zip (2 documents)

Load a Document from a Stream

Pass a Stream that contains the source document. The plugin reads the stream from the beginning, regardless of its current position, so pass a stream whose content starts at offset 0. The stream stays open after Save; disposing of it remains your responsibility.

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

// Open the source document as a stream
using var stream = File.OpenRead("business-plan.pdf");

// Load the source document from the stream
var splitter = new SplitPdf(stream, new[] { 1, 2 });

// Save one document per page
splitter.Save("output/page.pdf");
Imports System
Imports System.IO
Imports GroupDocs.Merger.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)

        ' Open the source document as a stream
        Using stream = File.OpenRead("business-plan.pdf")
            ' Load the source document from the stream
            Dim splitter As New SplitPdf(stream, {1, 2})

            ' Save one document per page
            splitter.Save("output/page.pdf")
        End Using
    End Sub
End Module
open System
open System.IO
open GroupDocs.Merger.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)

    // Open the source document as a stream
    use stream = File.OpenRead("business-plan.pdf")

    // Load the source document from the stream
    let splitter = SplitPdf(stream, [| 1; 2 |])

    // Save one document per page
    splitter.Save("output/page.pdf")
    0

Expected output: Download pages.zip (2 documents)

Merge Documents with a Source Stream

The merge plugins (JoinPdf, JoinDocx, and JoinPptx) accept the source document as a path or a stream, but the documents to append are always file paths.

using System;
using System.IO;
using GroupDocs.Merger.Domain.Options;
using GroupDocs.Merger.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);

// Open the source document as a stream
using var stream = File.OpenRead("chapter-1.pdf");

// The documents to append are file paths
var merger = new JoinPdf(stream, new[] { "chapter-2.pdf", "chapter-3.pdf" }, new JoinOptions());

// Save the merged document
merger.Save("output/merged-chapters.pdf");
Imports System
Imports System.IO
Imports GroupDocs.Merger.Domain.Options
Imports GroupDocs.Merger.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)

        ' Open the source document as a stream
        Using stream = File.OpenRead("chapter-1.pdf")
            ' The documents to append are file paths
            Dim merger As New JoinPdf(stream, {"chapter-2.pdf", "chapter-3.pdf"}, New JoinOptions())

            ' Save the merged document
            merger.Save("output/merged-chapters.pdf")
        End Using
    End Sub
End Module
open System
open System.IO
open GroupDocs.Merger.Domain.Options
open GroupDocs.Merger.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)

    // Open the source document as a stream
    use stream = File.OpenRead("chapter-1.pdf")

    // The documents to append are file paths
    let merger = JoinPdf(stream, [ "chapter-2.pdf"; "chapter-3.pdf" ], JoinOptions())

    // Save the merged document
    merger.Save("output/merged-chapters.pdf")
    0

Expected output: Download merged-chapters.pdf (18 pages)

Input Format Check

Each plugin checks that the source document has the format named in the plugin: JoinPdf expects a PDF document, SplitDocx a DOCX document, and so on. A file is checked by its extension, and a stream by its content. When the format doesn’t match, the plugin throws FileTypeNotSupportedException before doing any work. See Handling Errors.