Spire.Doc for Java

ニュース&リリース

2024-01-05

Spire.Doc for Java 12.1.0 では Spire.Pdf.jar への依存を削除しました

Spire.Doc for Java 12.1.0のリリースを発表できることを嬉しく思います。このバージョンでは、Spire.Pdf.jarへの依存を削除し、ライセンスの適用方法を「com.spire.doc.license.LicenseProvider.setLicenseKey(key)」に変更しました。 さらに、画像透かしを追加する新しいメソッドなど、多くの新機能が追加されました。詳細は以下の内容を読んでください。

このリリースで行われた変更のリストは次のとおりです
カテゴリー ID 説明
Adjustment - Spire.Pdf.jar への依存関係を削除しました。
Adjustment - ライセンスの適用方法を 「com.spire.doc.license.LicenseProvider.setLicenseKey(key) 」に変更しました。
New feature - 次のメソッド、クラス、およびインターフェイスは非推奨になりました。
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.
PointsConverter クラス
New feature - TableCell クラスの getWidth() メソッドと setWidth() メソッドは非推奨となり、getCellWidth() メソッドと setCellWidth() メソッドに置き換えられました。
New feature - 以下の名前空間を変更します。
com.spire.license.LicenseProvider -> com.spire.doc.License.LicenseProvider
New feature - 継承関係を変更します。「ShapeGroup implements ShapeObject」を「ShapeGroup implements ShapeBase」に変更します。
New feature - Documentの破棄時に、カスタムフォントに関連するデータも同時に破棄できるようになりました。
// カスタムフォントを設定する
Document.setCustomFontsFolders(string filePath);

// カスタムフォントを破棄する
Document.clearCustomFontsFolders();

// キャッシュ内のメモリを占有しているシステム フォント キャッシュをクリアする
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 - 次の列挙型クラスを変更します。
com.spire.doc.FileFormat.WPS -> com.spire.doc.FileFormat.Wps
com.spire.doc.FileFormat.WPT -> com.spire.doc.FileFormat.Wpt
ComparisonLevel -> TextDiffMode
New feature - 以下のメソッドを変更します。
ComparisonLevel getLevel() -> getTextCompareLevel()
setLevel(ComparisonLevel value) -> setTextCompareLevel(TextDiffMode)
IsPasswordProtect() -> isEncrypted()
getFillEfects() -> getFillEffects()
New feature - 画像の透かしを追加するメソッドを追加しました。
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 は、グラフィックスの塗りつぶしを操作するための getFill() メソッドを公開します。setFillColor(null) メソッドの代わりに getFill().setOn(false) を使用します。
New feature SPIREDOC-10005 グラフの追加のサポートが追加されました。
// Document の新しいインスタンスを作成します
Document document = new Document();

// ドキュメントにセクションを追加します
Section section = document.addSection();

// セクションに段落を追加し、そこにテキストを追加します
section.addParagraph().appendText("Line chart.");

// セクションに新しい段落を追加します
Paragraph newPara = section.addParagraph();

// 指定された幅と高さの折れ線グラフの形状を段落に追加します
ShapeObject shape = newPara.appendChart(ChartType.Line, 500, 300);

// 図形からチャートオブジェクトを取得します
Chart chart = shape.getChart();

// チャートのタイトルを取得します
ChartTitle title = chart.getTitle();

 // グラフのタイトルのテキストを設定します
title.setText("My Chart");

 // チャート内の既存の系列をクリアします
ChartSeriesCollection seriesColl = chart.getSeries();
seriesColl.clear();

// カテゴリ (X 軸の値) を定義します
String[] categories = { "C1", "C2", "C3", "C4", "C5", "C6" };

// 指定されたカテゴリと Y 軸値を持つ 2 つの系列をグラフに追加します
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 });

 // ドキュメントを Docx 形式でファイルに保存します
document.saveToFile("AppendLineChart.docx", FileFormat.Docx_2016);

// ドキュメントオブジェクトを使い終わったら破棄します
document.dispose();
New feature SPIREDOC-7515 ページのコンテンツを取得するために、ページ モデル Spire.Doc.Pages が提供されています。
// Document の新しいインスタンスを作成します
Document doc = new Document();

// 指定されたファイルからドキュメントを読み込みます
doc.loadFromFile(inputFile);

// ロードされたドキュメントを使用してFixedLayoutDocumentオブジェクトを作成します
FixedLayoutDocument layoutDoc = new FixedLayoutDocument(doc);

// 抽出されたテキストを保存する StringBuilder を作成します
StringBuilder stringBuilder = new StringBuilder();

// 最初のページの最初の行を取得し、StringBuilder に追加します
FixedLayoutLine line = layoutDoc.getPages().get(0).getColumns().get(0).getLines().get(0);
stringBuilder.append("Line: " + line.getText() + "\r\n");

// その行に関連付けられた元の段落を取得し、そのテキストを StringBuilder に追加します
Paragraph para = line.getParagraph();
stringBuilder.append("Paragraph text: " + para.getText() + "\r\n");

// ヘッダーとフッターを含む最初のページのすべてのテキストを取得し、StringBuilder に追加します
String pageText = layoutDoc.getPages().get(0).getText();
stringBuilder.append(pageText + "\r\n");

// ドキュメントの各ページを反復処理し、各ページの行数を出力します
for (Object obj : layoutDoc.getPages()) {
	FixedLayoutPage page = (FixedLayoutPage) obj;
	LayoutCollection lines = page.getChildEntities(LayoutElementType.Line, true);
	stringBuilder.append("Page " + page.getPageIndex() + " has " + lines.getCount() + " lines." + "\r\n");
}

// 最初の段落のレイアウト エンティティの逆引き参照を実行し、それらを 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("");
}

// 抽出したテキストをファイルに書き込みます
FileWriter fileWriter = new FileWriter(new File(outputFile));
fileWriter.write(stringBuilder.toString());
fileWriter.flush();
fileWriter.close();

// ドキュメントリソースを破棄します
doc.close();
doc.dispose();
New feature - SVG グラフィックの追加のサポートが追加されました。
//新しい Document オブジェクトを作成します
Document document = new Document();

//新しいセクションをドキュメントに追加します
Section section = document.addSection();

//新しい段落をセクションに追加します
Paragraph paragraph = section.addParagraph();

//画像 (SVG) を段落に追加します
paragraph.appendPicture(inputSvg);

//ドキュメントを指定された出力ファイルに保存します
document.saveToFile(outputFile, FileFormat.Docx_2013);

//ドキュメントを閉じます
document.dispose();
ここで Spire.Doc for Java 12.1.0をダウンロードする