Spire.XLS for .NET 13.7.0已发布。本次更新新增支持NETWORKDAYS.INTL函数。此外,一些已知问题也在该版本中被成功修复,如将图表转换为图片后内容不正确的问题。详情请阅读以下内容。
新功能:
问题修复:
Spire.PDF 9.7.0 已发布。该版本添加了放大率对适合高度的支持,还支持创建含结构化表的标签 PDF 文件。本次更新还增强了 PDF 到 PDF/A3A 和 PDF/A1B 的转换。此外,一些已知问题也被成功修复,如打印 PDF 时印章旋转变形的问题。详情请阅读以下内容。
新功能:
PdfDocument myPdf = new PdfDocument("test.pdf");
PdfPageBase page = myPdf .Pages[0];
PdfDestination dest = new PdfDestination(page, new PointF(-40f, -40f));
dest.Mode = PdfDestinationMode.FitV;
PdfGoToAction gotoaction = new PdfGoToAction(dest);
myPdf.AfterOpenAction = gotoaction;
myPdf.ViewerPreferences.PageMode = PdfPageMode.UseOutlines;
myPdf.SaveToFile("FitBH.pdf");
myPdf.Close();PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, new PdfMargins(20));
page.SetTabOrder(TabOrder.Structure);
PdfTaggedContent taggedContent = new PdfTaggedContent(doc);
taggedContent.SetLanguage("en-US");
taggedContent.SetTitle("test");
taggedContent.SetPdfUA1Identification();
PdfTrueTypeFont font = new PdfTrueTypeFont(new System.Drawing.Font("Times New Roman", 14), true);
PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
PdfStructureElement document = taggedContent.StructureTreeRoot.AppendChildElement(PdfStandardStructTypes.Document);
PdfStructureElement heading1 = document.AppendChildElement(PdfStandardStructTypes.HeadingLevel1);
heading1.BeginMarkedContent(page);
string headingText = "What is a Tagged PDF?";
page.Canvas.DrawString(headingText, font, brush, new PointF(0, 0));
heading1.EndMarkedContent(page);
PdfStructureElement paragraph = document.AppendChildElement(PdfStandardStructTypes.Paragraph);
paragraph.BeginMarkedContent(page);
string paragraphText = ""Tagged PDF" doesn’t seem like a life-changing term. But for some, it is. For people who are " +
"blind or have low vision and use assistive technology (such as screen readers and connected Braille displays) to " +
"access information, an untagged PDF means they are missing out on information contained in the document because assistive " +
"technology cannot "read" untagged PDFs. Digital accessibility has opened up so many avenues to information that were once " +
"closed to people with visual disabilities, but PDFs often get left out of the equation.";
RectangleF rect = new RectangleF(0, 30, page.Canvas.ClientSize.Width, page.Canvas.ClientSize.Height);
page.Canvas.DrawString(paragraphText, font, brush, rect);
paragraph.EndMarkedContent(page);
PdfStructureElement figure = document.AppendChildElement(PdfStandardStructTypes.Figure);
figure.BeginMarkedContent(page);
PdfImage image = PdfImage.FromFile(TestUtil.DataPath + "ImgFiles/Bug_3938.png");
page.Canvas.DrawImage(image, new PointF(0, 150));
figure.EndMarkedContent(page);
PdfStructureElement table = document.AppendChildElement(PdfStandardStructTypes.Table);
PdfTable pdfTable = new PdfTable();
pdfTable.Style.DefaultStyle.Font = font;
System.Data.DataTable dataTable = new System.Data.DataTable();
dataTable.Columns.Add("Name");
dataTable.Columns.Add("Age");
dataTable.Columns.Add("Sex");
dataTable.Rows.Add(new string[] { "John", "22", "Male" });
dataTable.Rows.Add(new string[] { "Katty", "25", "Female" });
pdfTable.DataSource = dataTable;
pdfTable.Style.ShowHeader = true;
pdfTable.StructureElement = table;
pdfTable.Draw(page.Canvas, new PointF(0, 280), 300f);
doc.SaveToFile("1.pdf");
doc.Dispose();问题修复:
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
PDF 属性是提供有关 PDF 文件的附加信息的元数据。通常,这些属性包括但不限于文档的标题、作者、关键字、主题和创建文档的应用程序。在处理大量的 PDF 文件时,添加属性是必不可少的,因为它可以提升文件的可检索性。在本文中,您将学习如何使用 Spire.PDF for .NET 以编程方式设置或获取 PDF 属性。
首先,您需要将 Spire.XLS for .NET 包含的 DLL 文件作为引用添加到您的 .NET 项目中。DLL 文件可以从此链接下载,也可以通过 NuGet 安装。
PM> Install-Package Spire.XLS基本的 PDF 文档属性,如标题、作者、主题和关键字,使用户以后更容易搜索或检索特定文档。以下是如何使用 Spire.PDF for .NET 设置这些属性的详细步骤。
using Spire.Pdf;
namespace PDFProperties
{
class Properties
{
static void Main(string[] args)
{
//创建一个PdfDocument实例
PdfDocument pdf = new PdfDocument();
//加载PDF文件
pdf.LoadFromFile("示例文档.pdf");
//设置标题
pdf.DocumentInformation.Title = "PDF (可移植文档格式)";
//设置作者
pdf.DocumentInformation.Author = "冰蓝科技";
//设置主题
pdf.DocumentInformation.Subject = "设置PDF属性";
//设置关键字
pdf.DocumentInformation.Keywords = ".NET PDF, 属性, 文档";
//设置生成器名称
pdf.DocumentInformation.Producer = "Spire.PDF";
//保存结果文档
pdf.SaveToFile("Pdf属性.pdf");
pdf.Dispose();
}
}
}Imports Spire.Pdf
Namespace PDFProperties
Friend Class Properties
Private Shared Sub Main(ByVal args As String())
'创建一个PdfDocument实例
Dim pdf As PdfDocument = New PdfDocument()
'加载PDF文件
pdf.LoadFromFile("示例文档.pdf")
'设置标题
pdf.DocumentInformation.Title = "PDF (可移植文档格式)"
'设置作者
pdf.DocumentInformation.Author = "冰蓝科技"
'设置主题
pdf.DocumentInformation.Subject = "设置PDF属性"
'设置关键字
pdf.DocumentInformation.Keywords = ".NET PDF, 属性, 文档"
'设置生成器名称
pdf.DocumentInformation.Producer = "Spire.PDF"
'保存结果文档
pdf.SaveToFile("Pdf属性.pdf")
pdf.Dispose()
End Sub
End Class
End Namespace
要获取特定的 PDF 属性,可以使用 PdfDocumentInformation 类下的相应属性。以下是详细的步骤。
using Spire.Pdf;
using System.IO;
using System.Text;
namespace GetPdfProperties
{
class Program
{
static void Main(string[] args)
{
//创建一个PdfDocument实例
PdfDocument pdf = new PdfDocument();
//加载PDF文件
pdf.LoadFromFile("https://cdn.e-iceblue.cn/Pdf属性.pdf");
//创建StringBuilder实例
StringBuilder content = new StringBuilder();
//获取PDF文档属性并将其附加到StringBuilder中
content.Append("标题: " + pdf.DocumentInformation.Title + "\r\n");
content.Append("作者: " + pdf.DocumentInformation.Author + "\r\n");
content.Append("主题: " + pdf.DocumentInformation.Subject + "\r\n");
content.Append("关键字: " + pdf.DocumentInformation.Keywords + "\r\n");
content.Append("PDF生成器: " + pdf.DocumentInformation.Producer + "\r\n");
//将StringBuilder写入TXT文件
File.WriteAllText("获取PDF属性.txt", content.ToString());
}
}
}Imports Spire.Pdf
Imports System.IO
Imports System.Text
Namespace GetPdfProperties
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'创建一个PdfDocument实例
Dim pdf As PdfDocument = New PdfDocument()
'加载PDF文件
pdf.LoadFromFile("https://cdn.e-iceblue.cn/Pdf属性.pdf")
'创建StringBuilder实例
Dim content As StringBuilder = New StringBuilder()
'获取PDF文档属性并将其附加到StringBuilder中
content.Append("标题: " & pdf.DocumentInformation.Title.ToString().ToString() & vbCrLf)
content.Append("作者: " & pdf.DocumentInformation.Author.ToString().ToString() & vbCrLf)
content.Append("主题: " & pdf.DocumentInformation.Subject.ToString().ToString() & vbCrLf)
content.Append("关键字: " & pdf.DocumentInformation.Keywords.ToString().ToString() & vbCrLf)
content.Append("PDF生成器: " & pdf.DocumentInformation.Producer.ToString().ToString() & vbCrLf)
'将StringBuilder写入TXT文件
Call File.WriteAllText("获取PDF属性.txt", content.ToString())
End Sub
End Class
End Namespace
如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取有效期 30 天的临时许可证。
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>13.12.2</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++ 产品在同一个项目中使用,当用流方式处理文档时,应用授权后程序抛出异常的问题。