Spire.XLS for Java 4.9.0已发布。该版本支持隐藏透视表行的所有项,增强了转换Excel到PDF/HTML的功能。此外本次更新还修复了加载Excel文档时出现的问题。详情请阅读以下内容。
新功能:
PivotField pivotField = (PivotField) pivotTable.getPivotFields().get("Product");
pivotField.hideAllItem(true);
问题修复:
Spire.Doc for Java 4.9.0已发布。该版本增强了转换Word到PDF,HTML到Word以及转换文本到图片的功能。此外本次更新还修复了加载和比较Word文档等时出现的问题。详情请阅读以下内容。
问题修复:
获取 PDF 中文本或图片的坐标对于精确引用、操作文档中的特定元素特别有帮助。通过提取坐标,您可以准确识别文本或图片在每一页上的位置,从而满足数据提取、文本识别或突出显示特定区域等任务的需求。本文将介绍如何使用 Spire.PDF for .NET 在 C# 中获取 PDF 文档中文本或图片的坐标信息。
首先,您需要添加 Spire.PDF for .NET 包中包含的 DLL 文件作为.NET项目中的引用。DLL 文件可以从此链接下载或通过 NuGet 安装。
PM> Install-Package Spire.PDFSpire.PDF 提供的 PdfTextFinder.Find() 方法能帮助我们在可搜索 PDF 文档中查找所有指定的文本。要获取文本的坐标信息可以使用 PdfTextFragment.Positions 属性。
以下是使用 Spire.PDF for .NET 获取 PDF 中指定文本的 (X, Y) 坐标的步骤:
using Spire.Pdf;
using Spire.Pdf.Texts;
using System.Drawing;
namespace GetCoordinatesOfText
{
class Program
{
static void Main(string[] args)
{
//创建PdfDocument对象
PdfDocument pdf = new PdfDocument();
//加载PDF文件
pdf.LoadFromFile("示例.pdf");
//遍历所有页面
foreach (PdfPageBase page in pdf.Pages)
{
//创建PdfTextFinder对象
PdfTextFinder finder = new PdfTextFinder(page);
//设置查找选项
PdfTextFindOptions options = new PdfTextFindOptions();
options.Parameter = TextFindParameter.IgnoreCase;
finder.Options = options;
//查找页面中所有指定文本
List<PdfTextFragment> fragments = finder.Find("互联网");
//遍历所有查找的文本
foreach (PdfTextFragment fragment in fragments)
{
//获取文本的坐标信息
PointF found = fragment.Positions[0];
Console.WriteLine(found);
}
}
}
}
}
Spire.PDF 提供的 PdfImageHelper.GetImagesInfo() 方法能帮助我们获取特定页面上的所有图像信息。要获取图片的坐标信息可以使用 PdfImageInfo.Bounds 属性。
以下是使用 Spire.PDF for .NET 获取 PDF 文档中图片坐标的步骤:
using Spire.Pdf;
using Spire.Pdf.Utilities;
namespace GetCoordinatesOfImage
{
class Program
{
static void Main(string[] args)
{
//创建PdfDocument对象
PdfDocument pdf = new PdfDocument();
//加载PDF文件
pdf.LoadFromFile("示例.pdf");
//获取指定页面
PdfPageBase page = pdf.Pages[0];
//创建PdfImageHelper对象
PdfImageHelper helper = new PdfImageHelper();
//获取页面中的图片信息
PdfImageInfo[] images = helper.GetImagesInfo(page);
//获取指定图片的 X、Y 坐标
float xPos = images[0].Bounds.X;
float yPos = images[0].Bounds.Y;
Console.WriteLine("图片位于({0},{1})", xPos, yPos);
}
}
}
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.PDF 7.9.2已发布。该版本增强了转换PDF到图片的功能,同时还修复了加载和合并PDF文档等时出现的问题。详情请阅读以下内容。
问题修复:
Spire.PDF for Java 4.8.7已发布。本次更新支持转换PDF到OFD的功能,增强了转换PDF到Word/HTML/PDFA1A/PDFA1B的功能。此外,该版本还修复了替换字体时出现的等问题。详情请阅读以下内容。
新功能:
pdf.saveToFile(output, FileFormat.OFD)
问题修复:
IXLSRange接口下提供了getStyle() 方法和setStyle() 方法,用来获取或设置特定单元格(区域)的样式。要将格式从一个单元格复制到另一个单元格,请先获取样式,然后将其应用到另一个单元格。
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;
public class CopyCellFormatting {
public static void main(String[] args) {
//创建Workbook对象
Workbook workbook = new Workbook();
//加载示例文档
workbook.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.xlsx");
//获取第一个工作表
Worksheet sheet = workbook.getWorksheets().get(0);
//获取被使用的行数
int rowCount = sheet.getRows().length;
//遍历行
for (int i = 1; i < rowCount + 1; i++)
{
//获取指定单元格的样式并应用到另一个单元格
sheet.getRange().get(String.format("C%d",i)).setStyle(sheet.getRange().get(String.format("A%d",i)).getStyle());
}
//保存文档
workbook.saveToFile("output/CopyFormatting.xlsx", ExcelVersion.Version2016);
}
}

