本基本教程通过提供配置步骤和可运行的示例代码,指导如何使用 C#** 将 PDF 转换为 CSV。它描述了如何使用 C# PDF 到 CSV 转换,方法是加载源 PDF,然后以 CSV 格式设置输出 Excel 文件的参数。配置完成后,从 PDF 生成 CSV 文件并保存在磁盘上。
使用 C# 将 PDF 转换为 CSV 的步骤
- 在您的项目中添加对 Aspose.PDF 的引用以将 PDF 转换为 CSV
- 将源 PDF 文件加载到 Document 类对象中以转换为 CSV
- 实例化 ExcelSaveOptions 类对象以定义输出文件格式和其他参数
- 使用所需配置将输入 PDF 保存为 CSV 文件
这些步骤通过将所需的库添加到项目中来提供有关项目配置的信息。在下一步中,源 PDF 文件被加载到文档类对象中,但是也可以使用许多其他格式。最后,输出文件可以保存为 CSV 或其他 MS Excel 支持的格式。
使用 C# 将 PDF 转换为 CSV 的代码
using Aspose.Pdf; | |
namespace ConvertPdfToCsvUsingCSharp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// Instantiate the license to avoid trial limitations while converting the PDF to CSV | |
License asposePdfLicense = new License(); | |
asposePdfLicense.SetLicense("Aspose.pdf.lic"); | |
// Load PDF document that is to be converted to Excel format | |
Document pdfDocumentToCsv = new Document("input.pdf"); | |
// Instantiate ExcelSaveOptions class object to define the output file format | |
ExcelSaveOptions excelSave = new ExcelSaveOptions { Format = ExcelSaveOptions.ExcelFormat.CSV }; | |
// Save the output file to CSV format | |
pdfDocumentToCsv.Save("PDFToCSV_out.csv", excelSave); | |
System.Console.WriteLine("Done"); | |
} | |
} | |
} |
此处使用 * 将 PDF 转换为 CSV C# 代码*,它使用 Document 类对象从磁盘加载源 PDF 文件,但也可以从流中加载。使用相应的 LoadOptions 类,支持将文件加载到 Document 类(如 CGM、HTML、EPUB、XML 等)中的许多其他格式。同样,您可以通过最小化工作表的数量、设置统一的工作表、首先插入空白列,甚至将输出格式设置为 XLSX、XLSM、ODS、XMLSpreadSheet2003 而不是 CSV 来配置输出 Excel 文件。
在本文中,我们学习了如何使用 C# 将 PDF 转换为 CSV。如果你想学习 PDF 到图像的转换,请参考 如何在 C# 中将 PDF 转换为图像 上的文章。