Spire.Doc 9.7.3现已发布。 此次更新增强了转换Word到PDF及转换Html到Word 的功能,同时还修复了一些在加载、保存、打印Word文档时出现的问题。具体修复内容如下。
问题修复:
Spire.Doc for Java 4.7已发布。该版本增强了转换Word/RTF到PDF,以及转换HTML到Word的功能。此外,本次更新还修复了加载和保存Word文档等时出现的问题。详情请阅读以下内容。
问题修复:
本文介绍如何使用Spire.Presentation for Java设置形状中文字的对齐方式。
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import java.awt.*;
import java.awt.geom.Rectangle2D;
public class SetTextAlignment {
public static void main(String[] args) throws Exception {
//创建Presentation对象
Presentation presentation = new Presentation();
presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);
//添加形状
IAutoShape textShape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, new Rectangle2D.Float(50, 50, 400, 200));
textShape.getShapeStyle().getLineColor().setColor(Color.DARK_GRAY);
textShape.getFill().setFillType(FillFormatType.NONE);
//删除默认段落
textShape.getTextFrame().getParagraphs().clear();
//添加段落和文字
textShape.getTextFrame().getParagraphs().append(new ParagraphEx());
textShape.getTextFrame().getParagraphs().get(0).getTextRanges().append(new PortionEx("文字居右靠下"));
textShape.getTextFrame().getParagraphs().get(0).getTextRanges().get(0).setFontHeight(20f);
textShape.getTextFrame().getParagraphs().get(0).getTextRanges().get(0).setLatinFont(new TextFont("宋体"));
textShape.getTextFrame().getParagraphs().get(0).getTextRanges().get(0).getFill().setFillType(FillFormatType.SOLID);
textShape.getTextFrame().getParagraphs().get(0).getTextRanges().get(0).getFill().getSolidColor().setColor(Color.BLACK);
//设置文字水平靠右
textShape.getTextFrame().getParagraphs().get(0).setAlignment(TextAlignmentType.RIGHT);
//设置文字垂直靠下
textShape.getTextFrame().setAnchoringType(TextAnchorType.BOTTOM);
//保存文档
presentation.saveToFile("TextAlignment.pptx",FileFormat.PPTX_2013);
}
}

本文介绍如何使用Spire.Doc for Java来读取Word表格中的文本数据和图片。
用于测试的Word文档如下:

import com.spire.doc.*;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.DocPicture;
import com.spire.doc.interfaces.ITable;
import javax.imageio.ImageIO;
import java.awt.image.RenderedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class GetTable {
public static void main(String[] args)throws IOException {
//加载Word测试文档
Document doc = new Document();
doc.loadFromFile("https://cdn.e-iceblue.cn/inputfile.docx");
//获取第一节
Section section = doc.getSections().get(0);
//获取第一个表格
ITable table = section.getTables().get(0);
//创建txt文件(用于写入表格中提取的文本)
String output = "ReadTextFromTable.txt";
File textfile = new File(output);
if (textfile.exists())
{
textfile.delete();
}
textfile.createNewFile();
FileWriter fw = new FileWriter(textfile, true);
BufferedWriter bw = new BufferedWriter(fw);
//创建List
List images = new ArrayList();
//遍历表格中的行
for (int i = 0; i < table.getRows().getCount(); i++)
{
TableRow row = table.getRows().get(i);
//遍历每行中的单元格
for (int j = 0; j < row.getCells().getCount(); j++)
{
TableCell cell = row.getCells().get(j);
//遍历单元格中的段落
for (int k = 0; k < cell.getParagraphs().getCount(); k++)
{
Paragraph paragraph = cell.getParagraphs().get(k);
bw.write(paragraph.getText() + "\t");//获取文本内容
//遍历段落中的所有子对象
for (int x = 0; x < paragraph.getChildObjects().getCount(); x++)
{
Object object = paragraph.getChildObjects().get(x);
//判定对象是否为图片
if (object instanceof DocPicture)
{
//获取图片
DocPicture picture = (DocPicture) object;
images.add(picture.getImage());
}
}
}
}
bw.write("\r\n");//写入内容到txt文件
}
bw.flush();
bw.close();
fw.close();
//将图片以PNG文件格式保存
for (int z = 0; z < images.size(); z++)
{
File imagefile = new File(String.format("提取的表格图片-%d.png", z));
ImageIO.write((RenderedImage) images.get(z), "PNG", imagefile);
}
}
}
文本数据读取结果:

