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>13.12.2</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(https://cdn.e-iceblue.cn/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("https://cdn.e-iceblue.cn/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
在阅读很长的 PDF 文档时,读者可能会疲于上下滚动来寻找想要的信息。因此,为了提升文档的阅读体验,文档作者可以在文档中添加导航工具。导航按钮正是一个非常实用的导航工具,尤其是用来导航到相关内容的位置特别方便。PDF 中的导航按钮是在页面上显示为带有提示文本的按钮,文档阅读者可以通过点击按钮轻松跳转到文档的相应位置。本文将展示如何使用 Spire.PDF for 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>11.11.11</version>
</dependency>
</dependencies>
Spire.PDF for Java 提供的 PdfButtonField 类代表 PDF 文档中的按钮,此类下的方法可以用于设置按钮的格式和点击按钮时执行的操作。我们可以创建自定义的 addNavigationButton() 方法,再将按钮、动作、矩形区域、文本作为参数传递给此方法,从而创建导航按钮。详细操作步骤如下:
import com.spire.pdf.FileFormat;
import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfPageBase;
import com.spire.pdf.actions.PdfAction;
import com.spire.pdf.actions.PdfActionDestination;
import com.spire.pdf.actions.PdfGoToAction;
import com.spire.pdf.actions.PdfNamedAction;
import com.spire.pdf.fields.PdfButtonField;
import com.spire.pdf.fields.PdfForm;
import com.spire.pdf.general.PdfDestination;
import com.spire.pdf.graphics.PdfRGBColor;
import com.spire.pdf.graphics.PdfTrueTypeFont;
import java.awt.*;
import java.awt.geom.Rectangle2D;
public class addNavigationButton {
public static void main(String[] args) throws Exception {
//创建PdfDocument类的对象
PdfDocument pdf = new PdfDocument();
//载入PDF文档
pdf.loadFromFile("资产负债表.pdf");
//获取最后一页
PdfPageBase lastPage = pdf.getPages().get(pdf.getPages().getCount() - 1);
//允许在PDF文档中创建表单命令
pdf.setAllowCreateForm(true);
//创建PdfButtonField的对象
PdfButtonField btn_1 = new PdfButtonField(lastPage, "btn_1");
//创建dfNamedAction的对象并将操作设置为跳转到第一页
PdfNamedAction namedAction = new PdfNamedAction(PdfActionDestination.FirstPage);
//定义按钮的位置和大小,以及要在按钮上显示的文本
float x = 150;
float y = 300;
float width = 170;
float height = 22;
Rectangle2D.Float rect = new Rectangle2D.Float(x, y, width, height);
String text = "跳转到第一页";
//使用自定义的方法添加一个跳转到首页的导航按钮
addNavigationButton(btn_1, rect, text, namedAction);
//创建另一个PdfButtonField的对象
PdfButtonField btn_2 = new PdfButtonField(lastPage, "btn_2");
//创建PdfGoToAction的对象并将操作设置为跳转到第三页
PdfGoToAction goToAction = new PdfGoToAction(new PdfDestination(pdf.getPages().get(2)));
//定义按钮的位置和大小,以及要在按钮上显示的文本
rect = new Rectangle2D.Float( x, y + height + 5, width, height);
String text1 = "跳转到第三页";
//使用自定义的方法添加一个跳转到第三页的导航按钮
addNavigationButton(btn_2, rect, text1, goToAction);
//保存文档
pdf.saveToFile("导航按钮.pdf", FileFormat.PDF);
pdf.close();
}
static void addNavigationButton(PdfButtonField btn, Rectangle2D.Float rect, String text, PdfAction action) {
//创建PdfTrueTypeFont的对象
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("黑体", Font.PLAIN, 13), true);
//设置按钮的位置和大小
btn.setBounds(rect);
//设置按钮上文本的字体
btn.setFont(font);
//设置按钮上的文本
btn.setText(text);
//设置按钮颜色
btn.setBackColor(new PdfRGBColor(Color.ORANGE));
//设置按钮上文本的颜色
btn.setForeColor(new PdfRGBColor(Color.blue));
//设置按钮的边框颜色
btn.setBorderColor(new PdfRGBColor(Color.green));
//设置按钮在鼠标点击后的执行的操作
btn.getActions().setMouseDown(action);
//将按钮添加到文档中
PdfForm form = new PdfForm();
form.getFields().add(btn);
}
}
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.XLS 13.2.4 已发布。本次更新新增支持 FLOOR.MATH 公式和“模拟分析”的单变量求解功能,还支持设置 addQuotationForStringValue 的布尔值,使excel转换为CSV后的结果字符串带有引号。该版本还增强了 Excel 到 PDF 和图片的转换。此外,一些已知问题也在本次更新中被成功修复。详情请阅读以下内容。
新功能:
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"ToCSV.xlsx");
//The last parameter " true" makes the result strings have quotation marks
workbook.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");问题修复:
将多个 PDF 文档合并为一个 PDF 文件可以帮助您整合文档内容,让您更轻松地阅读、打印和共享文件。合并后,您只需要处理一个而不是多个文件。在本文中,您将学习如何使用 Spire.PDF for C++ 在 C++ 中将多个 PDF 文件合并为一个 PDF。
有两种方法可以将 Spire.PDF for C++ 集成到您的应用程序中。一种方法是通过 NuGet 安装它,另一种方法是从我们的网站下载包并将库复制到您的程序中。通过 NuGet 安装更简单,更推荐使用。您可以通过访问以下链接找到更多详细信息。
如何将 Spire. PDF for C++ 集成到 C++ 程序中
Spire.PDF for C++ 提供了一个静态方法 - PdfDocument::MergeFiles(std::vector<LPCWSTR_S> inputFiles) 使您能够轻松地将多个 PDF 文件合并为一个 PDF 文件。以下是详细步骤:
#include "Spire.Pdf.o.h"
using namespace Spire::Pdf;
using namespace std;
using namespace Spire::Common;
int main() {
//将输入PDF文件的路径放入矢量
std::vector<LPCWSTR_S> files = { L"Input\\文件_1.pdf", L"Input\\文件_2.pdf", L"Input\\文件_3.pdf" };
//合并向量中路径指定的 PDF 文件
boost::intrusive_ptr<PdfDocumentBase> doc = PdfDocument::MergeFiles(files);
//指定输出文件路径
wstring outputFile = L"Output\\合并PDF.pdf";
//保存结果 PDF 文件
doc->Save(outputFile.c_str(), FileFormat::PDF);
doc->Close();
}
您可以使用 PdfDocument::MergeFiles(std::vector< Stream*> streams) 方法将多个 PDF 流合并为一个 PDF。以下是详细步骤:
#include "Spire.Pdf.o.h"
using namespace Spire::Pdf;
using namespace std;
using namespace Spire::Common;
int main() {
//将输入的 PDF 文件读入流
Stream* stream1 = new Stream(L"Input\\文件_1.pdf");
Stream* stream2 = new Stream(L"Input\\文件_2.pdf");
Stream* stream3 = new Stream(L"Input\\文件_3.pdf");
//将流放入向量中
std::vector<boost::intrusive_ptr<Stream>>streams = { stream1, stream2, stream3 };
//合并 PDF 流
boost::intrusive_ptr<PdfDocumentBase> doc = PdfDocument::MergeFiles(streams);
//指定输出文件路径
wstring outputFile = L"Output\\合并PDF.pdf";
//保存结果 PDF 文件
doc->Save(outputFile.c_str(), FileFormat::PDF);
doc->Close();
}您可以使用 PdfDocument->InsertPage(PdfDocument ldDoc, int pageIndex) 或 PdfDocument->InsertPageRange(PdfDocument ldDoc, int startIndex, int endIndex) 方法将多个 PDF 文件的特定页面或一系列页面合并为单个 PDF 文件。 以下是详细步骤:
#include "Spire.Pdf.o.h"
using namespace Spire::Pdf;
using namespace std;
using namespace Spire::Common;
int main() {
//将输入的 PDF 文件的路径放入向量中
std::vector<std::wstring> files = { L"Input\\文件_2.pdf", L"Input\\文件_4.pdf" };
//创建一个 PdfDocument 对象向量
std::vector<PdfDocument*> docs(files.size());
//遍历向量中的路径
for (int i = 0; i < files.size(); i++)
{
//加载路径指定的PDF文件
docs[i] = new PdfDocument();
docs[i]->LoadFromFile(files[i].c_str());
}
//新建一个 PDF 文档
PdfDocument* newDoc = new PdfDocument();
//将第一个 PDF 的指定页面插入新 PDF
newDoc->InsertPageRange(docs[0],0, 1);
//将第二个 PDF 的指定页面插入新 PDF
newDoc->InsertPage(docs[1], 0);
//指定输出文件路径
wstring outputFile = L"Output\\合并PDF文档.pdf";
//保存结果 PDF 文件
newDoc->SaveToFile(outputFile.c_str());
//关闭 PdfDocument 对象
newDoc->Close();
for (auto doc : docs)
{
doc->Close();
}
}
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.PDF 9.2.6 已发布。该版本支持设置文本框注释的文本对齐类型,同时还支持压缩PDF文件后保存到流。此外,该版本还修复了许多已知问题,如修复了打印PDF文件后内容不正确的问题。详情请阅读以下内容。
新功能:
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();
}问题修复: