Spire.PDF 11.7.14 现已正式发布。最新版本新增支持 XlsxLineLayoutOptions.TextRecognizer,通过 OCR 库增强 PDF 到 Excel 的转换效果。此外,该版本还修复了一系列已知问题,例如 XPS 转 PDF 内容不正确的问题。更多详情请查阅下方内容。
新功能:
- 新增支持 XlsxLineLayoutOptions.TextRecognizer,通过 OCR 库增强 PDF 到 Excel 的转换效果。
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("in.pdf");
XlsxLineLayoutOptions options = new XlsxLineLayoutOptions(false, false, false, true);
options.TextRecognizer = new TextRecognizer();
doc.ConvertOptions.SetPdfToXlsxOptions(options);
doc.SaveToFile("out.xlsx", Spire.Pdf.FileFormat.XLSX);
// niget install PaddleOCRSharp lib
using PaddleOCRSharp;
using Spire.Pdf.Conversion;
public class TextRecognizer : ITextRecognizer
{
private static readonly PaddleOCREngine _engine;
static TextRecognizer()
{ _engine = new PaddleOCREngine(null, “”); }
public string RecognizeGlyph(Stream glyphImageStream)
{
var image = new System.Drawing.Bitmap(glyphImageStream);
// paint glyph in image center
var fixImage = new System.Drawing.Bitmap(160, 240);
using (Graphics g = Graphics.FromImage(fixImage))
{ g.DrawImage(image, new RectangleF(20, 20, fixImage.Width - 40, fixImage.Height - 40), new RectangleF(0, 0, image.Width, image.Height), GraphicsUnit.Pixel); }
var unicodeResult = _engine.DetectText(fixImage).Text;
return unicodeResult;
}
}
问题修复:
- 修复了 XPS 转 PDF 内容不正确的问题。
- 优化了 PDF 转图片的耗时性能。
- 优化了打印 PDF 耗时性能。
- 修复了 PDF 转图片,内容丢失的问题。
- 修复了 PDF 转 PDFA,内容不正确的问题。
- 修复了提取 PDF 内容失败的问题。
- 修复了 PDF 转图片,内容被覆盖的问题。
- 修复了 OFD 转 PDF 或图片,内容不正确的问题。
- 修复了 Attachments.Add() 添加附件导致多个 ” Indirect reference“ 引用的问题。
- 修复了释放 pdfTextFinder 对象抛 "System.NullReferenceException" 异常的问题。
获取 Spire.PDF 11.7.14 请点击: