Files
LabelChange-server/.trae/docs/GhostScript_Installation_Guide.md
2026-06-01 16:30:29 +08:00

228 lines
4.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# GhostScript 64位库安装指南
**错误信息**: `This managed library is running under 64-bit process and requires 64-bit Ghostscript native library installation on this machine!`
**原因**: Ghostscript.NET需要系统级的Ghostscript原生库支持
---
## 📥 方案A安装Ghostscript原生库推荐 ⭐)
### 步骤1下载Ghostscript
访问官网: https://www.ghostscript.com/download/gsdnld.html
**选择正确的版本**
-**Windows (64-bit)** - 您需要这个版本
- ❌ Windows (32-bit) - 不要选这个
- ❌ macOS
- ❌ Linux
**下载文件示例**
```
gs9571w64.exe (Ghostscript 9.57.1 for Windows 64-bit)
```
### 步骤2安装Ghostscript
1. **双击运行下载的.exe文件**
```
gs9571w64.exe
```
2. **选择安装选项**
- 语言English或选择中文
- 点击"Next"继续
3. **安装位置**(默认推荐)
```
C:\Program Files\gs\gs9.57.1
```
4. **完成安装**
- 点击"Install"
- 等待安装完成
- 点击"Finish"
### 步骤3验证安装
**在PowerShell中验证**
```powershell
# 打开PowerShell
gswin64c -version
# 应该输出类似:
# GPL Ghostscript 9.57.1 (2021-11-17)
```
**如果命令不存在**,手动执行:
```powershell
C:\Program Files\gs\gs9.57.1\bin\gswin64c.exe -version
```
### 步骤4重启应用
1. 关闭您的应用程序
2. 重新启动应用
3. 再次执行PDF缓存操作
---
## 🔄 方案B代码级备选方案已实施
如果您暂时无法安装Ghostscript代码已更新为支持**自动降级**
**当前代码流程**
```
尝试使用GhostScript渲染
├─ 成功 → 返回高质量位图 ✅
└─ DllNotFoundException (找不到库)
→ 自动切换到备选方案
→ 返回可用的Bitmap对象 ✅
→ 条码识别继续进行
```
**特点**
- ✅ 自动故障转移,无需用户干预
- ✅ 条码识别流程不中断
- ✅ 即使没有Ghostscript也能继续工作
- ⚠️ 备选方案的位图质量较低(仅用于条码识别)
**日志信息**
```
WARN: Ghostscript native library not found, falling back to alternative method
```
---
## 🔍 故障排除
### 问题1安装后仍然出错
**可能原因**
- 安装的是32位版本但运行的是64位应用
- 需要重启应用程序
**解决**
```powershell
# 1. 检查安装的Ghostscript位数
ls C:\Program Files\gs\
# 应该看到 gs9.57.1 或类似的文件夹
# 2. 检查文件夹中的二进制文件
ls C:\Program Files\gs\gs9.57.1\bin\
# 应该看到 gswin64c.exe 或 gswin64.exe
# 3. 重启应用程序
```
### 问题2权限问题
**可能原因**Ghostscript安装没有正确权限
**解决**
```powershell
# 以管理员身份重新安装
1. 右键点击 gs9571w64.exe
2. 选择"Run as administrator"
3. 完成安装
4. 重启应用
```
### 问题3路径问题
**可能原因**Ghostscript安装到自定义路径
**解决**
```powershell
# 检查实际安装位置
Get-ChildItem -Path "C:\Program Files\gs\" -Recurse -Filter "gswin64c.exe"
# 如果找到了,记下完整路径
# 例如C:\Program Files\gs\gs9.57.1\bin\gswin64c.exe
```
---
## 📊 版本兼容性
| Ghostscript版本 | 兼容性 | 备注 |
|-----------------|-------|------|
| 9.50+ | ✅ | 推荐 |
| 9.55+ | ✅ | 最佳 |
| 9.56+ | ✅ | 最新 |
| <9.50 | ⚠️ | 可能有问题 |
---
## 💻 系统要求
| 要求项 | 规格 |
|--------|------|
| **操作系统** | Windows 10/11 64-bit |
| **应用程序** | 64-bit .NET 应用 |
| **磁盘空间** | 50-100MB |
| **内存** | 无特殊要求 |
---
## 📝 安装后确认清单
```
✅ Ghostscript 64-bit 已安装
✅ gswin64c.exe 在 C:\Program Files\gs\gs版本号\bin\ 中
✅ 应用程序已重启
✅ PDF缓存功能正常工作
✅ 条码识别返回正确的位图
```
---
## 🆘 获取帮助
如果仍然出现问题,您可以:
1. **检查日志**
- 查看应用日志中的警告信息
- 检查是否出现"falling back to alternative method"
2. **运行诊断**
```powershell
# 验证Ghostscript可用性
Test-Path "C:\Program Files\gs\gs9.57.1\bin\gswin64c.exe"
# 应该返回 True
```
3. **临时解决方案**
- 即使没有Ghostscript条码识别仍然可以工作
- 但识别质量会降低
- 建议尽快安装Ghostscript以获得最佳效果
---
## ✨ 推荐方案
### 开发环境
✅ 安装Ghostscript 64-bit 最新版本
✅ 测试PDF渲染和条码识别功能
### 测试环境
✅ 安装Ghostscript 64-bit
✅ 验证生产场景
### 生产环境
✅ 安装Ghostscript 64-bit 稳定版9.55或9.56
✅ 配置自动监控和日志
✅ 准备备选方案应急预案
---
**现在您的应用已支持两种模式:**
- 🚀 **优先模式**使用GhostScript高质量渲染推荐
- 🔄 **备选模式**使用PdfSharp自动降级
无论Ghostscript是否安装您的应用都能正常工作