Spire.Doc for Java 14.1.0 现已正式发布。该版本优化了与列表样式相关的方法,支持创建/获取/删除图片项目符号,比较两个 ListLevel 对象,并支持通过内置模板创建单级和多级列表。此外,一些在在转换 Word 到 PDF 和 MHT 到 PDF 时出现问题也已成功被修复。详情如下。
优化:
ListStyle listStyle = document.getStyles().add(ListType.Numbered, "levelstyle");
listStyle.isCustomStyle(true);
ListLevelCollection levels = listStyle.getListRef().getLevels();
levels.get(0).setPatternType(ListPatternType.Arabic);
levels.get(0).setStartAt(1);
levels.get(0).getCharacterFormat().setFontName("Trebuchet MS");
paragraph.getListFormat().applyStyle(ListStyle listStyle);
paragraph.getListFormat().setListLevelNumber(int leverNumber)
或
paragraph.getListFormat().applyListRef(ListDefinitionReference list, int leverNumber);
新功能:
Document document = new Document();
Section sec = document.addSection();
Paragraph paragraph = sec.addParagraph();
// 创建默认项目符号列表模板
ListTemplate template = ListTemplate.Bullet_Default;
ListDefinitionReference listRef = document.getListReferences().add(template);
// 创建默认编号列表模板
ListTemplate template1 = ListTemplate.Number_Default;
listRef = document.getListReferences().add(template1);
listRef.getLevels().get(2).setStartAt(4);// 设置第3级列表从数字4开始
// 添加段落并应用编号列表样式(第2级)
paragraph = sec.addParagraph();
paragraph.appendText("List Item 1");
// 应用第2级(索引从0开始,1表示第2级)
paragraph.getListFormat().applyListRef(listRef, 1);
paragraph = sec.addParagraph();
paragraph.appendText("List Item 2");
// 应用第3级
paragraph.getListFormat().applyListRef(listRef, 2);
paragraph = sec.addParagraph();
paragraph.appendText("List Item 3");
// 应用第2级
paragraph.getListFormat().applyListRef(listRef, 1);
paragraph = sec.addParagraph();
paragraph.appendText("List Item 4");
// 应用第3级
paragraph.getListFormat().applyListRef(listRef, 2);
document.saveToFile(outputFile, FileFormat.Docx);
document.close();
Document document = new Document();
Section sec = document.addSection();
Paragraph paragraph = sec.addParagraph();
// 创建阿拉伯数字编号列表模板(如 "1.", "2.", ...)
ListTemplate template = ListTemplate.Number_Arabic_Dot;
// 使用 addSingleLevelList 创建单级列表引用
ListDefinitionReference listRef = document.getListReferences().addSingleLevelList(template);
int levelcount = listRef.getLevels().getCount();//判断层级
boolean res=listRef.isMultiLevel();
// 添加第一个列表项
paragraph = sec.addParagraph();
paragraph.appendText("List Item 1");
paragraph.getListFormat().applyListRef(listRef, 0);
paragraph = sec.addParagraph();
paragraph.appendText("List Item 2");
paragraph.getListFormat().applyListRef(listRef, 0);
document.saveToFile(outputFile, FileFormat.Docx);
document.close();
Document document = new Document();
Section sec = document.addSection();
Paragraph paragraph = sec.addParagraph();
// 创建自定义项目符号列表样式
ListStyle listStyle = document.getStyles().add(ListType.Bulleted, "bulletList");
// 获取该列表样式的各级别配置
ListLevelCollection Levels = listStyle.getListRef().getLevels();
// 为第1级设置图片项目符号
Levels.get(0).createPictureBullet();
Levels.get(0).getPictureBullet().loadImage(imag_Path_1);
// 为第2级设置图片项目符号
Levels.get(1).createPictureBullet();
Levels.get(1).getPictureBullet().loadImage(imag_Path_2);
// 添加第一个列表项
paragraph = sec.addParagraph();
paragraph.appendText("List Item 1");
paragraph.getListFormat().applyStyle(listStyle);
// 添加第二个列表项
paragraph = sec.addParagraph();
paragraph.appendText("List Item 1.1");
paragraph.getListFormat().applyStyle(listStyle);
paragraph.getListFormat().setListLevelNumber(1);
//删除第1级的图片项目符号
Levels.get(0).deletePictureBullet();
document.saveToFile(outputFile, FileFormat.Docx);
document.close();
问题修复:

