Spire.Presentation 10.7.7 现已正式发布。最新版本支持加载 Markdown 文件。此外,该版本还成功修复了带有复制幻灯片的文件打开报错的问题。更多详情请查阅下方内容。
新功能:
Presentation pt = new Presentation();
pt.LoadFromFile(inputFilePath, FileFormat.Markdown);
pt.SaveToFile(outputFile, FileFormat.Pptx2013);
问题修复:
PDF 是数字文档管理的普遍格式,但其固定布局特性限制了在需要灵活编辑、更新或现代工作流集成场景下的应用。相比之下,Markdown(.md)语法轻量、易读,非常适合网页发布、文档编写和版本控制。本文将介绍如何使用 Spire.PDF for Python 库,在 Python 中高效实现 PDF 到 Markdown 的单文件转换与批量转换。
在内容创作与管理中,Markdown 相比 PDF 有显著优势:
Spire.PDF for Python 提供了一套强大的解决方案,能从 PDF 中提取文本和结构信息,同时保留表格、列表、基础样式等关键格式元素。
要在项目中使用 Spire.PDF for Python,需通过 PyPI 使用 pip 安装该库。打开终端或命令提示符,运行:
pip install Spire.PDF
若需将已安装版本升级至最新版,运行:
pip install --upgrade spire.pdf
以下基本示例展示了如何使用 Python 将 PDF 文件转换为 Markdown(.md)文件。
from spire.pdf.common import *
from spire.pdf import *
# 创建PdfDocument类的实例
pdf = PdfDocument()
# 加载PDF文档
pdf.LoadFromFile("测试.pdf")
# 将PDF转换为Markdown文件
pdf.SaveToFile("PDF转Markdown.md", FileFormat.Markdown)
pdf.Close()
这段Python 代码的逻辑很简单:先加载 PDF 文件,再通过 SaveToFile() 方法将其转为 Markdown 格式,其中 FileFormat.Markdown 参数用于指定输出格式。
转换说明
该库从 PDF 中提取文本、图片、表格和基本格式,并将它们转换为 Markdown 语法。
转换结果:

以下 Python 代码通过循环将指定目录中的所有 PDF 文件批量转换为 Markdown 格式。
import os
from spire.pdf import *
# 配置路径
input_folder = "PDF文件/"
output_folder = "转换结果/"
# 创建输出目录
os.makedirs(output_folder, exist_ok=True)
# 处理文件夹中的所有PDF
for file_name in os.listdir(input_folder):
if file_name.endswith(".pdf"):
# 初始化文档
pdf = PdfDocument()
pdf.LoadFromFile(os.path.join(input_folder, file_name))
# 生成输出路径
md_name = os.path.splitext(file_name)[0] + ".md"
output_path = os.path.join(output_folder, md_name)
# 转换为Markdown
pdf.SaveToFile(output_path, FileFormat.Markdown)
pdf.Close()
转换特点:
转换效果:

答:Spire.PDF 提供免费版本,但有使用限制(例如,每次转换最多 3 页)。如需无限制使用,可申请 30 天免费试用授权进行评估。
答:可以。使用 LoadFromFile 方法时,将密码作为第二个参数传入即可:
pdf.LoadFromFile("ProtectedFile.pdf", "your_password")
答:无法直接转换。该库仅提取文本类内容。对于扫描版 PDF,需先使用 OCR 工具(如 Spire.OCR for Python)将其转为可搜索的 PDF 文档。
Spire.PDF for Python 简化了 PDF 到 Markdown 的转换流程,无论单文件还是批量处理均能轻松应对。其核心优势包括:
无论你是迁移文档、处理研究论文,还是搭建内容处理流水线,按照本文中的示例操作,都能高效将静态 PDF 转为灵活可编辑的 Markdown 内容,进而简化工作流程并提高协作效率。
Spire.Presentation for Python 10.7.1 更新已发布。本次更新新增支持添加 SVG 到 PPT,同时优化并模块化设计了命名空间结构。更多详细信息请阅读以下内容。
调整:
新功能:
#Load a PPT document
presentation = Presentation()
#Insert svg to PPT
presentation.Slides[0].Shapes.AddFromSVGAsShapes(SvgFile)
#Save the document
presentation.SaveToFile(outputFile, FileFormat.Pptx2010)
presentation.Dispose()

现代商业系统高度依赖条形码扫描功能,从零售收银通道到仓库库存追踪皆是如此。如今,强大的编程库使得将这一核心功能集成到定制化软件解决方案中变得异常简单。其中,基于 Python 的实现方案因其多功能性和易用性而格外受欢迎。
本文将介绍如何使用 Spire.Barcode for Python 库 在 Python 中读取条形码,该库提供了简单易用的条形码扫描API。文章涵盖库的安装配置、从图像文件及字节流中读取条形码、设置自定义识别选项等全方位内容。
目录 :
Spire.Barcode for Python 是一款专为 Python 应用程序设计的强大条形码生成与读取库,凭借其丰富的功能和易用的接口脱颖而出。该库支持多种条形码格式,包括:
Spire.Barcode 的核心特性:
该库不仅支持从图像和流中读取条形码,还提供丰富的自定义选项,满足多样化的应用需求。
要开始使用 Spire.Barcode,首先需要安装该库,您可以通过 pip 完成此操作。打开终端并运行以下命令:
pip install spire.barcode
安装库后,您需要一个许可证密钥来解锁全部功能。您可以从我们的官网获取试用许可证。获得许可证密钥后,在 Python 脚本中设置库:
from spire.barcode import *
# 应用许可证密钥以解锁全部功能
License.SetLicenseKey("your license key")
现在库已准备就绪,您就可以开始使用 Python 读取条形码了。
使用 Spire.Barcode 从图像文件中读取单个条形码非常简单,具体操作如下:
from spire.barcode import *
# 应用许可证密钥以解锁全部功能
License.SetLicenseKey("your license key")
# 从图像文件读取单个条形码
result = BarcodeScanner.ScanOneFile("C:/Users/Administrator/Desktop/qr_code.png")
# 打印结果
print(result)
代码说明
效果图:

您可能感兴趣:Python 生成及识别二维码
若需从单个图像文件中读取多个条形码,Spire.Barcode同样能轻松实现。以下是具体示例:
from spire.barcode import *
# 应用许可证密钥以解锁全部功能
License.SetLicenseKey("your license key")
# 从文件读取多个条形码
results = BarcodeScanner.ScanFile("C:/Users/Administrator/Desktop/barcodes.jpg")
# 打印结果
print(results)
代码说明
效果图:

除了直接从文件中读取条形码,Spire.Barcode for Python 还支持从内存中的图像字节解码条形码,这种方案特别适用于处理动态加载的图像(如来自API接口、数据库或用户上传的场景)。
以下是实现方法:
from spire.barcode import *
# 应用许可证密钥以解锁全部功能
License.SetLicenseKey("your license key")
# 读取图像文件到内存
image_path = "C:/Users/Administrator/Desktop/barcodes.jpg"
with open(image_path, "rb") as file:
image_bytes = file.read()
# 将字节流封装为 Spire.Barcode 的 Stream 对象中
stream = Stream(image_bytes)
# 从流中读取一个条形码
# result = BarcodeScanner.ScanOneStream(stream)
# 从流中读取多个条形码
results = BarcodeScanner.ScanStream(stream)
# 打印结果
print(results)
代码说明
Spire.Barcode 的 BarcodeScanner 类提供多种方法用于自定义识别参数,可显著提升检测精度和效率。核心配置方法包括:
应用示例(指定条码类型 + 校验和验证)
from spire.barcode import *
# 应用许可证密钥以解锁全部功能
License.SetLicenseKey("your license key")
# 指定条形码类型(例如,EAN13)
barcode_type = BarCodeType.EAN13
# 带校验和验证的条码扫描
result = BarcodeScanner.ScanOneFileBarCodeTypeIncludeCheckSum("C:/Users/Administrator/Desktop/EAN_13.png", barcode_type, True)
# 打印结果
print(result)
代码说明
本文详细介绍了如何使用 Spire.Barcode 库在 Python 中实现条形码识别功能,内容包括:
掌握这些方法后,您可轻松为 Python 应用程序集成专业的条码扫描能力。
Spire.Barcode 支持多种条形码格式,包括 QR 码、UPC、EAN、Code 128、Code 39 等。
是的,您需要许可证密钥以解锁库的全部功能。您可以该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。获取免费的 30 天试用许可证。
虽然 Spire.Barcode 不直接支持网络摄像头输入,但您可以从网络摄像头捕获图像,然后使用该库从这些图像中读取条形码。
您可以通过指定条形码类型和在扫描过程中启用校验和验证来提高准确性。此外,确保图像足够清晰。
是的,Spire.Barcode 支持条形码识别和生成。有关详细说明,请查看本教程:如何使用 Python 生成条形码
Spire.PDF for Java 11.7.5现已发布,该版本支持将 PDF 转换为 Markdown,并解决了几个已知问题,包括在 PDF 转换为图像时文本出现乱码以及在将 OFD 转换为 PDF 时内容旋转的问题。有关更多详细信息,请参见以下信息。
新功能:
PdfDocument doc = new PdfDocument("input.pdf");
doc.saveToFile("output.md", FileFormat.Markdown);
调整:
问题修复:
Spire.Doc 13.7.9 现已发布。该版本新增了多项功能, 如支持创建组合图表,支持在将 Word 转换为 PDF 时设置图像压缩方法。此外还修复了一个在转换Doc到PDF时标题图像被拉伸的问题。详情如下。
新功能:
Document doc = new Document();
Paragraph paragraph = doc.AddSection().AddParagraph();
Chart chart = paragraph.AppendChart(ChartType.Column, 450, 300).Chart;
// 将'Series 3' 修改为折线图,并显示在次坐标轴上
chart.ChangeSeriesType("Series 3", ChartSeriesType.Line, true);
Console.WriteLine(chart.Series[2].ChartType);
doc.SaveToFile("组合图表.docx");
Document document = new Document();
// 设置默认替换字体
doc.DefaultSubstitutionFontName = "Arial";
Section sec = doc.AddSection();
Paragraph para = sec.AddParagraph();
TextRange tr = para.AppendText("test");
tr.CharacterFormat.FontName = "Helvetica";
doc.SaveToFile(outputFile, FileFormat.PDF);
doc.Close();
// 处理内联结构标记
List tagInlines = structureTags.getM_tagInlines();
for (int i = 0; i < tagInlines.Count; i++)
{
tagInlines[i].RemoveSelfOnly();
}
// 处理其他结构标记
List tags = structureTags.getM_tags();
for (int i = 0; i < tags.Count; i++)
{
tags[i].RemoveSelfOnly();
}
// 处理 StructureDocumentTagRow
List rowtags = structureTags.getM_rowtags();
for (int i = 0; i < rowtags.Count; i++)
{
rowtags[i].RemoveSelfOnly();
}
// 处理 StructureDocumentTagCell
List celltags = structureTags.getM_celltags();
for (int i = 0; i < celltags.Count; i++)
{
celltags[i].RemoveSelfOnly();
}
Document document = new Document();
document.LoadFromFile(@"Sample.docx");
ToPdfParameterList para = new ToPdfParameterList();
para.PdfImageCompression = Spire.Doc.Export.PdfImageCompression.Jpeg;
document.SaveToFile(outputFile,para);
Document document = new Document();
Section section = doc.AddSection();
foreach (string ommlCode in OmqlCodes)
{
OfficeMath officeMath = new OfficeMath(doc);
officeMath.CharacterFormat.FontSize = 14f;
officeMath.FromOMMLCode(ommlCode);
section.AddParagraph().ChildObjects.Add(officeMath);
}
doc.SaveToFile(outputFile, FileFormat.Docx2013);
doc.Dispose();
Document document = new Document();
doc.LoadFromFile(inputFile);
StringBuilder stringBuilder = new StringBuilder();
// 遍历文档中所有节
foreach (Section section in doc.Sections)
{
// 遍历每一节中的所有段落
foreach (Paragraph par in section.Body.Paragraphs)
{
// 遍历每一个段落中的子对象
foreach (DocumentObject obj in par.ChildObjects)
{
// 判断对象是否为OfficeMath 公式
OfficeMath omath = obj as OfficeMath;
if (omath == null) continue;
// 将 OfficeMath 公式转换为 LaTex 代码
string mathml = omath.ToLaTexMathCode();
// 将 MathML 代码添加到StringBuilder
stringBuilder.Append("LaTeX code" + mathml);
stringBuilder.Append("\r\n");
}
}
}
// 将 LaTex 代码写入文本文件
File.WriteAllText(outputFile, stringBuilder.ToString());
问题修复:
Spire.XLS for Java 15.7.7 现已正式发布。最新版本支持 MarkerDesigner 使用 Array 数据。此外,该版本还成功修复了一些已知问题,例如 Excel 转 PDF,linux 环境下字体不正确的问题。更多详情请查阅下面的内容。
新功能:
Workbook workbook = new Workbook();
// Get the first worksheet from the workbook
Worksheet sheet = workbook.getWorksheets().get(0);
// Set the value of cell range A1 to "&=Array"
sheet.getCellRange("A1").setValue("&=Array");
// Add a parameter named "Array" with an array of strings as its value
workbook.getMarkerDesigner().addArray("Array",new String[] { "Spire.Xls", "Spire.Doc","Spire.PDF", "Spire.Presentation","Spire.Email" });
// Apply the marker design to the workbook
workbook.getMarkerDesigner().apply();
// Calculate all the values in the workbook
workbook.calculateAllValue();
// Auto-fit the rows and columns in the allocated range of the worksheet
sheet.getAllocatedRange().autoFitRows();
sheet.getAllocatedRange().autoFitColumns();
// Save the workbook to the specified file path using Excel 2013 format
workbook.saveToFile(outputFile, ExcelVersion.Version2013);
// Clean up and release resources used by the workbook
workbook.dispose();
问题修复:
Spire.XLS 15.7.8 现已正式发布。该版本新增了 LoadFromMarkdown() 方法,可加载 Markdown 格式文档。同时修复了多个问题,包括 Excel 转 PDF 时的复选框显示错误、AGGREGATE 公式计算异常、文本换行和分页错误等。详情如下:
新功能:
Workbook wb = new Workbook();
wb.LoadFromMarkdown("test.md");
wb.SaveToFile("out.pdf", FileFormat.PDF);
wb.SaveToFile("out.xlsx", ExcelVersion.Version2010);
问题修复:
Spire.Presentation for Java 10.7.1 现已发布,该版本修复了拆分PPT文档时程序抛错的问题。具体信息如下。
问题修复:
Spire.PDF for C++ 11.7.0 现已正式发布。该版本升级依赖的SkiaSharp版本并修复了两个在转换OFD到PDF和获取字体属性时出现的问题。详情请查阅以下内容。
调整:
问题修复: