Spire.PDF for Java 9.2.5 已发布。本次更新优化了文档压缩功能,同时增强了 PDF 到 Excel 的转换。此外,该版本还修复了一些已知问题。详情请阅读以下内容。
新功能:
PdfCompressor compressor = new PdfCompressor(inputFile);
compressor.getOptions().getImageCompressionOptions().setResizeImages(true);
compressor.getOptions().getImageCompressionOptions().setImageQuality(ImageQuality.Low);
compressor.compressToFile(outputFile);问题修复:
Word 文档是使用 Microsoft Word 或其他文字处理程序创建的文件。它们被世界上几乎所有类型的企业所使用。各种专业文档,如商业合同、论文、手册、信件、简历和报告,都以 Word 文档的形式创建和保存。在本文中,您将学习如何使用 Spire.Doc for C++ 以编程方式在 C++ 中创建或编辑 Word 文档。
有两种方法可以将 Spire.Doc for C++ 集成到您的应用程序中。一种方法是通过 NuGet 安装它,另一种方法是从我们的网站下载包并将库复制到您的程序中。通过 NuGet 安装更简单,更推荐使用。您可以通过访问以下链接找到更多详细信息。
如何将 Spire.Doc for C++ 集成到 C++ 程序中
使用 Spire.Doc for C++,您可以创建一个包含一个或多个部分的 Word 文档,并向其中添加各种元素,例如段落、表格、图像、列表、超链接、水印、页眉、页脚、内容控件和注释。
以下步骤向您展示了如何创建一个包含一个节和三个段落的简易 Word 文档:
#include "Spire.Doc.o.h"
using namespace Spire::Doc;
int main()
{
//初始化 Document 类的一个实例
intrusive_ptr<Document> doc = new Document();
//在文档中添加一个节
intrusive_ptr<Section> section = doc->AddSection();
//设置页边距
section->GetPageSetup()->GetMargins()->SetAll(72);
//向该节添加标题段落
intrusive_ptr<Paragraph> titlePara = section->AddParagraph();
//向段落添加文本
titlePara->AppendText(L"Spire.Doc for C++ 简介");
//向该节添加正文段落
intrusive_ptr<Paragraph> bodyPara1 = section->AddParagraph();
//向段落添加文本
bodyPara1->AppendText(L"Spire.Doc for C++ 是一个专业的Word 库,专门为开发人员设计,可以在C++ 应用程序中创建、读取、写入、转换、合并、拆分和比较Word 文档,具有快速和高质量的性能。");
//向该节添加正文段落
intrusive_ptr<Paragraph> bodyPara2 = section->AddParagraph();
//向段落添加文本
bodyPara2->AppendText(L"通过使用 Spire.Doc for C++,用户可以将 Word Doc/Docx 转换为 XML、RTF、EMF、TXT、XPS、EPUB、HTML、SVG、ODT,反之亦然。Spire.Doc for C++ 还支持将 Word Doc/Docx 转换为 PDF 以及将 HTML 转换为图像。");
//创建样式并将其应用于标题段落
intrusive_ptr<ParagraphStyle> style1 = new ParagraphStyle(doc);
style1->SetName(L"titleStyle");
style1->GetCharacterFormat()->SetBold(true);
style1->GetCharacterFormat()->SetTextColor(Color::GetBlue());
style1->GetCharacterFormat()->SetFontName(L"宋体");
style1->GetCharacterFormat()->SetFontSize(16);
doc->GetStyles()->Add(style1);
titlePara->ApplyStyle(L"titleStyle");
//创建样式并将其应用于正文段落
intrusive_ptr<ParagraphStyle> style2 = new ParagraphStyle(doc);
style2->SetName(L"paraStyle");
style2->GetCharacterFormat()->SetFontName(L"宋体");
style2->GetCharacterFormat()->SetFontSize(12);
doc->GetStyles()->Add(style2);
bodyPara1->ApplyStyle(L"paraStyle");
bodyPara2->ApplyStyle(L"paraStyle");
//设置标题和正文段落的水平对齐方式
titlePara->GetFormat()->SetHorizontalAlignment(HorizontalAlignment::Center);
bodyPara1->GetFormat()->SetHorizontalAlignment(HorizontalAlignment::Justify);
bodyPara2->GetFormat()->SetHorizontalAlignment(HorizontalAlignment::Justify);
//在标题和正文段落后设置间距
titlePara->GetFormat()->SetAfterSpacing(10);
bodyPara1->GetFormat()->SetAfterSpacing(10);
//保存结果文件
doc->SaveToFile(L"创建Word文档.docx", FileFormat::Docx2013);
doc->Dispose();
}
除了从头开始创建 Word 文档外,Spire.Doc for C++ 还可以让您能够编辑现有的 Word 文档。 例如,您可以修改文档中的现有元素或向文档添加新元素。
以下步骤向您展示了如何修改 Word 文档中特定段落的文本:
#include "Spire.Doc.o.h"
using namespace Spire::Doc;
int main()
{
//初始化Document类的实例
intrusive_ptr<Document> doc = new Document();
//加载Word文档
doc->LoadFromFile(L"创建Word文档.docx");
//访问文档中的第一节
intrusive_ptr<Section> section = doc->GetSections()->GetItemInSectionCollection(0);
//访问第一节中的第二段
intrusive_ptr<Paragraph> para = section->GetParagraphs()->GetItemInParagraphCollection(1);
//修改段落文本
para->SetText(L"本段已更新");
//保存结果文档
doc->SaveToFile(L"编辑Word文档.docx", FileFormat::Docx2013);
doc->Dispose();
}
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Spreadsheet 7.2.0 已发布。本次更新支持缩放功能。详情请阅读以下内容。
新功能:
https://www.e-iceblue.cn/Downloads/Spire-Spreadsheet-NET.html
带标签的 PDF 是包含与 HTML 代码非常相似的标签的 PDF 文档。标签提供了一种逻辑结构,用于控制如何通过辅助技术呈现PDF内容。每个标签标识了关联的内容元素,例如标题级别 1 <H1>、段落 <P>、图像 <Figure> 或表格 <Table>。在本文中,您将学习如何使用 Spire.PDF for Java 在 Java 中创建带标签的 PDF 文档。
首先,您需要在 Java 程序中添加 Spire.Pdf.jar 文件作为依赖项。JAR 文件可以从此链接下载。如果您使用 Maven,则可以将以下代码添加到项目的 pom.xml 文件中,从而在应用程序中导入 JAR 文件。
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.pdf</artifactId>
<version>12.9.0</version>
</dependency>
</dependencies>
要在带标签的 PDF 文档中添加结构元素,我们必须首先创建 PdfTaggedContent 类的对象。 然后使用 PdfTaggedContent.getStructureTreeRoot().appendChildElement() 方法向根添加一个元素。以下是使用 Spire.PDF for Java 向带标签的 PDF 添加“标题”元素的详细步骤。
以下代码提供了一个示例,展示了如何在 Java 标记的 PDF 文档中创建各种元素,包括文档、标题、段落、图像和表格。
import com.spire.pdf.*;
import com.spire.pdf.graphics.*;
import com.spire.pdf.interchange.taggedpdf.PdfStandardStructTypes;
import com.spire.pdf.interchange.taggedpdf.PdfStructureElement;
import com.spire.pdf.interchange.taggedpdf.PdfTaggedContent;
import com.spire.pdf.tables.PdfTable;
import java.awt.*;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
public class CreateTaggedPdf {
public static void main(String[] args) throws Exception {
//创建一个 PdfDocument 对象
PdfDocument doc = new PdfDocument();
//添加页面
PdfPageBase page = doc.getPages().add(PdfPageSize.A4, new PdfMargins(20));
//设置 Tab 键顺序
page.setTabOrder(TabOrder.Structure);
//创建 PdfTaggedContent 类的对象
PdfTaggedContent taggedContent = new PdfTaggedContent(doc);
//设置文档的语言和标题
taggedContent.setLanguage("zh-CN");
taggedContent.setTitle("创建标签PDF文件");
//设置PDF/UA1标识
taggedContent.setPdfUA1Identification();
//创建字体和画笔
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("宋体",Font.PLAIN,13), true);
PdfSolidBrush brush = new PdfSolidBrush(new PdfRGBColor(Color.BLACK));
//添加“文档”元素
PdfStructureElement document = taggedContent.getStructureTreeRoot().appendChildElement(PdfStandardStructTypes.Document);
//添加“标题”元素
PdfStructureElement heading1 = document.appendChildElement(PdfStandardStructTypes.HeadingLevel1);
heading1.beginMarkedContent(page);
String headingText = "什么是标签PDF文件?";
page.getCanvas().drawString(headingText, font, brush, new Point2D.Float(5, 30));
heading1.endMarkedContent(page);
//添加“段落”元素
PdfStructureElement paragraph = document.appendChildElement(PdfStandardStructTypes.Paragraph);
paragraph.beginMarkedContent(page);
String paragraphText = "带标签的 PDF 似乎不是一个改变生活的术语。但对一些人来说,它是。" +
"对于盲人或视力不佳且使用辅助技术(例如屏幕阅读器和连接的盲文显示器)来访问信息的人来说," +
"未加标签的 PDF 意味着他们错过了文档中包含的信息," +
"因为辅助技术无法“阅读”未加标签的 PDF。" +
"数字可访问性为曾经对视障人士关闭的信息开辟了许多途径,但 PDF 经常被排除在外。";
Rectangle2D.Float rect = new Rectangle2D.Float(5, 60, (float) page.getCanvas().getClientSize().getWidth(), (float) page.getCanvas().getClientSize().getHeight());
page.getCanvas().drawString(paragraphText, font, brush, rect);
paragraph.endMarkedContent(page);
//添加“图形”元素
PdfStructureElement figure = document.appendChildElement(PdfStandardStructTypes.Figure);
figure.beginMarkedContent(page);
PdfImage image = PdfImage.fromFile("PDF.png");
page.getCanvas().drawImage(image, new Point2D.Float(5, 160));
figure.endMarkedContent(page);
//添加“表格”元素
PdfStructureElement table = document.appendChildElement(PdfStandardStructTypes.Table);
table.beginMarkedContent(page);
PdfTable pdfTable = new PdfTable();
pdfTable.getStyle().getDefaultStyle().setFont(font);
String[] data = {"姓名;年龄;性别",
"杨丽;22;女",
"李顺;25;男"
};
String[][] dataSource = new String[data.length][];
for (int i = 0; i < data.length; i++) {
dataSource[i] = data[i].split("[;]", -1);
}
pdfTable.setDataSource(dataSource);
pdfTable.getStyle().setShowHeader(true);
pdfTable.draw(page.getCanvas(), new Point2D.Float(5, 320), 300f);
table.endMarkedContent(page);
//将文档保存到文件
doc.saveToFile("创建标签PDF文件.pdf");
}
}
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Presentation for C++ 是一个专业的 PowerPoint 库,供开发人员在任何类型的 C++ 应用程序中阅读、创建、编辑和转换 PowerPoint 文档。本文演示了如何以两种不同的方式将 Spire.Presentation for C++ 集成到您的 C++ 应用程序中。
步骤1
在 Visual Studio 2022 中创建一个 C++ 项目。

步骤2
在解决方案资源管理器中右键单击“引用”,然后在弹出菜单中选择“管理 NuGet 包”。

单击“浏览”,搜索“spire.presentation.cpp”,并将其安装到您的项目中。

步骤3
在解决方案资源管理器中右键单击“源文件”,选择“添加”,然后选择“新建项”。

创建一个 .cpp 文件

步骤4
单击刚刚创建的 .cpp 文件以编写代码。在开始之前,您需要通过将以下代码行添加到您的程序来包含头文件“Spire.Presentation.o.h”。
#include "Spire.Presentation.o.h"下面的代码示例向您展示了如何使用 Spire.Presentation for C++ 创建一个简单的 PowerPoint 文件。

步骤1
下载 Spire. Presentation for C++ 包并将其解压到本地磁盘上的某个位置,以获得以下文件。

步骤2
在 Visual Studio 2022 中创建一个 C++ 项目。

步骤3
将产品包中的“include”文件夹和“lib”文件夹复制到您的项目中,并将它们保存在 .sln 文件所在的同一文件夹下。

步骤4
右键单击项目名称并选择“属性”。

配置输出目录。根据您选择的构建模式(调试或发布),可以将输出目录设置为“..\lib\x64\debug”或“..\lib\x64\release”。

步骤5
在解决方案资源管理器中右键单击“源文件”,选择“添加”,然后选择“新建项”。

创建一个 .cpp 文件

步骤6
单击刚才创建的 .cpp 文件以编写代码。开始之前,您需要在程序中包含以下两行代码。
#include "../include/Spire.Presentation.o.h"
#pragma comment(lib,"../lib/x64/debug/Spire.Presentation.Cpp.lib")下列代码示例向您展示了如何使用 Spire.Presentation for C++ 创建一个简单的 PowerPoint 文件。

页边距是 Word 文档中页面主体内容和页面边缘之间的空白部分。创建 Word 文档时,文档的文字、图片等内容通常需插入到页边距以内的位置,而页眉页脚等内容则可放在页边距中。在 Microsoft Word 中,页边距的默认值是1英寸,用户也可以根据自己的需求设置页边距。本文将介绍如何使用 Spire.Doc for Java 通过代码对 Word 文档页边距进行设置。
首先,您需要在 Java 程序中添加 Spire.Doc.jar 文件作为依赖项。您可以从此链接下载 JAR 文件;如果您使用 Maven,则可以通过在 pom.xml 文件中添加以下代码导入 JAR 文件。
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.cn/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc</artifactId>
<version>14.9.5</version>
</dependency>
</dependencies>
Spire.Doc for Java 中包含的 MarginsF 类代表页面的页边距设置,我们可以使用 Section.getPageSetup().getMargins() 方法来获取页面的页边距设置,再用 MarginsF 类下的方法设置上下左右页边距。详细操作步骤如下:
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.Section;
import com.spire.doc.documents.MarginsF;
public class setPageMargins {
public static void main(String []args){
//创建一个Document的对象
Document document = new Document();
//载入Word文档
document.loadFromFile("生而如是.docx");
//获取文档第一节
Section section = document.getSections().get(0);
//获取第一节的页边距
MarginsF pageMargin = section.getPageSetup().getMargins();
//设置第一节的上下左右页边距
pageMargin.setTop(17.9f);
pageMargin.setBottom(17.9f);
pageMargin.setLeft(17.9f);
pageMargin.setRight(17.9f);
//保存文档
document.saveToFile("设置页边距.docx", FileFormat.Docx_2013);
}
}
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Office for Java 8.2.0 已发布。在该版本中,Spire.Doc for Java 支持设置内容控件的 sdtAppearance 属性;Spire.PDF for Java支持转换 PDF 到 PPT;Spire.Presentation for Java增强了 PPT 到 SVG 和图片的转换。此外,许多已知问题也在本次更新中被成功修复。详情请阅读以下内容。
获取 Spire.Office for Java 8.2.0请点击:https://www.e-iceblue.cn/Downloads/Spire-Office-JAVA.html
新功能:
Document doc = ConvertUnit.GetNewEngineDocument();
doc.loadFromFile(inputFile);
for (Object docObj : doc.getSections().get(0).getBody().getChildObjects())
{
if (docObj instanceof StructureDocumentTag) {
DocumentObject Obj = (DocumentObject)docObj;
SDTProperties sdtProperties = ((StructureDocumentTag)Obj).getSDTProperties();
switch (sdtProperties.getSDTType())
{
case Text:
sdtProperties.setAppearance(SdtAppearance.Hidden);
break;
case Rich_Text:
sdtProperties.setAppearance(SdtAppearance.BoundingBox);
break;
case Picture:
sdtProperties.setAppearance(SdtAppearance.Tags);
break;
case Check_Box:
sdtProperties.setAppearance(SdtAppearance.Default);
break;
}
}
}
doc.saveToFile(outputFile, FileFormat.Docx);
doc.dispose();问题修复:
新功能:
PdfDocument pdfDocument =new PdfDocument();
pdfDocument.loadFromFile("input.pdf");
pdfDocument.saveToFile("output.pptx", FileFormat.PPTX);PdfStandardsConverter converter=new PdfStandardsConverter("input.pdf", "password");
converter.toPdfA2A("output.pdf");PdfCompressor compressor = new PdfCompressor("input.pdf","password");
compressor.getOptions().getImageCompressionOptions().setImageQuality(ImageQuality.Low);
compressor.compressToFile("output.pdf");问题修复:
问题修复:
问题修复:
Spire.XLS for Java 13.2.4已发布。该版本修复了多次设置公式后引用的数据路径不正确等已知问题。详情请阅读以下内容。
问题修复:
Spire.Office 8.2.2 已发布。在该版本中,Spire.PDF支持设置文本框注释的文本对齐类型,还新增 TextCompressionOptions 以支持设置压缩类型;Spire.XLS 支持 FLOOR.MATH 公式和“模拟分析”的单变量求解功能;Spire.Presentation 增强了 PPT 到图片的转换。此外,本次更新还成功修复了许多已知问题。详情请阅读以下内容。
该版本涵盖了最新版的 Spire.Doc,Spire.PDF,Spire.XLS,Spire.Email,Spire.DocViewer, Spire.PDFViewer,Spire.Presentation,Spire.Spreadsheet, Spire.OfficeViewer, Spire.DocViewer, Spire.Barcode, Spire.DataExport。
版本信息如下:
https://www.e-iceblue.cn/Downloads/Spire-Office-NET.html
新功能:
PdfDocument pdf = new PdfDocument();
PdfPageBase page = pdf.Pages.Add();
PdfRGBColor c = Color.Purple;
//color space RGB
PdfSeparationColorSpace cs = new PdfSeparationColorSpace("MySpotColor", new PdfRGBColor(c.R, c.G, c.B));
//color space CMYK
PdfSeparationColorSpace cs = new PdfSeparationColorSpace("MySpotColor", new PdfRGBColor(c.C, c.M, c.Y, c.K));
//color space Grayscale
PdfSeparationColorSpace cs = new PdfSeparationColorSpace("MySpotColor", new PdfRGBColor(c.Gray));
PdfSeparationColor color = new PdfSeparationColor(cs, 1f);
PdfSolidBrush brush = new PdfSolidBrush(color);
page.Canvas.DrawPie(brush, 10, 30, 60, 60, 360, 360);
page.Canvas.DrawString("Tint=1.0", new PdfFont(PdfFontFamily.Helvetica, 10f), brush, new PointF(22, 100));
color = new PdfSeparationColor(cs, 0.5f);
brush = new PdfSolidBrush(color);
page.Canvas.DrawPie(brush, 80, 30, 60, 60, 360, 360);
page.Canvas.DrawString("Tint=0.5", new PdfFont(PdfFontFamily.Helvetica, 10f), brush, new PointF(92, 100));
color = new PdfSeparationColor(cs, 0.25f);
brush = new PdfSolidBrush(color);
page.Canvas.DrawPie(brush, 150, 30, 60, 60, 360, 360);
page.Canvas.DrawString("Tint=0.25", new PdfFont(PdfFontFamily.Helvetica, 10f), brush, new PointF(162, 100));
pdf.SaveToFile("SpotColorrgb.pdf");PdfCompressor compressor = new PdfCompressor(fileName);
compressor.Options.TextCompressionOptions.UnembedFonts = true;
compressor.CompressToFIle(outputName);RectangleF rect = new RectangleF(x, y, 100, 15);
PdfFreeTextAnnotation textAnnotation = new PdfFreeTextAnnotation(rect);
TextAlignment(textAnnotation);
textAnnotation.TextAlignment = PdfAnnotationTextAlignment.Right;using (FileStream fileStream = new FileStream(outputFile, FileMode.Create))
{
PdfCompressor compressor = new PdfCompressor(inputFile);
compressor.CompressToStream(fileStream);
fileStream.Flush();
fileStream.Close();
}问题修复:
新功能:
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"ToCSV.xlsx");
Worksheet sheet = workbook.Worksheets[0];
//The last parameter " true" makes the result strings have quotation marks
sheet.SaveToFile(@"ToCSV.csv", ",",true);Workbook book = new Workbook();
book.LoadFromFile(inputFile);
Worksheet sheet = book.Worksheets[0];
CellRange targetCell = sheet.Range["E2"];
CellRange gussCell = sheet.Range["B4"];
GoalSeek goalSeek = new GoalSeek();
GoalSeekResult result= goalSeek.TryCalculate (targetCell, 2000, gussCell);
result.Determine();Workbook workbook = new Workbook();
workbook.Worksheets[0].Range["A1"].Formula = "FLOOR.MATH(12.758,2,-1)";
workbook.CalculateAllValue();
workbook.SaveToFile("result.xlsx");问题修复:
问题修复:
问题修复:
Spire.Presentation for Java 8.2.1 已发布。本次更新增强了 PPT 到 SVG 和图片的转换。同时,该版本还修复了一些已知问题,如修复了加载 PPT 文档程序抛出 java.lang.Exception: Error reading bytes 异常的问题。详情请阅读以下内容。
问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Presentation-JAVA.html