Spire.Presentation for .NET 8.7.0已发布。本次更新不仅支持PPTX 2016和PPTX 2019文件格式,同时也支持设置图表的横坐标距轴线的距离。此外,一些已知问题也在该版本中被成功修复,如拆分PPT文档后,生成的文档无法打开的问题。详情请阅读以下内容。
新功能:
Spire.Presentation.FileFormat.Pptx2016
Spire.Presentation.FileFormat.Pptx2019Presentation ppt = new Presentation();
IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.ColumnClustered, new RectangleF(50, 50, 400, 400));
//获取PrimaryCategory轴
IChartAxis chartAxis = chart.PrimaryCategoryAxis;
//设置距轴线的距离
chartAxis.LabelsDistance = 200;
//保存文件
ppt.SaveToFile(outputFile, FileFormat.Pptx2013);问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Presentation-NET.html
Spire.Doc for C++ 11.6.3 已发布。本次更新修复了程序抛出的异常无法用 Try Catch 抓取的问题。详情请阅读以下内容。
问题修复:
重复水印,也称为多行水印,是一种在 Word 文档的页面上以固定间隔多次出现的水印。与普通水印相比,重复水印更难去除或遮盖,因此可以为文档提供更好的保护,防止未经授权的复制和分发。本文将使用 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>
我们可以通过在页眉中以指定间隔添加重复的艺术字来向 Word 文档插入重复文本水印。具体步骤如下:
import com.spire.doc.Document;
import com.spire.doc.HeaderFooter;
import com.spire.doc.Section;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.documents.ShapeLineStyle;
import com.spire.doc.documents.ShapeType;
import com.spire.doc.fields.ShapeObject;
import java.awt.*;
public class insertRepeatingTextWatermark {
public static void main(String[] args) {
//创建Document的对象
Document doc = new Document();
//载入Word文档
doc.loadFromFile("示例.docx");
//创建ShapeObject的对象并设置艺术字的文本
ShapeObject shape = new ShapeObject(doc, ShapeType.Text_Plain_Text);
shape.getWordArt().setText("草稿");
//设置文本水印的旋转角度以及垂直和水平重复次数
double rotation = 315;
int ver = 5;
int hor = 3;
//设置艺术字的格式
shape.setWidth(60);
shape.setHeight(20);
shape.setVerticalPosition(30);
shape.setHorizontalPosition(20);
shape.setRotation(rotation);
shape.getWordArt().setFontFamily("HarmonyOS Sans SC");
shape.setFillColor(Color.BLUE);
shape.setLineStyle(ShapeLineStyle.Single);
shape.setStrokeColor(Color.CYAN);
shape.setStrokeWeight(1);
//循环遍历文档中的节
for (Section section : (Iterable<Section>) doc.getSections()) {
//获取节的页眉
HeaderFooter header = section.getHeadersFooters().getHeader();
//添加一个段落到页眉中
Paragraph paragraph = header.addParagraph();
for (int i = 0; i < ver; i++) {
for (int j = 0; j < hor; j++) {
//将艺术字添加到页眉中
shape = (ShapeObject) shape.deepClone();
shape.setVerticalPosition((float) (section.getPageSetup().getPageSize().getHeight()/ver * i + Math.sin(rotation) * shape.getWidth()/2));
shape.setHorizontalPosition((float) ((section.getPageSetup().getPageSize().getWidth()/hor - shape.getWidth()/2) * j));
paragraph.getChildObjects().add(shape);
}
}
}
//保存文档
doc.saveToFile("重复文本水印.docx");
doc.dispose();
}
}
同样,我们也可以通过在文档的页眉中按照指定间隔添加重复的图片来实现向 Word 文档插入重复图像水印。具体步骤如下:
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.HeaderFooter;
import com.spire.doc.Section;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.documents.TextWrappingStyle;
import com.spire.doc.fields.DocPicture;
public class insertRepeatingPictureWatermark {
public static void main(String[] args) {
//创建Document的对象
Document doc = new Document();
//载入Word文档
doc.loadFromFile("示例.docx");
//载入图片
DocPicture pic = new DocPicture(doc);
pic.loadImage("水印.png");
//将图片的文本环绕方式设置为衬于文字下方
pic.setTextWrappingStyle(TextWrappingStyle.Behind);
//设置垂直和水平重复次数
int ver = 4;
int hor = 3;
//循环遍历文档中的节
for (Section section : (Iterable<Section>) doc.getSections()) {
//获取节的页眉
HeaderFooter header = section.getHeadersFooters().getHeader();
//在页眉中添加一个段落
Paragraph paragraph = header.addParagraph();
for (int i = 0; i < ver; i++) {
for (int j = 0; j < hor; j++) {
//添加图片到页眉中
pic = (DocPicture) pic.deepClone();
pic.setVerticalPosition((float) ((section.getPageSetup().getPageSize().getHeight()/ver) * i));
pic.setHorizontalPosition((float) (section.getPageSetup().getPageSize().getWidth()/hor - pic.getWidth()/2) * j);
paragraph.getChildObjects().add(pic);
}
}
}
//保存文档
doc.saveToFile("重复图片水印.docx", FileFormat.Auto);
doc.dispose();
}
}
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
XPS 是一种与 PDF 类似的格式,但它使用 XML 来呈现文件的布局、外观和打印信息。XPS 格式由微软开发,Windows 操作系统本身就能够支持该格式。如果您想在不安装其他软件的情况下在 Windows 计算机上使用 PDF 文件,可以将其转换为 XPS 格式。同样,如果您需要与 Mac 用户共享 XPS 文件或在各种设备上使用它,则更建议将其转换为 PDF。本文将演示如何使用 Spire.PDF for .NET 以编程方式将 PDF 转换为 XPS 或将 XPS 转换为 PDF。
首先,您需要添加 Spire.PDF for .NET 包中包含的 DLL 文件作为 .NET 项目中的引用。DLL 文件可以从此链接下载或通过 NuGet 安装。
PM> Install-Package Spire.PDFSpire.PDF for .NET 支持将 PDF 转换为各种文件格式,要实现 PDF 到 XPS 的转换,只需要三行核心代码。以下是详细的步骤。
using Spire.Pdf;
namespace ConvertPdfToXps
{
class Program
{
static void Main(string[] args)
{
//创建一个PdfDocument实例
PdfDocument pdf = new PdfDocument();
//加载示例PDF文档
pdf.LoadFromFile("示例文档.pdf");
//保存为XPS格式
pdf.SaveToFile("ToXPS.xps", FileFormat.XPS);
pdf.Close();
}
}
}Imports Spire.Pdf
Namespace ConvertPdfToXps
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'创建一个PdfDocument实例
Dim pdf As PdfDocument = New PdfDocument()
'加载示例PDF文档
pdf.LoadFromFile("示例文档.pdf")
'保存为XPS格式
pdf.SaveToFile("ToXPS.xps", FileFormat.XPS)
pdf.Close()
End Sub
End Class
End Namespace
从 XPS 到 PDF 的转换也可以使用 Spire.PDF for .NET 实现。在转换时,您可以使用 PdfDocument.ConvertOptions.SetXpsToPdfOptions() 方法设置为在生成的 PDF 文件上保持高质量的图像。以下是详细的步骤。
using Spire.Pdf;
namespace ConvertXPStoPDF
{
class Program
{
static void Main(string[] args)
{
//创建一个PdfDocument实例
PdfDocument pdf = new PdfDocument();
//加载XPS文件
pdf.LoadFromFile("Sample.xps", FileFormat.XPS);
//pdf.LoadFromXPS("Sample.xps");
//将XPS转换为PDF时保持高质量图像
pdf.ConvertOptions.SetXpsToPdfOptions(true);
//将XPS文件保存为PDF文件
pdf.SaveToFile("XPStoPDF.pdf", FileFormat.PDF);
pdf.Dispose();
}
}
}Imports Spire.Pdf
Namespace ConvertXPStoPDF
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'创建一个PdfDocument实例
Dim pdf As PdfDocument = New PdfDocument()
'加载XPS文件
pdf.LoadFromFile("Sample.xps", FileFormat.XPS)
'pdf.LoadFromXPS("Sample.xps");
'将XPS转换为PDF时保持高质量图像
pdf.ConvertOptions.SetXpsToPdfOptions(True)
'将XPS文件保存为PDF文件
pdf.SaveToFile("XPStoPDF.pdf", FileFormat.PDF)
pdf.Dispose()
End Sub
End Class
End Namespace
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Presentation for Java 8.6.2 已发布。本次更新支持了获取多边形的顶点个数和位置的功能。此外,该版本还修复了一些已知问题,如修复了添加图片时设置3D旋转效果不生效的问题。详情请阅读以下内容。
新功能:
Presentation ppt = new Presentation();
ppt.loadFromFile(inputFile);
IAutoShape shape = (IAutoShape)ppt.getSlides().get(0).getShapes().get(0);
ArrayList<Point2D> points = shape.getPoints();
String text1 = "point count:" + " " + points.size() + "\r\n";
FileWriter writer1 = new FileWriter(outputFile, true);
writer1.append(text1);
writer1.close();
for (int i = 0; i < points.size(); i++)
{
String text2 = "point" + i + " " + points.get(i) + "\r\n";
FileWriter writer2 = new FileWriter(outputFile, true);
writer2.append(text2);
writer2.close();
}问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Presentation-JAVA.html
如果您想将多个图像合并为一个文件以便于分发或存储,那么将它们转换为一个 PDF 文档是一个很好的解决方案。这一过程不仅节省了空间,还确保所有图像都保存在一个文件中,便于共享或传输。在本文中,您将学习如何使用 Spire.PDF for .NET 在 C# 和 VB.NET 中将多个图像组合成一个 PDF 文档。
首先,您需要添加 Spire.PDF for .NET 包中包含的 DLL 文件作为 .NET 项目中的引用。DLL 文件可以从此链接下载或通过 NuGet 安装。
PM> Install-Package Spire.PDF为了将文件夹中的所有图像转换为 PDF,我们遍历每个图像,在 PDF 中添加一个与图像大小相同的新页面,然后将图像绘制到新页面上。以下是详细的步骤。
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
using System.IO;
namespace ConvertMultipleImagesIntoPdf
{
class Program
{
static void Main(string[] args)
{
//创建PdfDocument对象
PdfDocument doc = new PdfDocument();
//将页边距设置为零
doc.PageSettings.SetMargins(0);
//获取存储图像的文件夹
DirectoryInfo folder = new DirectoryInfo(@"C:\Users\Administrator\Desktop\图片");
//遍历文件夹中的文件
foreach (FileInfo file in folder.GetFiles())
{
//加载特定图像
Image image = Image.FromFile(file.FullName);
//获取图像宽度和高度
float width = image.PhysicalDimension.Width;
float height = image.PhysicalDimension.Height;
//添加与图像大小相同的页面
PdfPageBase page = doc.Pages.Add(new SizeF(width, height));
//基于图像创建PdfImage对象
PdfImage pdfImage = PdfImage.FromImage(image);
//在页面的(0,0)处绘制图像
page.Canvas.DrawImage(pdfImage, 0, 0, pdfImage.Width, pdfImage.Height);
}
//保存文件
doc.SaveToFile("结果文档.pdf");
doc.Dispose();
}
}
}Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports System.Drawing
Imports System.IO
Namespace ConvertMultipleImagesIntoPdf
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'创建PdfDocument对象
Dim doc As PdfDocument = New PdfDocument()
'将页边距设置为零
doc.PageSettings.SetMargins(0)
'获取存储图像的文件夹
Dim folder As DirectoryInfo = New DirectoryInfo("C:\Users\Administrator\Desktop\图片")
'遍历文件夹中的文件
For Each file In folder.GetFiles()
'加载特定图像
Dim image As Image = Image.FromFile(file.FullName)
'获取图像宽度和高度
Dim width As Single = image.PhysicalDimension.Width
Dim height As Single = image.PhysicalDimension.Height
'添加与图像大小相同的页面
Dim page As PdfPageBase = doc.Pages.Add(New SizeF(width, height))
'基于图像创建PdfImage对象
Dim pdfImage As PdfImage = PdfImage.FromImage(image)
'在页面的(0,0)处绘制图像
page.Canvas.DrawImage(pdfImage, 0, 0, pdfImage.Width, pdfImage.Height)
Next
'保存文件
doc.SaveToFile("结果文档.pdf")
doc.Dispose()
End Sub
End Class
End Namespace
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
Spire.Office for C++ 8.6.0 已发布。在该版本中,Spire.Doc for C++、Spire.XLS for C++、Spire.Presentation for C++ 以及 Spire.PDF for C++ 修复了两个及以上的 C++ 产品在同一个项目中使用,当用流方式处理文档时,应用授权后程序抛出异常的问题。详情请阅读以下内容。
获取 Spire.Office for C++ 8.6.0请点击:https://www.e-iceblue.cn/Downloads/Spire-Office-CPP.html
问题修复:
Spire.Doc for C++、Spire.XLS for C++、Spire.Presentation for C++ 以及 Spire.PDF for C++ 修复了两个及以上的 C++ 产品在同一个项目中使用,当用流方式处理文档时,应用授权后程序抛出异常的问题。
Spire.XLS for Java 13.6.5 已发布。该版本增强了 Excel 到 PDF 的转换。此外,该版本还修复了一些已知问题,如修复了添加水印后chart的横坐标发生改变的问题。详情请阅读以下内容。
问题修复:
Spire.PDF for Java 9.6.2 已发布。本次更新增强了 PDF 到 Word 和 Excel 以及 OFD 到 PDF 的转换。此外,一些已知问题在该版本中被成功修复,如用 WPS 工具打开文档不显示添加的文本框的问题。详情请阅读以下内容。
问题修复:
将 PDF 文件转换为图片是文档管理系统、电子档案平台或在线预览工具中的常见需求,广泛应用于缩略图生成、跨平台内容展示及历史文档存档等业务场景。对于.NET开发人员来说,Spire.PDF库提供了一种强大而有效的方法来实现PDF到图像的高保真转换。其主要优势包括
在本文中,您将学习如何使用 Spire.PDF for .NET库在 C# 中将 PDF 转换为 JPG 或 PNG 图片,包括安装指南、实用代码片段和转换优化技巧等。
在开始使用 C# 将 PDF 转换为 PNG 或 PDF 转换为 JPG 之前,需要先安装 Spire.PDF for .NET 库。您可以通过 NuGet 包管理器进行安装:
或者,使用程序包管理器控制台:
PM> Install-Package Spire.PDF
PdfDocument 类的 SaveAsImage(int pageIndex, PdfImageType type) 方法可用于将指定的 PDF 页面转换为图片。其中的两个参数:
1、 pageIndex (Int32)
2、 Type (PdfImageType)
以下C#代码演示了如何使用 Spire.PDF 将PDF文档的第一页转换为JPEG图像:
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
using System.Drawing.Imaging;
namespace PDFtoJPG
{
class Program
{
static void Main(string[] args)
{
// 创建PdfDocument 对象
PdfDocument pdf = new PdfDocument();
// 加载示例PDF 文档
pdf.LoadFromFile("示例.pdf");
// 将第二页转换为 bitmap 图片
Image image = pdf.SaveAsImage(1, PdfImageType.Bitmap);
// 将图片保存为JPG 格式
image.Save("Pdf转JPG.jpg", ImageFormat.Jpeg);
// 释放资源
pdf.Dispose();
}
}
}

Spire.PDF 提供了另一种 SaveAsImage() 方法的重载,该方法需要四个参数:页面索引、图片类型、水平分辨率(dpiX) 和垂直分辨率(dpiY)。 使用该方法,您可以通过自定义DPI设置来控制输出图像的质量和大小。
下面的C#代码示例将PDF的第一页转换为高分辨率的PNG图像(300 DPI):
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
using System.Drawing.Imaging;
namespace PDFtoImage
{
class Program
{
static void Main(string[] args)
{
// 创建PdfDocument 对象
PdfDocument pdf = new PdfDocument();
// 加载示例PDF 文档
pdf.LoadFromFile("示例.pdf");
// 将第二页转换为指定分辨率的图片
Image image = pdf.SaveAsImage(1, PdfImageType.Bitmap, 300, 300);
// 将图片另存为PNG 格式
image.Save("Pdf转PNG.png", ImageFormat.Png);
// 释放资源
pdf.Dispose();
}
}
}

请注意:DPI 越高,图像质量越好,但转换速度越慢。
遍历PDF 中的所有页面,然后将每个页面转换为单独的图片:
// 遍历PDF中所有页面
for (int i = 0; i < pdf.Pages.Count; i++)
{
// 将每页转换为单独的图片并设置Dpi
Image image = pdf.SaveAsImage(i, PdfImageType.Bitmap, 300, 300);
// 将图片保存为PNG格式
string file = string.Format("Image\\ToImage-{0}.png", i);
image.Save(file, ImageFormat.Png);
}
通过更改 Image.Save() 方法的 ImageFormat 参数,可以将 PDF 转换为 JPG、PNG、BMP 或 Gif 格式:
// 保存为 JPEG 格式
image.Save("PDFtoJPG.jpg", ImageFormat.Jpeg);
// 保存为 PNG 格式
image.Save("PDFtoPNG.png", ImageFormat.Png);
// 保存为 BMP 格式
image.Save("PDFtoBMP.bmp", ImageFormat.Bmp);
// 保存为 EMF 格式
image.Save("PDFtoEMF.emf", ImageFormat.Emf);
// 保存为 GIF 格式
image.Save("PDFtoGIF.gif", ImageFormat.Gif);
对于需要处理数据流的情况,可参考以下代码:
// 创建 MemoryStream 对象
MemoryStream ms = new MemoryStream();
// 将第一页转换为图片并设置dpi
Image image = pdf.SaveAsImage(0, PdfImageType.Bitmap, 300, 300);
// 以 PNG 格式将图像保存到流
image.Save(ms, ImageFormat.Png);
// 将Stream对象写入字节数组,以便进一步处理
byte[] imageBytes = ms.ToArray();
Spire.PDF 为 C# 开发者提供了一种高效的方式来将 PDF 文件转换为图片。其强大的功能集、高质量的渲染效果以及对多种图像格式的支持,使其成为处理简单或复杂 PDF 转图片任务的理想选择。通过本文提供的示例,您可以在.NET 应用程序中快速集成 PDF 转换功能。
答:您可以申请30天免费试用许可证,以去除红色水印并全面评估Spire.PDF库。或者您也可以使用免费版(有一定的页面限制)。
答:可以!官方详细教程请参阅: 使用C#将PDF转换为TIFF
答:可以!Spire.PDF for .NET提供了 SaveToFile(String, FileFormat.SVG) 方法,用于将PDF文件转换为SVG文件。完整示例可以查看这篇文章。