We're pleased to announce the release of Spire.Office for Java 9.3.1. This version contains some fantastic features, such as Spire.PDF for Java adds the PdfTextReplacer class to replace PDF text and supports adding InkAnnotation to PDF; Spire.XLS for Java supports AI features; Spire.Presentation for Java supports adding math equation in paragraphs and getting the display color of a shape. In addition, many known issues are fixed in this version. More details are listed below.
Click the link to download Spire.Office for Java 9.3.1:
Here is a list of changes made in this release
Spire.Doc for Java
Category |
ID |
Description |
Improvement |
SPIREDOC-10325 |
Optimizes the file size of the resulting document of Word to OFD conversion. |
New feature |
- |
Adds the setImageLink() in MergeImageFieldEventArgs event to support adding hyperlinks to the mail merge images.
Document document = new Document();
document.loadFromFile(inputFile);
String[] fieldNames = new String[]{"ImageFile"};
String[] fieldValues = new String[]{inputFile_img};
document.getMailMerge().MergeImageField = new MergeImageFieldEventHandler() {
@Override
public void invoke(Object sender, MergeImageFieldEventArgs args) {
mailMerge_MergeImageField(sender, args);
}
};
document.getMailMerge().execute(fieldNames, fieldValues);
document.saveToFile(outputFile, FileFormat.Docx);
private static void mailMerge_MergeImageField(Object sender, MergeImageFieldEventArgs field) {
String filePath = field.getImageFileName();
if (filePath != null && !"".equals(filePath)) {
try {
field.setImage(filePath);
field.setImageLink("https://www.baidu.com/");
} catch (Exception e) {
e.printStackTrace();
}
}
|
New feature |
SPIREDOC-9369 |
Adds the getFieldOptions() method to support setting field properties when updating a field.
document.getFieldOptions().setCultureSource(FieldCultureSource.CurrentThread);
|
New feature |
- |
Adds the hasDigitalSignature() method to support determining whether a document has a digital signature.
Document.hasDigitalSignature("filepath");
|
New feature |
SPIREDOC-9455 |
Adds the integrateFontTableTo method to support copying Fonttable data from source document to target document.
sourceDoc.integrateFontTableTo(Document destDoc);
|
New feature |
SPIREDOC-9869 |
Adds the HtmlUrlLoadEvent event to support the control of loading URLs in the file when loading HTML files.
public static void main(String[] args) {
Document document = new Document();
document.HtmlUrlLoadEvent = new MyDownloadEvent();
document.loadFromFile(inputFile, FileFormat.Html, XHTMLValidationType.None);
document.saveToFile(outputFile, FileFormat.PDF);
}
static class MyDownloadEvent extends HtmlUrlLoadHandler {
@Override
public void invoke(Object o, HtmlUrlLoadEventArgs htmlUrlLoadEventArgs) {
try {
byte[] bytes = downloadBytesFromURL(htmlUrlLoadEventArgs.getUrl());
htmlUrlLoadEventArgs.setDataBytes(bytes);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static byte[] downloadBytesFromURL(String urlString) throws Exception {
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(5000);
connection.setReadTimeout(5000);
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream inputStream = connection.getInputStream();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.close();
return outputStream.toByteArray();
} else {
throw new Exception("Failed to download content. Response code: " + responseCode);
}
}
|
New feature |
- |
Adds the setCustomFonts(InputStream[] fontStreamList) method to support setting custom fonts by stream.
document.setCustomFonts(InputStream[] fontStreamList);
|
New feature |
- |
Replaces the clearCustomFontsFolders() method with the new clearCustomFonts() method.
document.clearCustomFonts();
|
New feature |
- |
Replaces the setGlobalCustomFontsFolders(InputStream[] fontStreamList) method with the new setGlobalCustomFonts(InputStream[] fontStreamList) method.
Document.setGlobalCustomFonts(InputStream[] fontStreamList);
|
New feature |
- |
Replaces the clearGlobalCustomFontsFolders() method with the new clearGlobalCustomFonts() method.
Document.clearGlobalCustomFonts();
|
Spire.XLS for Java
Category |
ID |
Description |
New feature |
- |
Supports AI features, which enables document calculation, range merging, image generation, file upload, questioning and translation with the help of AI. |
Bug |
SPIREXLS-5096 |
Optimize the issue that the memory consumption is high when parsing Excel documents. |
Bug |
SPIREXLS-5136 |
Fix the issue that it reported an error when opening an Excel document after loading and saving it directly. |
Bug |
SPIREXLS-5138 |
Fix the issue that shapes were lost after copying the worksheet table. |
Spire.PDF for Java
Category |
ID |
Description |
New feature |
SPIREPDF-4354 |
Adds the PdfTextReplacer class to replace PDF text.
PdfDocument doc = new PdfDocument();
doc.loadFromFile("Input.pdf");
PdfPageBase page = doc.getPages().get(0);
PdfTextReplacer textReplacer = new PdfTextReplacer(page);
textReplacer.replaceAllText("old", "NEW");
doc.saveToFile("output.pdf");
doc.dispose();
|
New feature |
SPIREPDF-6591 |
Supports adding InkAnnotation to PDF.
PdfDocument doc = new PdfDocument();
PdfPageBase pdfPage = doc.getPages().add();
List<int[]> inkList = new ArrayList<>();
int[] intPoints = new int[]
{
100,800,
200,800,
200,700
};
inkList.add(intPoints);
PdfInkAnnotation ia = new PdfInkAnnotation(inkList);
ia.setColor(new PdfRGBColor(Color.RED));
ia.getBorder().setWidth(12);
ia.setText("e-iceblue");
((PdfNewPage) pdfPage).getAnnotations().add(ia);
doc.saveToFile("inkannotation.pdf");
|
Bug |
SPIREPDF-6606 |
Optimizes the PDF signature time to match the system local time. |
Bug |
SPIREPDF-6548 |
Fixes the issue that the PDF type obtained by using pdfDocument.getConformance() was incorrect. |
Bug |
SPIREPDF-6554 |
Fixes the issue that it threw "StackOverflow" exception when using setRowSpan() twice. |
Bug |
SPIREPDF-6581 |
Fixes the issue that content was lost after converting OFD to PDF. |
Spire.Presentation for Java
Category |
ID |
Description |
New feature |
SPIREPPT-2210 |
Supports adding math equation in paragraphs.
Presentation ppt = new Presentation();
String latexMathCode="x^{2}+\\sqrt{x^{2}+1=2}";
IAutoShape shape=ppt.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE,new Rectangle2D.Float(30,100,400,200));
shape.getTextFrame().getParagraphs().clear();
ParagraphEx p=new ParagraphEx();
shape.getTextFrame().getParagraphs().append(p);
PortionEx portionEx=new PortionEx("Test");
p.getTextRanges().append(portionEx);
p.appendFromLatexMathCode(latexMathCode);
PortionEx portionEx2=new PortionEx("Hello");
p.getTextRanges().append(portionEx2);
ppt.saveToFile(outputFile, FileFormat.AUTO);
|
New feature |
SPIREPPT-2422 |
Supports getting the display color of a shape.
Presentation ppt = new Presentation();
ppt.loadFromFile("input.pptx");
IAutoShape shape = (IAutoShape)ppt.getSlides().get(0).getShapes().get(0);
System.out.println(shape.getDisplayFill().getFillType().getName());
System.out.println(shape.getDisplayFill().getSolidColor().getColor());
|
Bug |
SPIREPPT-2456 |
Fixes the issue that the application threw "DocumentEditException" when merging documents. |