Spire.Doc for Java 12.1.0 removes the dependency on Spire.Pdf.jar

2024-01-04 09:30:17

We are pleased to announce the release of Spire.Doc for Java 12.1.0. This version removes the dependency on Spire.Pdf.jar and changes the method of license application to "com.spire.doc.license.LicenseProvider.setLicenseKey(key)". In addition, a number of new features have also been added, such as a new method for adding image watermarks. More details are listed below.

Here is a list of changes made in this release

Category ID Description
Adjustment - Removes the dependency on Spire.Pdf.jar.
Adjustment - Changes the method of license application to "com.spire.doc.license.LicenseProvider.setLicenseKey(key)".
New feature - Deprecates the following methods, classes and interfaces.
The "newEngine" parameter in the Document constructor no longer has any effect. The internal mechanism now defaults to using the new engine.
The HeaderType enum.
The GroupedShapeCollection class.
The ShapeObjectTextCollection class.
The MailMergeData interface.
The EnumInterface interface.
The public PictureWaterMark(InputStream inputeStream, boolean washout) constructor.
The public PictureWaterMark(String filename, boolean washout) constructor.
The downloadImage method in the Field class.
The IDocOleObject interface.
The PointsConverter class.
New feature - Deprecates the "getWidth()" and "setWidth()" methods in the TableCell class and replaces them with the "getCellWidth()" and "setCellWidth()" methods.
New feature - Changes the following namespaces.
com.spire.license.LicenseProvider -> com.spire.doc.License.LicenseProvider
New feature - Changes the inheritance relationship: changes "ShapeGroup implements ShapeObject" to "ShapeGroup implements ShapeBase".
New feature - Supports destroying data related to customized fonts when destroying the Document at the same time.
// Set custom fonts
Document.setCustomFontsFolders(string filePath);

// Dispose of custom fonts
Document.clearCustomFontsFolders();

// Clear system font cache that occupies memory in the cache
Document.clearSystemFontCache();

Example code:
Document doc = new Document();
doc.loadFromFile("inputFile.docx");
doc.setCustomFontsFolders(@"d:\Fonts");
doc.saveToFile("output.pdf", FileFormat.PDF);
doc.close();
doc.dispose();
New feature - Changes the following enumerated classes.
com.spire.doc.FileFormat.WPS -> com.spire.doc.FileFormat.Wps
com.spire.doc.FileFormat.WPT -> com.spire.doc.FileFormat.Wpt
ComparisonLevel -> TextDiffMode
New feature - Changes the following methods.
ComparisonLevel getLevel() -> getTextCompareLevel()
setLevel(ComparisonLevel value) -> setTextCompareLevel(TextDiffMode)
IsPasswordProtect() -> isEncrypted()
getFillEfects() -> getFillEffects()
New feature - Adds a new method to add image watermark.
File imageFile = new File("data/E-iceblue.png");
BufferedImage bufferedImage = ImageIO.read(imageFile);
// Create a new instance of the PictureWatermark class with the input BufferedImage, and set the scaling factor for the watermark image
PictureWatermark picture = new PictureWatermark(bufferedImage,false);
		// Or another way to create PictureWatermark
		// PictureWatermark picture = new PictureWatermark();
		// picture.setPicture(bufferedImage);
		// picture.isWashout(false);
		// Set the scaling factor for the watermark image
picture.setScaling(250);
// Set the watermark to be applied to the document
document.setWatermark(picture);
New feature - shape exposes the "getFill()" method to manipulate the fill of a shape; please use "getFill().setOn(false)" instead of "setFillColor(null)".
New feature SPIREDOC-10005 Supports adding charts.
// Create a new instance of Document
Document document = new Document();

// Add a section to the document
Section section = document.addSection();

// Add a paragraph to the section and append text to it
section.addParagraph().appendText("Line chart.");

// Add a new paragraph to the section
Paragraph newPara = section.addParagraph();

