Specify file type when loading a document

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Signature MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-signature -- dnx GroupDocs.Signature.Mcp --yes
Folders, licensing and more →

GroupDocs.Signature supports specifing the file type when loading a document. When loading a document via a file path or FileStream, GroupDocs.Signature checks the file extension to determine the file type, which can take some time. with the new feature, you can specify the file type directly in LoadOptions, and GroupDocs.Signature will skip the detection process and use the specified type right away.

The following are the steps to work with password protected documents.

  • Instantiate the LoadOptions object and set the file type;
  • Create a Stream for the document file using File.OpenRead(filePath);
  • Create Signature object by passing the document stream and load options to its constructor;
  • Call the Sign method to sign the document and save the signed version to the output path.

The following code sample shows how to specify file type when loading a document.

// The path to the documents directory.
string filePath = Constants.SAMPLE_PDF;
string fileName = Path.GetFileName(filePath);
string outputFilePath = Path.Combine(Constants.OutputPath, "LoadWithFileType", fileName);

using (Stream stream = File.OpenRead(filePath))
{
    // Specify the file type (PDF) while loading the document
    LoadOptions loadOptions = new LoadOptions(FileType.PDF);

    // Initialize the Signature instance with the file stream and load options
    using (Signature signature = new Signature(stream, loadOptions))
    {
        QrCodeSignOptions options = new QrCodeSignOptions("JohnSmith")
        {
            EncodeType = QrCodeTypes.QR,
            Left = 100,
            Top = 100
        };
        // sign document to file
        signature.Sign(outputFilePath, options);
    }
}
Console.WriteLine("\nSource document signed successfully.\nFile saved at " + outputFilePath);

More resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online Apps 

Along with the full-featured .NET library, we provide simple but powerful free online apps.
To sign PDF, Word, Excel, PowerPoint, and other documents you can use the online apps from the GroupDocs.Signature App Product Family.