图片读取结果:

在创建PDF portfolio时,Spire.PDF for Java支持添加文件或文件夹到portfolio。本文将介绍如何使用Spire.PDF for Java创建PDF portfolio,并添加文件/文件夹。
创建PDF portfolio并添加文件
import com.spire.pdf.FileFormat;
import com.spire.pdf.PdfDocument;
public class CreatePortfolioWithFiles {
public static void main(String []args){
String[] files = new String[] { "sample.pdf", "sample.docx", "sample.xlsx","sample.pptx","image.jpg" };
//创建PdfDocument实例
PdfDocument pdf = new PdfDocument();
for (int i = 0; i < files.length; i++)
{
//创建PDF文件包并添加文件
pdf.getCollection().addFile(files[i]);
}
//保存文档
pdf.saveToFile("PortfolioWithFiles.pdf", FileFormat.PDF);
pdf.dispose();
}
}
结果文档:

创建PDF portfolio并添加文件夹
import com.spire.pdf.FileFormat;
import com.spire.pdf.PdfDocument;
import com.spire.pdf.collections.PdfFolder;
public class CreatePortfolioWithFolders {
public static void main(String []args){
String[] files = new String[] { "sample.pdf", "sample.docx", "sample.xlsx","sample.pptx","image.jpg" };
//创建PdfDocument实例
PdfDocument pdf = new PdfDocument();
for (int i = 0; i < files.length; i++)
{
//创建PDF文件包并添加文件夹
PdfFolder folder = pdf.getCollection().getFolders().createSubfolder("folder" + i);
folder.addFile(files[i]);
}
//保存文档
pdf.saveToFile("PortfolioWithFolders.pdf", FileFormat.PDF);
pdf.dispose();
}
}
结果文档:

本文将通过使用Spire.Barcode for Java展示如何在创建一维条码及二维条码时,设置条码数据不可见,即创建后的条码效果图中不展示条码包含的数据文本信息。只需通过设置settings.setShowText(false);即可。
1、创建一维条码时,设置文本数据不可见
import com.spire.barcode.BarCodeGenerator;
import com.spire.barcode.BarCodeType;
import com.spire.barcode.BarcodeSettings;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class CreateBarcode {
public static void main(String[] args) throws IOException {
BarcodeSettings settings = new BarcodeSettings();//创建BarcodeSettings实例
settings.setType(BarCodeType.Codabar);//指定条码类型
settings.setData("123456789");//设置条码数据
settings.setData2D("123456789");//设置条码显示数据
settings.setShowText(false);//设置条码数据不显示
/*settings.setShowText(true);//显示数据文本
settings.setShowTextOnBottom(true);//设置数据文本显示在条码底部*/
settings.setX(0.8f);//设置黑白条宽度
settings.setImageHeight(50);//设置生成的条码图片高度
settings.setImageWidth(70);//设置生成的条码图片宽度
settings.hasBorder(true);//设置边框可见
settings.setBorderColor(new Color(135,206,250));//设置条码边框颜色
settings.setBorderWidth(1);//设置条码边框宽度
settings.setBackColor(new Color(240,255,255));//设置条码背景色
BarCodeGenerator barCodeGenerator = new BarCodeGenerator(settings);//创建BarCodeGenerator实例
BufferedImage bufferedImage = barCodeGenerator.generateImage();//根据settings生成图像数据,保存至BufferedImage实例
ImageIO.write(bufferedImage, "png", new File("Codabar.png"));//保存条码为PNG图片
}
}
条码效果:

2、创建二维码时,设置文本数据不可见
import com.spire.barcode.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class CreateQR {
public static void main(String[] args) throws IOException {
BarcodeSettings settings = new BarcodeSettings();//创建BarcodeSettings实例
settings.setType(BarCodeType.QR_Code);//设置条码类型为QR二维码
settings.setData("Hello 123456789");//设置二维码数据
settings.setData2D("Hello 123456789");//设置二维码显示数据
settings.setShowText(false);//设置条码数据不显示
/*settings.setShowText(true);//显示数据文本
settings.setShowTextOnBottom(true);//设置数据文本显示在条码底部*/
settings.setQRCodeDataMode(QRCodeDataMode.Alpha_Number);//设置数据类型
settings.setImageWidth(50);//设置生成的二维码图片宽度
settings.setImageHeight(50);//设置生成的二维码图片高度
settings.setX(3.0f);//设置二维码模型宽度
settings.setQRCodeECL(QRCodeECL.H);//设置二维码纠错级别
settings.hasBorder(false);//设置二维码边框不可见
BarCodeGenerator barCodeGenerator = new BarCodeGenerator(settings);//创建BarCodeGenerator实例
BufferedImage bufferedImage = barCodeGenerator.generateImage();//根据settings生成图像数据,保存至BufferedImage实例
ImageIO.write(bufferedImage, "png", new File("QRCode.png"));//保存二维码图片为PNG格式
}
}
二维码效果:

