OfdToImg 1.0.5
dotnet add package OfdToImg --version 1.0.5
NuGet\Install-Package OfdToImg -Version 1.0.5
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="OfdToImg" Version="1.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OfdToImg" Version="1.0.5" />
<PackageReference Include="OfdToImg" />
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 OfdToImg --version 1.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: OfdToImg, 1.0.5"
#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 OfdToImg@1.0.5
#: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=OfdToImg&version=1.0.5
#tool nuget:?package=OfdToImg&version=1.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
OfdToImg
一个用于将OFD(开放版式文档)格式文件转换为图片的.NET库。支持多页拼接、阴影效果等功能。
功能特性
- ✅ 完整的OFD解析 - 支持OFD文档结构的完整解析
- ✅ 高质量图片转换 - 使用SkiaSharp进行高质量渲染
- ✅ 多页自动拼接 - 自动将多页OFD文档拼接为单张长图
- ✅ 页面阴影效果 - 每个页面四周带有阴影,清晰区分各页
- ✅ 路径精确渲染 - 正确处理路径坐标系统(Boundary偏移量)
- ✅ 线宽单位转换 - 自动将毫米单位转换为像素
- ✅ 图像支持 - 支持OFD中的嵌入图像
- ✅ 文本渲染 - 支持文本内容的渲染
- ✅ 跨平台支持 - 基于.NET 8.0,支持Windows、Linux、macOS
安装
通过NuGet包管理器安装:
dotnet add package OfdToImg
或在Visual Studio的NuGet包管理器中搜索 OfdToImg。
快速开始
基本用法
using OfdToImg;
// 创建转换器实例
var converter = new OfdToImageConverter();
// 加载OFD文件并转换为图片
converter.Convert("document.ofd", "output.png");
Console.WriteLine("转换完成!");
高级选项
using OfdToImg;
var converter = new OfdToImageConverter();
// 设置DPI(默认96)
converter.Dpi = 300;
// 设置页面间距(默认20像素)
converter.PageSpacing = 30;
// 转换文件
converter.Convert("document.ofd", "output.png");
获取Bitmap对象
using OfdToImg;
using SkiaSharp;
var converter = new OfdToImageConverter();
// 转换为SKBitmap对象(不保存文件)
SKBitmap bitmap = converter.ConvertToBitmap("document.ofd");
// 可以进一步处理bitmap
// ...
// 记得释放资源
bitmap.Dispose();
API参考
OfdToImageConverter
主要转换类,提供以下方法:
Convert(string ofdPath, string outputPath)
将OFD文件转换为图片并保存到指定路径。
参数:
ofdPath: OFD文件路径outputPath: 输出图片路径(支持PNG格式)
ConvertToBitmap(string ofdPath)
将OFD文件转换为SKBitmap对象。
参数:
ofdPath: OFD文件路径
返回:
SKBitmap: 渲染后的位图对象
Properties
Dpi: 渲染DPI(默认96)PageSpacing: 多页拼接时的页面间距(默认20像素)
技术细节
坐标系统
OFD使用毫米作为坐标单位,转换时会自动应用以下转换:
- 毫米 → 像素:
pixels = mm × DPI / 25.4 - 路径坐标是相对于Boundary的局部坐标,会自动加上Boundary偏移量
线宽处理
- LineWidth从毫米转换为像素
- 最小线宽设置为0.5像素,确保细线条可见
- 与WPS显示效果保持一致
多页拼接
- 所有页面垂直拼接为单张长图
- 每页宽度居中显示
- 页面间有固定间距(可配置)
- 每个页面四周有阴影效果(10像素宽)
- 画布边距为20像素,确保阴影完整显示
支持的图形元素
- ✅ 路径(Path)- 包括直线、贝塞尔曲线、圆弧等
- ✅ 图像(Image)- JPEG、PNG等格式
- ✅ 文本(Text)- 支持字体和样式
- ✅ 复合对象(Composite)
依赖项
- .NET 8.0 或更高版本
- SkiaSharp 2.88.8 - 2D图形渲染
- SixLabors.ImageSharp 3.1.5 - 图像处理
示例项目
项目中包含以下示例:
OfdSharp.ConsoleTest- 控制台测试程序OfdSharp.Test- Avalonia UI测试程序
许可证
本项目采用 MIT 许可证。详见 LICENSE 文件。
贡献
欢迎提交Issue和Pull Request!
更新日志
v1.0.5 (2026-06-17)
- ✨ 完整支持相对路径解析 (
./和../) - 🐛 修复空基路径时前导斜杠处理问题
- ✅ 所有OFD标准测试文件100%通过(13/13)
v1.0.3 (2026-06-17)
- ✨ 完整支持相对路径解析 (
./和../) - 🐛 修复空基路径时前导斜杠处理问题
- ✅ 所有OFD标准测试文件100%通过(13/13)
v1.0.2 (2026-06-17)
- 🐛 修复图片路径双斜杠问题 (
//image_10.bmp) - 🐛 修复平行结构文件资源路径解析
- ✨ 添加URL编码支持 (
Uri.UnescapeDataString()) - ✅ 修复4个之前失败的测试文件
v1.0.1 (2026-06-29)
- 🔧 将.NET版本从10.0降级到8.0(LTS长期支持版本)
- 🐛 修复版本冲突导致的编译错误
- ✨ 优化依赖项管理
v1.0.0 (2026-06-29)
- ✨ 初始版本发布
- ✅ 完整的OFD转图片功能
- ✅ 多页自动拼接
- ✅ 页面阴影效果
- ✅ 路径坐标系统修复
- ✅ 线宽优化
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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.
-
net8.0
- SixLabors.ImageSharp (>= 3.1.5)
- SkiaSharp (>= 2.88.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.