Specify file type when loading a document
Leave feedback
On this page
GroupDocs.Signature supports specifying the file type when loading a document. When the file type is not specified, GroupDocs.Signature detects it from the document content, which takes some time. Starting with GroupDocs.Signature for Java 26.10, you can specify the file type directly in LoadOptions, and GroupDocs.Signature skips the detection and uses the specified type right away.
The following are the steps to specify the file type when loading a document.
Instantiate the LoadOptions object and set the file type, either with the LoadOptions(FileType) constructor or with the setFileType method;
Create an InputStream for the document file, for example new FileInputStream(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.
try(InputStreamstream=newFileInputStream(filePath)){// Specify the file type (PDF) while loading the document
LoadOptionsloadOptions=newLoadOptions(FileType.PDF);// Initialize the Signature instance with the file stream and load options
Signaturesignature=newSignature(stream,loadOptions);try{QrCodeSignOptionsoptions=newQrCodeSignOptions("JohnSmith");options.setEncodeType(QrCodeTypes.QR);options.setLeft(100);options.setTop(100);// sign document to file
signature.sign(outputFilePath,options);}finally{signature.dispose();}}System.out.println("\nSource document signed successfully.\nFile saved at "+outputFilePath);
The same load options work with a file path: new Signature(filePath, new LoadOptions(FileType.PDF)). FileType.Unknown, the default, detects the file type from the document content.
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 Java 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.
On this page
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.