经常有客户反馈,在Windows系统中,使用Spire组件转换文档时,结果文档正常,但是在Linux系统中,结果文档会出现乱码、方框或程序抛出字体缺失异常如:Cannot found font[SansSerif] installed on the system。
这个问题是由于Linux服务器缺少字体所导致。Spire组件转换文档时需要从系统中寻找对应的字体绘制字形,如果系统中没有安装原文档中所使用的字体,会先从系统已安装的字体中匹配能支持这个字形的字体,如果无法匹配出相应的字体,结果文档就会出现乱码或方框,或者程序会抛出字体缺失异常。若您遇到了这类问题,请先确认原文档中使用了哪些字体,然后将这些字体或Windows中的所有字体安装到您的Linux系统后,问题会得到解决。
以下是如何查看和安装字体的详细指令。
1、开启 root 权限
输入指令: su root 不行时,需要先输入指令: sudo passwd root
根据步骤输入密码,然后再重新输入指令: su root
2、将字体文件先放到某一个文件夹下
然后进入文件夹输入指令: cp simsun.ttc /usr/share/fonts/ ,依次输入下面的指令:
mkfontscale //字体扩展
mkfontdir //新增字体目录
fc-cache-fv //刷新缓存
3、查看安装的字体文件
查看系统中的字体:
指令:fc-list
查看系统中的中文字体:
指令:fc-list:lang=zh
如果按照上述步骤安装字体后,问题依然存在,请及时联系我们:该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。 或致电 028-81705109。
本文介绍如何使用Spire.XLS for Java来压缩Excel中的图片。
import com.spire.xls.*;
public class CompressImgs {
public static void main(String[] args) {
Workbook wb = new Workbook();
wb.loadFromFile("test.xlsx");//加载Excel测试文档
//遍历工作表
for(int s = 0; s < wb.getWorksheets().getCount(); s++)
{
Worksheet sheet = wb.getWorksheets().get(s);
//遍历工作表中的图片
for(int p = 0; p < sheet.getPictures().getCount(); p++)
{
ExcelPicture pic = sheet.getPictures().get(p);
pic.compress(40);//压缩图片
}
}
//保存文档
wb.saveToFile("CompressImgs.xlsx",FileFormat.Version2013);
wb.dispose();
}
}
压缩前后,可查看文档大小效果对比:

本文介绍如何使用Spire.Presentation for Java更改PowerPoint中文本的字体样式,包括字体名称,字体大小,字体颜色,粗体,斜体等。
import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import java.awt.*;
public class ChangeFontStyles {
public static void main(String[] args) throws Exception {
//创建Presentation对象
Presentation presentation = new Presentation();
//加载示例文档
presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pptx");
//获取文本形状
IAutoShape shape = (IAutoShape) presentation.getSlides().get(0).getShapes().get(0);
//获取第一个段落并更改字体颜色
ParagraphEx paragraph = shape.getTextFrame().getParagraphs().get(0);
for (int i = 0; i < paragraph.getTextRanges().getCount(); i++) {
PortionEx textRange = paragraph.getTextRanges().get(i);
textRange.getFormat().getFill().setFillType(FillFormatType.SOLID);
textRange.getFormat().getFill().getSolidColor().setColor(Color.blue);
}
//获取第三个段落并将文字加粗,设置斜体和下划线
paragraph = shape.getTextFrame().getParagraphs().get(2);
for (int i = 0; i < paragraph.getTextRanges().getCount(); i++) {
PortionEx textRange = paragraph.getTextRanges().get(i);
textRange.getFormat().isBold(TriState.TRUE);
textRange.getFormat().isItalic(TriState.TRUE);
textRange.getFormat().setTextUnderlineType(TextUnderlineType.DASHED);
}
//获取第五个段落并更改字体名称及大小
paragraph = shape.getTextFrame().getParagraphs().get(4);
for (int i = 0; i < paragraph.getTextRanges().getCount(); i++) {
PortionEx textRange = paragraph.getTextRanges().get(i);
textRange.getFormat().setEastAsianFont(new TextFont("黑体"));
textRange.getFormat().setFontHeight(22f);
}
//保存文档
presentation.saveToFile("output/ChangeFontStyles.pptx", FileFormat.PPTX_2013);
}
}

Spire.PDFViewer 6.8.6已发布。本次更新带了些新功能,比如ASP.NET控件支持旋转页面,支持控件支持查找文本并高亮。同时,该版本还修复了PDF文档显示相关等问题。详情请阅读以下内容。
新功能:
input type=button id=PdfDocumentViewer1_btnRotate onfocus=this.blur() onclick=pdfdocumentviewer1.Rotate(pdfdocumentviewer1.RotateAngle + 270); value=rotate_270
input type=text id=PdfDocumentViewer1_txtFindText onkeydown=if(event.keyCode==13){pdfdocumentviewer1.SearchText(this.value,true);return false;} value=
protected void Page_Load(http://cdn.e-iceblue.cn/object sender, EventArgs e)
{
if (!IsPostBack)
{
this.PdfDocumentViewer1.FindTextHighLightColor = System.Drawing.Color.FromArgb(125, 255, 0, 0);
this.PdfDocumentViewer1.LoadFromFile(input.pdf);
}
}
问题修复: