GroupDocs.Parser for Java 24.3 Release Notes
Full List of Issues Covering all Changes in this Release
Key | Summary | Category |
---|---|---|
PARSERNET-1928 | Implement the ability to load files by URL | Feature |
PARSERNET-2210 | Implement the ability to serialize/deserialize templates | Feature |
Public API and Backward Incompatible Changes
Implement the ability to load files by URL
Description
This feature provides the ability to load documents from URL instead of a file on disk or a stream.
Public API changes
Parser public class was updated with changes as follows:
- Added Parser(java.net.URL url) constructor
- Added Parser(java.net.URL url, LoadOptions loadOptions) constructor
- Added Parser(java.net.URL url, ParserSettings parserSettings) constructor
- Added Parser(java.net.URL url, LoadOptions loadOptions, ParserSettings parserSettings) constructor
LoadOptions public class was updated with changes as follows:
- Added LoadOptions(Duration timeout) constructor
- Added LoadOptions(FileFormat fileFormat, String password, Charset charset, Charset defaultAnsiCharset, Duration timeout) constructor
- Added Timeout property
Usage
The following example shows how to load the document from the url:
// Create an instance of Parser class with the url
try (Parser parser = new Parser(url)) {
// Extract a text into the reader
try (TextReader reader = parser.getText()) {
// Print a text from the document
// If text extraction isn't supported, a reader is null
System.out.println(reader == null ? "Text extraction isn't supported" : reader.readToEnd());
}
}
Implement the ability to serialize/deserialize templates
Description
This feature allows to save Template object to XML file and restore Template object from XML file.
Public API changes
Template public class was updated with changes as follows:
- Added load(String filePath) static method
- Added load(java.io.InputStream stream) static method
- Added save(String filePath) method
- Added save(java.io.OutputStream stream) method
TemplateLinkedPositionEdges public class was updated with changes as follows:
- Added parse(String s) static method
Point public class was updated with changes as follows:
- Added parse(String s) static method
Size public class was updated with changes as follows:
- Added parse(String s) static method
- Added isEmpty property
Usage
The following example shows how to save the template to the file:
// Create detector parameters for "Details" table
TemplateTableParameters detailsTableParameters = new TemplateTableParameters(new Rectangle(new Point(35, 320), new Size(530, 55)), null);
// Create detector parameters for "Summary" table
TemplateTableParameters summaryTableParameters = new TemplateTableParameters(new Rectangle(new Point(330, 385), new Size(220, 65)), null);
// Create a collection of template items
TemplateItem[] templateItems = new TemplateItem[]
{
new TemplateField(new TemplateFixedPosition(new Rectangle(new Point(35, 135), new Size(100, 10))), "FromCompany"),
new TemplateField(new TemplateFixedPosition(new Rectangle(new Point(35, 150), new Size(100, 35))), "FromAddress"),
new TemplateField(new TemplateFixedPosition(new Rectangle(new Point(35, 190), new Size(150, 2))), "FromEmail"),
new TemplateField(new TemplateFixedPosition(new Rectangle(new Point(35, 250), new Size(100, 2))), "ToCompany"),
new TemplateField(new TemplateFixedPosition(new Rectangle(new Point(35, 260), new Size(100, 15))), "ToAddress"),
new TemplateField(new TemplateFixedPosition(new Rectangle(new Point(35, 290), new Size(150, 2))), "ToEmail"),
new TemplateField(new TemplateRegexPosition("Invoice Number"), "InvoiceNumber"),
new TemplateField(new TemplateLinkedPosition(
"InvoiceNumber",
new Size(200, 15),
new TemplateLinkedPositionEdges(false, false, true, false)),
"InvoiceNumberValue"),
new TemplateField(new TemplateRegexPosition("Order Number"), "InvoiceOrder"),
new TemplateField(new TemplateLinkedPosition(
"InvoiceOrder",
new Size(200, 15),
new TemplateLinkedPositionEdges(false, false, true, false)),
"InvoiceOrderValue"),
new TemplateField(new TemplateRegexPosition("Invoice Date"), "InvoiceDate"),
new TemplateField(new TemplateLinkedPosition(
"InvoiceDate",
new Size(200, 15),
new TemplateLinkedPositionEdges(false, false, true, false)),
"InvoiceDateValue"),
new TemplateField(new TemplateRegexPosition("Due Date"), "DueDate"),
new TemplateField(new TemplateLinkedPosition(
"DueDate",
new Size(200, 15),
new TemplateLinkedPositionEdges(false, false, true, false)),
"DueDateValue"),
new TemplateField(new TemplateRegexPosition("Total Due"), "TotalDue"),
new TemplateField(new TemplateLinkedPosition(
"TotalDue",
new Size(200, 15),
new TemplateLinkedPositionEdges(false, false, true, false)),
"TotalDueValue"),
new TemplateTable(detailsTableParameters, "details", null),
new TemplateTable(summaryTableParameters, "summary", null)
};
// Create a document template
Template template = new Template(java.util.Arrays.asList(templateItems));
// Save the document template to the file
template.save("template.xml");
The following example shows how to load the template from the file:
// Load a document template from the file
Template template = Template.load("template.xml");