// Append a line chart shape to the paragraph with specified width and height
ShapeObject shape = newPara.appendChart(ChartType.Line, 500, 300);

// Get the chart object from the shape
Chart chart = shape.getChart();

// Get the title of the chart
ChartTitle title = chart.getTitle();

 // Set the text of the chart title
title.setText("My Chart");

 // Clear any existing series in the chart
ChartSeriesCollection seriesColl = chart.getSeries();
seriesColl.clear();

// Define categories (X-axis values)
String[] categories = { "C1", "C2", "C3", "C4", "C5", "C6" };

// Add two series to the chart with specified categories and Y-axis values
seriesColl.add("AW Series 1", categories, new double[] { 1, 2, 2.5, 4, 5, 6 });
seriesColl.add("AW Series 2", categories, new double[] { 2, 3, 3.5, 6, 6.5, 7 });

 // Save the document to a file in Docx format
document.saveToFile("AppendLineChart.docx", FileFormat.Docx_2016);

// Dispose of the document object when finished using it
document.dispose();
New feature SPIREDOC-7515 Provides the page model "Spire.Doc.Pages" to get the content of the page.
// Create a new instance of Document
Document doc = new Document();

// Load the document from the specified file
doc.loadFromFile(inputFile);

// Create a FixedLayoutDocument object using the loaded document
FixedLayoutDocument layoutDoc = new FixedLayoutDocument(doc);

// Create a StringBuilder to store the extracted text
StringBuilder stringBuilder = new StringBuilder();

// Get the first line on the first page and append it to the StringBuilder
FixedLayoutLine line = layoutDoc.getPages().get(0).getColumns().get(0).getLines().get(0);
stringBuilder.append("Line: " + line.getText() + "\r\n");

// Retrieve the original paragraph associated with the line and append its text to the StringBuilder
Paragraph para = line.getParagraph();
stringBuilder.append("Paragraph text: " + para.getText() + "\r\n");

// Retrieve all the text on the first page, including headers and footers, and append it to the StringBuilder
String pageText = layoutDoc.getPages().get(0).getText();
stringBuilder.append(pageText + "\r\n");

// Iterate through each page in the document and print the number of lines on each page
for (Object obj : layoutDoc.getPages()) {
	FixedLayoutPage page = (FixedLayoutPage) obj;
	LayoutCollection<LayoutElement> lines = page.getChildEntities(LayoutElementType.Line, true);
	stringBuilder.append("Page " + page.getPageIndex() + " has " + lines.getCount() + " lines." + "\r\n");
}

// Perform a reverse lookup of layout entities for the first paragraph and append them to the StringBuilder
stringBuilder.append("\r\n");
stringBuilder.append("The lines of the first paragraph:" + "\r\n");

for (Object object : layoutDoc.getLayoutEntitiesOfNode(((Section) doc.getFirstChild()).getBody().getParagraphs().get(0))) {
	FixedLayoutLine paragraphLine = (FixedLayoutLine) object;

	stringBuilder.append(paragraphLine.getText().trim() + "\r\n");
	stringBuilder.append(paragraphLine.getRectangle().toString() + "\r\n");
	stringBuilder.append("");
}

// Write the extracted text to a file
FileWriter fileWriter = new FileWriter(new File(outputFile));
fileWriter.write(stringBuilder.toString());
fileWriter.flush();
fileWriter.close();

// Dispose of the document resources
doc.close();
doc.dispose();
New feature - Supports adding SVG graphics.
// Create a new Document object
Document document = new Document();

// Add a new Section to the document
Section section = document.addSection();

// Add a new Paragraph to the section
Paragraph paragraph = section.addParagraph();

// Append the picture (SVG) to the paragraph
paragraph.appendPicture(inputSvg);

// Save the document to the specified output file
document.saveToFile(outputFile, FileFormat.Docx_2013);

// Close the document
document.dispose();
Click the link below to download Spire.Doc for Java 12.1.0: