Specify file type when loading a document

GroupDocs.Signature supports specifing the file type when loading a documents. 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.