Specify file type when loading a document
Leave feedback
On this page
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.stringfilePath=Constants.SAMPLE_PDF;stringfileName=Path.GetFileName(filePath);stringoutputFilePath=Path.Combine(Constants.OutputPath,"LoadWithFileType",fileName);using(Streamstream=File.OpenRead(filePath)){// Specify the file type (PDF) while loading the documentLoadOptionsloadOptions=newLoadOptions(FileType.PDF);// Initialize the Signature instance with the file stream and load optionsusing(Signaturesignature=newSignature(stream,loadOptions)){QrCodeSignOptionsoptions=newQrCodeSignOptions("JohnSmith"){EncodeType=QrCodeTypes.QR,Left=100,Top=100};// sign document to filesignature.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:
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.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.