Aspose.PDF for .NET是一种高PDF处理和解析API,用于在跨平台应用程序中执行文档管理和操作任务。API可以轻松用于生成、修改、转换、渲染、保护和打印PDF文档,而无需使用AdobeAcrobat。此外,API还提供PDF压缩选项,表格创建和操作,图形和图像功能,广泛的超链接功能,印章和水印任务,扩展的安全控制和自定义字体处理。
>>Aspose.PDF for .NET更新至最新版v20.1,欢迎下载体验。
▲将PDF转换为DOC
Aspose.PDF for .NET允许使用两行代码将源PDF文件转换为DOC文件。为了实现此功能,引入了一个名为的枚举SaveFormat ,从而可以将源文件保存为Microsoft Word格式。以下代码段显示了将PDF文件转换为DOC的过程。
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET// The path to the documents directory.string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion(); // Open the source PDF documentDocument pdfDocument = new Document(dataDir + "PDFToDOC.pdf");// Save the file into MS document formatpdfDocument.Save(dataDir + "PDFToDOC_out.doc", SaveFormat.Doc);
DocSaveOptions类提供了完善的PDF文件转换成DOC格式的过程中众多特性。在这些属性中,Mode可以指定PDF内容的识别模式。从而可以从RecognitionMode枚举中为此属性指定任何值。这些值均具有特定的优点和局限性:
- 该 RelativeHorizontalProximity 属性可用于控制文本元素之间的相对接近度,并且意味着距离由字体大小确定。较大的字体在音节之间的距离可能更大,但仍视为一个整体。它指定为字体大小的百分比,例如1 = 100%。这意味着相距12点的两个12pt字符在近端。
- RecognitionBullets 用于在转换期间打开项目符 的识别。
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET// The path to the documents directory.string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion(); // Open the source PDF documentDocument pdfDocument = new Document(dataDir + "PDFToDOC.pdf"); // Save using save options// Create DocSaveOptions objectDocSaveOptions saveOptions = new DocSaveOptions();// Set the recognition mode as FlowsaveOptions.Mode = DocSaveOptions.RecognitionMode.Flow;// Set the Horizontal proximity as 2.5saveOptions.RelativeHorizontalProximity = 2.5f;// Enable the value to recognize bullets during conversion processsaveOptions.RecognizeBullets = true;// Save the resultant DOC filepdfDocument.Save(dataDir + "saveOptionsOutput_out.doc", saveOptions);
▲将PDF转换为Word DOCX
Docx是Microsoft Word文档的一种众所周知的格式,其结构从纯二进制更改为XML和二进制文件的组合。 可以使用Word 2007和横向版本打开Docx文件,但不能使用支持DOC文件扩展名的早期版本的MS Word打开。
DocSaveOptions类具有一个名为Format的属性,该属性提供了指定结果文档格式(即DOC或DOCX)的功能。 为了将PDF文件转换为DOCX格式,请传递DocSaveOptions.DocFormat枚举中的Docx值。以下代码片段提供了将PDF文件转换为DOCX格式的功能。
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET// The path to the documents directory.string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();// Open the source PDF documentDocument pdfDocument = new Document(dataDir + "PDFToDOC.pdf");// Instantiate DocSaveOptions objectDocSaveOptions saveOptions = new DocSaveOptions();// Specify the output format as DOCXsaveOptions.Format = DocSaveOptions.DocFormat.DocX;// Save document in docx formatpdfDocument.Save("ConvertToDOCX_out.docx", saveOptions);
还想要更多吗可以点击阅读【2019 · Aspose最新资源整合】,查找需要的教程资源。如果您有任何疑问或需求,请随时联系客服,我们很高兴为您提供查询和咨询。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!