OfdNet.Layout 0.2.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package OfdNet.Layout --version 0.2.1
                    
NuGet\Install-Package OfdNet.Layout -Version 0.2.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OfdNet.Layout" Version="0.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OfdNet.Layout" Version="0.2.1" />
                    
Directory.Packages.props
<PackageReference Include="OfdNet.Layout" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OfdNet.Layout --version 0.2.1
                    
#r "nuget: OfdNet.Layout, 0.2.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OfdNet.Layout@0.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OfdNet.Layout&version=0.2.1
                    
Install as a Cake Addin
#tool nuget:?package=OfdNet.Layout&version=0.2.1
                    
Install as a Cake Tool

OfdNet

ofdrw 的 .NET 10 移植,提供 OFD 文档的读取、编辑、排版生成、 数字签名、加密、OFD-A 归档转换与文档合并。

本项目是社区移植,不是 ofdrw 官方发布,不代表上游背书。

安装

推荐直接安装元包,它会带上全部模块:

dotnet add package OfdNet

也可以按需安装单个模块:

dotnet add package OfdNet.Core       # 数据模型
dotnet add package OfdNet.Pkg        # 虚拟容器 / 打包解包
dotnet add package OfdNet.Reader     # 读取、资源定位、关键字检索
dotnet add package OfdNet.Layout     # 排版生成
dotnet add package OfdNet.Sign       # 数字签名 / 签章
dotnet add package OfdNet.Crypto     # 加密 / 解密
dotnet add package OfdNet.Gm         # SM2 / SM3 / SES 国密结构
dotnet add package OfdNet.Font       # 字体度量 / 字体子集化
dotnet add package OfdNet.Archive    # OFD-A 检查与转换
dotnet add package OfdNet.Tool       # 合并、页面删除等工具

目标框架:.NET 10。

快速开始

排版生成 OFD

using Ofd.Layout;
using Ofd.Layout.Element;

using var doc = new OFDDoc("out.ofd");
doc.Add(new Paragraph("Hello OFD", 5));
doc.Add(new Div(100, 40).SetBackgroundColor(230, 240, 255));
// Dispose / Close 时完成布局并打包

读取内容

using Ofd.Reader;

using var reader = new OFDReader("out.ofd");
int pages = reader.GetNumberOfPages();
var page = reader.GetPage(1);

关键字检索

using Ofd.Reader.Keyword;

var hits = KeywordExtractor.GetKeyWordPositionList(reader, "关键词");

字体子集化

OfdNet.Font 提供纯 C# 的 TrueType 字体子集化,不依赖 Python/fontTools:

using Ofd.Font.Subset;
using Ofd.Layout;

// 方式一:生成时自动按页面文本裁剪字体
using var doc = new OFDDoc("out.ofd");
doc.EnableFontSubsetting();
doc.Add(new Paragraph("通讯费发票……", 5));

// 方式二:对已有 OFD 原地/另存子集化
var result = OfdFontSubsetter.SubsetFile("in.ofd", "out-subset.ofd");

// 方式三:内存中处理,不产生磁盘临时文件
byte[] ofdBytes = File.ReadAllBytes("in.ofd");
byte[] subsetBytes = OfdFontSubsetter.Subset(ofdBytes);

// 方式四:只处理字体文件
var fontResult = FontSubsetter.SubsetToFile("font.ttf", "实际文本", "font.subset.ttf");

限制:

  • 仅支持 TrueType glyf 字体(TTF);CFF/OTF、TTC 暂不支持;
  • OFDDoc.EnableFontSubsetting() 仅支持输出到文件路径;
  • 签名或加密的 OFD 拒绝处理,避免破坏签名;
  • 字体子集只覆盖实际出现的字符,新增字符需重新生成或使用完整字体。

OFD-A 检查与转换

using Ofd.Archive.Check;
using Ofd.Archive.Convert;

var violations = new OFDArchiveChecker().Check("in.ofd");
new OFDArchiveConverter().Convert("in.ofd", "out-ofda.ofd");

字体说明

  • 随包提供 Noto Serif SC(SIL OFL 1.1),用于跨平台确定性排版;许可证随包附在 Assets/NotoSerif/OFL.txt。
  • 不提供 FangSong_GB2312.ttf。该字体版权归 GreatWall Computer Co.,没有再分发许可; 需要时请自行获取已授权副本,文件缺失时字体会回退到系统宋体。
  • 字体随文档嵌入时,请自行确认目标字体的再分发授权。

许可证与归属

  • 本项目以 Apache License 2.0 发布,全文见包内 LICENSE。
  • 上游归属、修改说明与第三方组件声明见包内 NOTICE、THIRD-PARTY-NOTICES.md。
  • 依赖:BouncyCastle.Cryptography(MIT)、SkiaSharp(MIT)。

源码与问题反馈:https://github.com/icysky/ofdrw-net

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on OfdNet.Layout:

Package Downloads
OfdNet.Tool

OFD 工具:文档合并、页面删除、裸文档构造。

OfdNet

OfdNet 元包:一次安装 OFD 读取、编辑、排版、签章、加密、OFD-A 与合并全部模块。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.2 103 11/16/2026
0.2.1 103 11/16/2026
0.2.0 98 11/16/2026
0.1.1 118 11/2/2026
0.1.0 109 11/2/2026

Initial NuGet release (0.1.0).