在许多 Web 应用中,PDF 文件不仅仅是可下载的附件,它们往往是业务流程的最终输出结果。无论是发票、财务报表、合同、证书,还是需要在不同设备上保持版式一致的数据导出文件,PDF 都扮演着至关重要的角色。
对于 ASP.NET 开发者而言,在服务器端直接生成 PDF 文件是一项非常常见的需求。无论你是在维护传统的 ASP.NET MVC 应用,还是构建现代化的 ASP.NET Core 服务,通过代码方式生成 PDF,都可以确保输出文档在结构、排版和打印效果上的一致性。
但在实际开发中,ASP.NET 的 PDF 生成功能并不总是“开箱即用”,开发者往往会遇到一些现实问题,例如:
围绕这些问题,本文将结合 Spire.PDF for .NET,系统介绍在 ASP.NET 与 ASP.NET Core 环境中通过 C# 生成 PDF 的实用方案,涵盖 MVC 与 Web API 等常见项目类型。读完本文后,你将能够对 ASP.NET 中的 PDF 生成机制有一个清晰、可落地的认识,并将其直接应用到实际业务场景中。
快速导航
在 ASP.NET 或 ASP.NET Core 项目中开始生成 PDF 之前,首先需要确保开发环境配置正确,这有助于避免常见问题并保证项目顺利运行。
dotnet --version
要生成 PDF,你需要使用一个与项目兼容的 PDF 库。Spire.PDF for .NET 是一个常用选择,它同时支持 ASP.NET Framework 与 ASP.NET Core。
Install-Package Spire.PDF
你也可以直接 下载 Spire.PDF for .NET 并手动安装。
同时请确保运行环境具备文件写入权限(如需保存文件),并支持文档所需的字体。
本节将演示如何在 ASP.NET Framework 应用中使用 C# 创建 PDF 文件,适用于传统的 ASP.NET Web Forms 和 ASP.NET MVC 项目。
在 ASP.NET 中生成 PDF 的基本流程如下:
下面是一个简单示例,展示如何创建 PDF 并将其保存到服务器端:
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
PdfDocument document = new PdfDocument();
PdfPageBase page = document.Pages.Add();
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("微软雅黑", 12f, FontStyle.Regular), true);
page.Canvas.DrawString(
"本文件为系统自动生成的 PDF 文档,用于业务数据导出。",
font,
PdfBrushes.Black,
new PointF(40, 40)
);
document.SaveToFile(Server.MapPath("~/Output/Sample.pdf"));
document.Close();
该示例展示了在 ASP.NET 中通过 C# 创建 PDF 的核心流程:所有内容均由代码生成,开发者可以精确控制页面、文本和布局。你可以根据业务需要,在此基础上添加文本、表格或图片等内容,从而灵活构建完整的 PDF 文档。
如果需要在 PDF 中插入图片,可以参考教程:使用 C# 向 PDF 中插入图片。
在 ASP.NET MVC 项目中,PDF 通常在控制器的 Action 中生成,并直接返回给浏览器,从而实现在线预览或下载,而无需永久保存到服务器。
典型的 MVC PDF 生成实现如下所示:
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
using System.IO;
using System.Web.Mvc;
namespace WebApplication.Controllers
{
public class DefaultController : Controller
{
public ActionResult GeneratePdf()
{
// 创建 PDF 文档
using (PdfDocument document = new PdfDocument())
{
PdfPageBase page = document.Pages.Add();
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("微软雅黑", 12f, FontStyle.Regular), true);
page.Canvas.DrawString(
"在 ASP.NET MVC 中生成的 PDF 文档。",
font,
PdfBrushes.Black,
new PointF(40, 40)
);
// 将文档保存到内存流并返回给浏览器
using (MemoryStream stream = new MemoryStream())
{
document.SaveToStream(stream);
return File(
stream.ToArray(),
"application/pdf",
"MvcSample.pdf"
);
}
}
}
}
}
生成的 PDF 文档预览如下:

提示:在需要直接在线预览 PDF 的场景中,可通过 Spire.PDFViewer for ASP.NET 在 Web 环境中展示生成的文档。
在 ASP.NET Core 中生成 PDF 的核心 API 与 ASP.NET Framework 基本一致,但在文件返回方式、路径处理以及运行环境假设上存在明显差异。例如,ASP.NET Core 不再依赖 System.Web,也不推荐使用基于物理路径的文件输出方式。
本节将结合具体示例,演示如何在 ASP.NET Core MVC 和 ASP.NET Core Web API 项目中,通过流(Stream)的方式生成并返回 PDF 文件,并说明这种实现方式在跨平台和云部署场景下的优势。
在 ASP.NET Core Web 应用中,PDF 通常在控制器的 Action 中生成,并以文件形式返回。与 ASP.NET Framework 不同,ASP.NET Core 不再依赖 System.Web,文件处理一般基于流(Stream)实现。
下面示例演示了在控制器中生成 PDF 的基本做法。
在 IDE 中创建一个 ASP.NET Core Web App(MVC)项目,并在 Controllers 文件夹下新建一个名为 PdfController 的控制器,添加 CreatePdf() 方法:
using Microsoft.AspNetCore.Mvc;
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace CoreWebApplication.Controllers
{
public class PdfController : Controller
{
public IActionResult CreatePdf()
{
using (PdfDocument document = new PdfDocument())
{
PdfPageBase page = document.Pages.Add();
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("微软雅黑", 14f, FontStyle.Bold), true);
page.Canvas.DrawString(
"在 ASP.NET Core 中生成的 PDF 文档。",
font,
PdfBrushes.DarkRed,
new PointF(40, 40)
);
using (MemoryStream stream = new MemoryStream())
{
document.SaveToStream(stream);
return File(
stream.ToArray(),
"application/pdf",
"AspNetCoreSample.pdf"
);
}
}
}
}
}
生成的 PDF 文档效果如下:

这种基于流的 PDF 生成方式,更适合在后台管理系统或内部系统中使用,可由用户在界面上直接触发生成并下载结果,且无需在服务器端保留中间文件。
如果你需要在 PDF 中创建结构化表格,可以参考教程:在 ASP.NET Core 中使用 C# 生成 PDF 表格。
在前后端分离架构中,PDF 生成功能通常由 ASP.NET Core Web API 实现。此时,API 接口会以二进制流的形式返回 PDF 文件,供 Web 前端、移动端或其他服务调用。
下面是一个典型的 Web API PDF 生成示例。
在 Controllers 文件夹中创建名为 PdfApiController 的控制器,并添加如下代码:
using Microsoft.AspNetCore.Mvc;
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
[ApiController]
[Route("api/pdf")]
public class PdfApiController : ControllerBase
{
[HttpGet("generate")]
public IActionResult GeneratePdf()
{
PdfDocument document = new PdfDocument();
PdfPageBase page = document.Pages.Add();
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("微软雅黑", 14f, FontStyle.Bold), true);
page.Canvas.DrawString(
"由 ASP.NET Core Web API 生成的 PDF 文档。",
font,
PdfBrushes.BlueViolet,
new PointF(40, 40)
);
using (MemoryStream stream = new MemoryStream())
{
document.SaveToStream(stream);
document.Close();
return File(
stream.ToArray(),
"application/pdf",
"ApiGenerated.pdf"
);
}
}
}
生成的 PDF 预览效果如下:

当 PDF 生成被纳入自动化流程(例如定时任务或服务间调用)时,采用 Web API 的方式更有利于解耦前端交互与文档生成逻辑。
前面的示例主要演示了 PDF 的基本创建流程,但在真实项目中,PDF 往往并不是静态内容,而是需要根据运行时数据动态生成,并对页面布局和分页行为进行控制。
本节将通过几个常见场景,展示在 ASP.NET 应用中如何将业务数据逐条写入 PDF,并在内容增多时保持文档结构和版式的稳定性。
在实际业务中,PDF 通常需要根据数据库查询或接口返回的数据动态生成,而不是在代码中写死固定内容。这类场景的关键在于:如何在循环写入数据时,正确控制内容位置,并为后续分页预留空间。
下面示例演示了如何基于动态数据生成一个简单的类表格布局:
PdfDocument document = new PdfDocument();
PdfPageBase page = document.Pages.Add();
PdfTrueTypeFont headerFont = new PdfTrueTypeFont(new Font("微软雅黑", 12f, FontStyle.Bold), true);
PdfTrueTypeFont bodyFont = new PdfTrueTypeFont(new Font("微软雅黑", 10f, FontStyle.Regular), true);
float startY = 40;
float y = startY;
float pageHeight = page.Canvas.ClientSize.Height - 40;
// 标题
page.Canvas.DrawString("订单报表", headerFont, PdfBrushes.Black, 40, y);
y += 30;
// 示例动态数据
string[] orders = {
"订单编号 1001 - 金额 ¥2500",
"订单编号 1002 - 金额 ¥1800",
"订单编号 1003 - 金额 ¥3200"
};
foreach (string order in orders)
{
// 分页判断(示例数据不足以触发,但逻辑完整)
if (y > pageHeight)
{
page = document.Pages.Add();
y = startY;
}
page.Canvas.DrawString(order, bodyFont, PdfBrushes.Black, 40, y);
y += 20;
}
document.SaveToFile("OrderReport.pdf");
document.Close();
输出效果预览:

这种基于代码的生成方式,允许在运行时将数据库或接口返回的数据逐条绘制到 PDF 页面中。通过显式控制纵向位置和分页逻辑,即使数据行数发生变化,也能保证文档结构和版式的一致性,更适合用于报表和清单类输出。
在通过代码生成 PDF 时,页面布局并不会自动适配内容变化,开发者需要显式控制页眉、页脚以及内容的绘制位置。这一点在多页文档或需要打印输出的场景中尤为重要。
下面的示例演示如何添加页眉和页脚:
PdfPageBase page = document.Pages.Add();
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("微软雅黑", 12f), true);
page.Canvas.DrawString(
"公司内部资料",
font,
PdfBrushes.Gray,
new PointF(40, 15)
);
page.Canvas.DrawString(
"第 1 页",
font,
PdfBrushes.Gray,
new PointF(
page.Canvas.ClientSize.Width - 60,
page.Canvas.ClientSize.Height - 30
)
);
输出效果预览:

在多页 PDF 文档生成场景下,通过统一控制纵向位置的计算,并在写入内容前判断剩余空间,可以在数据超出单页容量时安全地切换到新页面。同时,将页眉、行距和分页规则集中管理,有助于保持跨页布局的一致性,使生成的文档既适合屏幕查看,也符合打印需求。
除了直接通过 C# 创建 PDF,一些 ASP.NET 应用还会根据需求采用其他 PDF 处理方式。你可以参考以下相关文章了解更多示例:
在 ASP.NET 或 ASP.NET Core 中实现 PDF 生成功能时,选择合适的 PDF 库至关重要。它将直接影响开发效率、后期维护成本以及运行时性能。
与其只关注功能列表,不如从实际应用角度评估 ASP.NET PDF 库 是否符合项目需求。
优秀的 PDF 库应提供:
这对于 PDF 逻辑需要长期演进的项目尤为重要。
许多团队同时维护旧版 ASP.NET 应用和新的 ASP.NET Core 服务。选择一个在以下环境中表现一致的库,可以显著降低迁移和维护成本:
在生产环境中,PDF 生成通常运行于:
一个合格的 ASP.NET PDF 生成器 应在高负载下保持稳定,并能高效处理多页文档,避免过度占用内存。
从实践来看,PDF 库大致可分为基于 HTML 渲染和基于代码生成两类。对于需要精确控制输出结果和版式的应用,通过 C# 代码直接生成 PDF 往往是更优选择。
得益于一致的 API 设计,Spire.PDF for .NET 中的示例代码与实际工程场景高度一致,开发者可以在理解基本用法后,自然过渡到生产级应用。
原生支持 ASP.NET 与 ASP.NET Core 同一套 API 可用于传统 ASP.NET、MVC、ASP.NET Core Web 应用以及 Web API 项目。
基于代码的 PDF 生成方式 无需依赖外部渲染引擎或浏览器组件,直接通过 C# 创建 PDF。
丰富的 PDF 功能 支持文本、图片、表格、分页、页眉页脚,适合报表、发票及各类业务文档。
部署友好 可稳定运行于服务器环境,包括容器化和云端托管的 ASP.NET Core 应用。
正因如此,Spire.PDF 非常适合对稳定性、布局控制以及跨版本兼容性要求较高的 ASP.NET PDF 生成场景,而不仅仅是快速 HTML 转换。
如需查看所有可用类和方法,可参考官方 API 文档:Spire.PDF for .NET API 参考。
可以。ASP.NET Core 中生成 PDF 并不强制依赖 MVC,除了 MVC 控制器外,还可以在以下场景中生成并返回 PDF:
只要返回的是合法的 PDF 字节流,并设置正确的 Content-Type,即可正常工作。
PDF 创建的核心逻辑基本一致,但仍存在一些差异:
从 PDF API 的角度来看,大部分代码逻辑是可以复用的。
可以。许多生产系统都是完全通过 C# 代码生成 PDF,这种方式具有以下优势:
在强调一致性和可靠性的 ASP.NET PDF 解决方案中,这是非常常见的实现模式。
在 ASP.NET 与 ASP.NET Core 应用中,生成 PDF 文件是一个非常普遍的需求,尤其适用于报表、发票和数据导出等场景。通过 C# 代码直接创建 PDF,可以对文档结构、布局和输出行为进行完全控制。
本文系统介绍了在 ASP.NET Framework 与 ASP.NET Core 中生成 PDF 的方法,涵盖了 MVC 和 Web API 场景、动态数据输出以及基础布局控制,并讨论了如何从实际项目需求出发选择合适的 PDF 库。
如果你希望在真实项目环境中完整测试这些示例、且不受功能限制,可以 申请临时许可证,以便在评估阶段解锁全部功能。
我们很高兴地宣布 Spire.Office 10.12.0 正式发布。在这个版本中,Spire.Doc 新增基于 Word 版本的文档兼容性设置;Spire.XLS 支持在 Excel 转 Markdown 时自定义导出选项;Spire.Presentation 支持压缩图片;Spire.PDF 支持设置水平和垂直文本对齐方式。同时,本次更新还修复了一系列已知问题。更多详情如下。
该版本涵盖了最新版的 Spire.Doc、Spire.PDF、Spire.XLS、Spire.Presentation、Spire.Barcode、Spire.DocViewer、Spire.PDFViewer 和 Spire.Email。
https://www.e-iceblue.cn/Downloads/Spire-Office-NET.html
新功能:
Document doc = new Document();
Section section = doc.AddSection();
Spire.Doc.Documents.Paragraph paragraph = section.AddParagraph();
Spire.Doc.Fields.TextRange farEastLayout = paragraph.AppendText("test");
FarEastLayout style = new FarEastLayout();
style.Vertical = true;
farEastLayout.CharacterFormat.FarEastLayout = style;
doc.SaveToFile(outputFile, FileFormat.Docx);
doc.Close();
//Load template documents with existing styles
Document temple = new Document();
temple.LoadFromFile("temple.docx");
//Load markdown file
Document doc = new Document();
doc = new Document(@"Doc.md");
//Copy styles from template documents
doc.CopyStylesFromTemplate(temple);
//Save
doc.SaveToFile(@"Doc.docx", Spire.Doc.FileFormat.Docx2016);
Document doc = new Document();
doc.LoadFromFile(inputFile);
RevisionInfoCollection revisionInfoCollection = doc.GetRevisionInfos();
StringBuilder sb = new StringBuilder();
foreach (RevisionInfo revisionInfo in revisionInfoCollection)
{
if (revisionInfo.RevisionType == RevisionType.FormatChange)
{
if (revisionInfo.OwnerObject is Spire.Doc.Fields.TextRange)
{
TextRange range = (TextRange)revisionInfo.OwnerObject;
sb.AppendLine("TextRange:" + range.Text + "\r\n");
doc.RevisionsView = RevisionsView.Original;
sb.AppendLine("Original style:" + "isBold:" + range.CharacterFormat.Bold + ";" + "TextColor:" + range.CharacterFormat.TextColor + ";HighlightColor:" + range.CharacterFormat.HighlightColor + ";FontName:" + range.CharacterFormat.FontName + ";UnderlineStyle:" + range.CharacterFormat.UnderlineStyle + "\r\n");
doc.RevisionsView = RevisionsView.Final;
sb.AppendLine("Final style:" + "isBold:" + range.CharacterFormat.Bold + ";" + "TextColor:" + range.CharacterFormat.TextColor + ";HighlightColor:" + range.CharacterFormat.HighlightColor + ";FontName:" + range.CharacterFormat.FontName + ";UnderlineStyle:" + range.CharacterFormat.UnderlineStyle + "\r\n");
}
}
}
File.WriteAllText(outputFile, sb.ToString());
doc.Close();
Document doc = new Document();
doc.CompatibilityOptions.UlTrailSpace = false;
doc.CompatibilityOptions.AdjustLineHeightInTable = true;
doc.CompatibilityOptions.SpaceForUL = true;
doc.CompatibilityOptions.ApplyBreakingRules = true;
doc.CompatibilityOptions.DoNotExpandShiftReturn = false;
doc.CompatibilityOptions.OverrideTableStyleFontSizeAndJustification = false;
doc.CompatibilityOptions.DoNotAutofitConstrainedTables = true;
doc.SaveToFile("outputFile");
Document doc = new Document();
doc.LoadFromFile("inputtFile");
Spire.Doc.Settings.CompatibilityOptions options = doc.CompatibilityOptions;
Document doc = new Document();
doc.LoadFromFile(inputFile);
// Set properties
doc.CompatibilityOptions.UlTrailSpace = false;
doc.CompatibilityOptions.AdjustLineHeightInTable = true;
doc.CompatibilityOptions.SpaceForUL = true;
doc.CompatibilityOptions.ApplyBreakingRules = true;
doc.CompatibilityOptions.DoNotExpandShiftReturn = false;
doc.CompatibilityOptions.OverrideTableStyleFontSizeAndJustification = false;
doc.CompatibilityOptions.DoNotAutofitConstrainedTables = true;
// Set FileFormat when saving to preserve effects
doc.SaveToFile(outputFile_after, FileFormat.Docx2016);
// Using version compatibility will reset previously set properties
Spire.Doc.Settings.CompatibilityOptions options = doc.CompatibilityOptions;
doc.CompatibilityOptions.OptimizeForWordVersion(WordVersion.Word2016);
PrintCompatibilityOptions(options, outputFile);
doc.Close();
问题修复:
调整:
新功能:
Workbook wb = new Workbook();
wb.loadFromFile("input.xlsx");
// Create export options
MarkdownOptions options = new MarkdownOptions();
// Set whether to save images using relative paths
options.setSavePicInRelativePath(true);
// Set whether to format hyperlinks as Markdown reference-style links
options.setSaveHyperlinkAsRef(true);
wb.saveToMarkdown("output.md", options);
问题修复:
新功能:
Presentation presentation = new Presentation();
presentation.LoadFromFile(inputFile);
foreach (ISlide slide in presentation.Slides)
{
foreach (Spire.Presentation.IShape shape in slide.Shapes)
{
if (shape is SlidePicture)
{
SlidePicture ps = shape as SlidePicture;
// 压缩图片:启用裁剪区域移除(true),并将图像分辨率压缩至 150 DPI(适用于网页显示的常用分辨率)
ps.PictureFill.CompressImage(true, 150f);
}
}
}
presentation.SaveToFile(outputFile, FileFormat.Pptx2013);
presentation.SaveToImage(int pageIndex, int dpiX, int dpiY);
问题修复:
调整:
优化:
问题修复:
Spire.PDF for Android via Java 10.7.9现已发布。该版本支持转换 PDF 到 Markdown 文件。更多详细信息见下文。
新功能:
PdfDocument pdf = new PdfDocument(inputFile);
pdf.saveToFile(OutputFile, FileFormat.Markdown);
PdfDocument pdf = new PdfDocument();
pdf.loadFromFile(inputFile);
ByteArrayOutputStream ms = new ByteArrayOutputStream();
pdf.saveToStream(ms, FileFormat.Markdown);
FileOutputStream outputStream = new FileOutputStream(new File(OutputFile));
outputStream.write(ms.toByteArray());
outputStream.close();
pdf.dispose();
https://www.e-iceblue.cn/Downloads/pdf-for-android-via-java.html
Spire.Office for Java 10.12.0 现已正式发布。在该版本中,Spire.Doc for Java 支持检测写保护密码是否正确;Spire.XLS for Java 优化了表头中长文本的处理逻辑;Spire.PDF for Java 减小了拆分后 PDF 文档的文件大小。此外,该版本还修复了许多已知问题。详细更新内容如下。
https://www.e-iceblue.cn/Downloads/Spire-Office-JAVA.html
Boolean protectionPassword = document.checkWriteProtectionPassword("password");
问题修复:
优化:
问题修复:
问题修复:
问题修复:
Spire.PDF for Java 11.12.16 现已发布。该版本优化了 PDF 拆分后的文件体积,显著减小了生成的 PDF 文件大小,并修复了多个与表单字段以及 OFD 转 PDF 相关的已知问题。具体更新内容如下。
问题修复:
Spire.Presentation 10.12 已发布。该版本支持压缩图片以及在转换幻灯片到图片时配置图片DPI。此外,一些在转换 PPTX 到 PDF 和加载文档时出现的问题也已成功被修复。详情请查看下文。
新功能:
Presentation presentation = new Presentation();
presentation.LoadFromFile(inputFile);
foreach (ISlide slide in presentation.Slides)
{
foreach (Spire.Presentation.IShape shape in slide.Shapes)
{
if (shape is SlidePicture)
{
SlidePicture ps = shape as SlidePicture;
// 压缩图片:启用裁剪区域移除(true),并将图像分辨率压缩至 150 DPI(适用于网页显示的常用分辨率)
ps.PictureFill.CompressImage(true, 150f);
}
}
}
presentation.SaveToFile(outputFile, FileFormat.Pptx2013);
presentation.SaveToImage(int pageIndex, int dpiX, int dpiY);
问题修复:
https://www.e-iceblue.cn/Downloads/Spire-Presentation-NET.html
Spire.XLS 15.12 现已正式发布。该版本支持在将 Excel 转换为 Markdown 时自定义导出选项。此外,新版本新增了对 .NET 10.0 的支持,并移除了部分旧版框架。同时,一些在转换 Excel 到 PDF 或 HTML,以及计算公式时出现的问题也得以成功修复。更多详情如下。
调整:
新功能:
Workbook wb = new Workbook();
wb.loadFromFile("input.xlsx");
// Create export options
MarkdownOptions options = new MarkdownOptions();
// Set whether to save images using relative paths
options.setSavePicInRelativePath(true);
// Set whether to format hyperlinks as Markdown reference-style links
options.setSaveHyperlinkAsRef(true);
wb.saveToMarkdown("output.md", options);
问题修复:
Spire.PDF 11.12 现已发布。本次更新针对 .NET Standard DLL 中 Web 打印请求缓慢的问题进行了优化,并修复了多个与文件转换和打印相关的已知问题,进一步提升了产品的稳定性和使用体验。详细更新内容如下:
优化:
问题修复:
Spire.XLS for Java 15.12.15 已正式发布,该版本对 Excel 表头中超过 253 个字符的长文本处理逻辑进行了优化,并同时修复了多个已知问题。具体更新内容如下。
优化:
问题修复: