public class Document extends Object implements Closeable
Represents a document for comparison process.
The Document class provides methods to load, generate preview images, and manipulate documents during the comparison process.
Example usage:
try (Comparer comparer = new Comparer(sourceFile)) {
try (IDocumentInfo info = comparer.getSource().getDocumentInfo()) {
System.out.println("File type: " + info.getFileType());
System.out.println("Number of pages: " + info.getPageCount());
System.out.println("Document size: " + info.getSize());
}
}
Comparer,
IDocumentInfo| Constructor and Description |
|---|
Document(InputStream stream)
Initializes new instance of Document class with the specified document stream.
|
Document(InputStream inputStream,
LoadOptions loadOptions)
Initializes new instance of Document class with the specified document stream and load options.
|
Document(InputStream stream,
String password)
Initializes new instance of Document class with the specified document stream and a password.
|
Document(Path filePath)
Initializes new instance of Document class with the specified document path.
|
Document(Path filePath,
LoadOptions loadOptions)
Initializes new instance of Document class with the specified document path and load options.
|
Document(Path filePath,
String password)
Initializes new instance of Document class with the specified document path and a password.
|
Document(String filePath)
Initializes new instance of Document class with the specified document path.
|
Document(String filePathOrTextContent,
boolean isLoadText)
Initializes new instance of Document class with the specified document path or text content and a flag that indicates what was passed.
|
Document(String filePath,
LoadOptions loadOptions)
Initializes new instance of Document class with the specified document path and load options.
|
Document(String filePath,
String password)
Initializes new instance of Document class with the specified document path and a password.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
InputStream |
createStream()
Creates new stream with document content.
|
void |
generatePreview(PreviewOptions previewOptions)
Generates document previews based on the provided
PreviewOptions. |
List<ChangeInfo> |
getChanges()
Gets a list of
ChangeInfo objects representing the changes detected during the comparison process. |
IDocumentInfo |
getDocumentInfo()
Gets information about the document, including document type, page count, page sizes, and more.
|
FileType |
getFileType()
Gets the type of the document.
|
String |
getName()
Gets the name of the document.
|
String |
getPassword()
Gets the password of the document
|
long |
getStreamLength()
Gets the size of the document
|
void |
setChanges(List<ChangeInfo> value)
Sets a list of
ChangeInfo objects representing the changes detected during the comparison process. |
void |
setFileType(FileType fileType)
Sets the type of the document.
|
void |
setName(String value)
Sets the name of the document.
|
public Document(InputStream stream)
Initializes new instance of Document class with the specified document stream.
stream - Document streampublic Document(InputStream inputStream, LoadOptions loadOptions)
Initializes new instance of Document class with the specified document stream and load options.
inputStream - Document streamloadOptions - Load optionspublic Document(InputStream stream, String password)
Initializes new instance of Document class with the specified document stream and a password.
stream - Document streampassword - Document passwordpublic Document(Path filePath)
Initializes new instance of Document class with the specified document path.
filePath - Document pathpublic Document(Path filePath, LoadOptions loadOptions)
Initializes new instance of Document class with the specified document path and load options.
filePath - Document pathloadOptions - Load optionspublic Document(Path filePath, String password)
Initializes new instance of Document class with the specified document path and a password.
filePath - Document pathpassword - Document passwordpublic Document(String filePath)
Initializes new instance of Document class with the specified document path.
filePath - Document pathpublic Document(String filePathOrTextContent, boolean isLoadText)
filePathOrTextContent - the file pathisLoadText - the is load textpublic Document(String filePath, LoadOptions loadOptions)
Initializes new instance of Document class with the specified document path and load options.
filePath - Document pathloadOptions - Load optionspublic void close()
close in interface Closeableclose in interface AutoCloseablepublic InputStream createStream()
Creates new stream with document content.
public final void generatePreview(PreviewOptions previewOptions)
PreviewOptions.
This method generates previews of the document pages according to the specified options, such as preview format, page numbers, and output stream provider. The generated previews can be saved or further processed as needed.
Example usage:
try (Comparer comparer = new Comparer(sourceFile)) {
PreviewOptions previewOptions = new PreviewOptions(
pageNumber -> Files.newOutputStream(Paths.get("preview-image-page-" + pageNumber + ".png"))
);
previewOptions.setPreviewFormat(PreviewFormats.PNG);
previewOptions.setPageNumbers(new int[]{1, 2});
comparer.getSource().generatePreview(previewOptions);
}
previewOptions - The preview options specifying the format, page numbers and so onComparer,
PreviewOptionspublic final List<ChangeInfo> getChanges()
Gets a list of ChangeInfo objects representing the changes detected during the comparison process.
Use this method to get detailed information about the changes between the source document and the target document(s).
Each ChangeInfo object contains information such as the type of change, the affected area,
and the content before and after the change.
ChangeInfo objects representing the changes detected during the comparison processChangeInfopublic final IDocumentInfo getDocumentInfo()
Gets information about the document, including document type, page count, page sizes, and more.
IDocumentInfopublic FileType getFileType()
Gets the type of the document.
public final String getName()
Gets the name of the document.
public String getPassword()
Gets the password of the document
public long getStreamLength()
Gets the size of the document
public final void setChanges(List<ChangeInfo> value)
Sets a list of ChangeInfo objects representing the changes detected during the comparison process.
Use this method to get detailed information about the changes between the source document and the target document(s).
Each ChangeInfo object contains information such as the type of change, the affected area,
and the content before and after the change.
value - a list of ChangeInfo objects representing the changes detected during the comparison processChangeInfopublic void setFileType(FileType fileType)
Sets the type of the document.
fileType - the type of the documentpublic final void setName(String value)
Sets the name of the document.
value - the name of the documentCopyright © 2024. All rights reserved.