Spire.XLS for Java 4.6.5已发布。本次更新增强了转换Excel到PDF的功能,同时还修复了加载和拷贝Excel文档时出现的问题。详情请阅读以下内容。
问题修复:
Spire.Presentation 6.6.6已发布。该版本修复了ole对象相关的问题,同时还修复了加载PPT文件等时出现的问题。详情请阅读以下内容。
问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Presentation-NET.html
本文介绍如何使用Spire.Presentation for .NET设置形状中文字的对齐方式。
using Spire.Presentation;
using System.Drawing;
using Spire.Presentation.Drawing;
namespace TextAlignment
{
class Program
{
static void Main(string[] args)
{
//创建Presentation对象
Presentation presentation = new Presentation();
presentation.SlideSize.Type = SlideSizeType.Screen16x9;
//添加形状
IAutoShape textShape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 400, 200));
textShape.ShapeStyle.LineColor.Color = Color.DarkGray;
textShape.Fill.FillType = FillFormatType.None;
//删除默认段落
textShape.TextFrame.Paragraphs.Clear();
//添加段落和文字
textShape.TextFrame.Paragraphs.Append(new TextParagraph());
textShape.TextFrame.Paragraphs[0].TextRanges.Append(new TextRange("文字对齐方式"));
textShape.TextFrame.Paragraphs[0].TextRanges[0].FontHeight = 20f;
textShape.TextFrame.Paragraphs[0].TextRanges[0].LatinFont = new TextFont("黑体");
textShape.TextFrame.Paragraphs[0].TextRanges[0].Fill.FillType = FillFormatType.Solid;
textShape.TextFrame.Paragraphs[0].TextRanges[0].Fill.SolidColor.Color = Color.Black;
//设置文字水平靠右
textShape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Right;
//设置文字垂直靠下
textShape.TextFrame.AnchoringType = TextAnchorType.Bottom;
//保存文档
presentation.SaveToFile("AlignText.pptx", FileFormat.Pptx2013);
}
}
}
Imports Spire.Presentation
Imports System.Drawing
Imports Spire.Presentation.Drawing
Namespace TextAlignment
Class Program
Shared Sub Main(ByVal args() As String)
'创建Presentation对象
Dim presentation As Presentation = New Presentation()
presentation.SlideSize.Type = SlideSizeType.Screen16x9
'添加形状
Dim textShape As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Rectangle,New RectangleF(50,50,400,200))
textShape.ShapeStyle.LineColor.Color = Color.DarkGray
textShape.Fill.FillType = FillFormatType.None
'删除默认段落
textShape.TextFrame.Paragraphs.Clear()
'添加段落和文字
textShape.TextFrame.Paragraphs.Append(New TextParagraph())
textShape.TextFrame.Paragraphs(0).TextRanges.Append(New TextRange("文字对齐方式"))
textShape.TextFrame.Paragraphs(0).TextRanges(0).FontHeight = 20f
textShape.TextFrame.Paragraphs(0).TextRanges(0).LatinFont = New TextFont("黑体")
textShape.TextFrame.Paragraphs(0).TextRanges(0).Fill.FillType = FillFormatType.Solid
textShape.TextFrame.Paragraphs(0).TextRanges(0).Fill.SolidColor.Color = Color.Black
'设置文字水平靠右
textShape.TextFrame.Paragraphs(0).Alignment = TextAlignmentType.Right
'设置文字垂直靠下
textShape.TextFrame.AnchoringType = TextAnchorType.Bottom
'保存文档
presentation.SaveToFile("AlignText.pptx", FileFormat.Pptx2013)
End Sub
End Class
End Namespace

Spire.PDF 7.6.15已发布。该版本增强了转换PDF到图片/PDFA1A/PDFA1B的功能,修复了打印和合并PDF时出现的问题。详情请阅读以下内容。
问题修复: