标签:form C# Aspose 展平 Pdf PDF NET
当您想将 PDF 表单字段与 .NET 应用程序中的内容合并,因此这些字段不可编辑时,您想知道如何在 C# 代码中拼合 PDF 表单字段?Aspose.PDF for .NET API用几行代码帮助回答这个问题。
使用此 .NET API,可以一次展平基于 acroform 的PDF、所有表单字段或选择特定字段以在您的 C# 应用程序中展平。ASP.NET Web 应用程序、Windows 桌面应用程序或其他 .NET 平台的代码相同。
Aspose.PDF for .NET是用于.NET Core的高级PDF处理API,可以在跨平台应用程序中轻松生成,修改,转换,呈现,保护和打印文档。无需使用Adobe Acrobat。(下载Aspose.PDF安装包)
在 C# 中展平 PDF 表单字段的步骤
- 为 .NET NuGet 包安装Aspose.PDF
- 包括Aspose.PDF和Aspose.PDF.Facades命名空间
- 使用许可证类设置 Aspose 许可证
- 创建 Form 类的实例
- 绑定要拼合的 PDF 文件
- 使用FlattenAllField 方法合并所有表单域
- 使用 FlattenField 方法展平特定字段
- 最后,保存拼合后的输出PDF文件
在 C# 中展平 PDF 表单字段的代码
代码如下:
using System; //Add Aspose.Pdf for .NET package reference //Use following namespaces to flatten PDF form Fields using Aspose.Pdf; using Aspose.Pdf.Facades; namespace FlattenPDFFormFields { class Program { static void Main(string[] args) { //Set Aspose license before flattening PDF form fields //with the help of Aspose.Pdf for .NET Aspose.Pdf.License AsposePDFLicense = new Aspose.Pdf.License(); AsposePDFLicense.SetLicense(@"c:\asposelicense\license.lic"); //create an object of Form class to initiate form field flattening Form PDFFormToBeFlattened = new Form(); //Bind the PDF file which contains the form fields to be flattened PDFFormToBeFlattened.BindPdf("SamplePDFFormwithFields.pdf"); //Use FlattenAllFields method to flatten all of the fields in the //PDF form loaded above PDFFormToBeFlattened.FlattenAllFields(); //Save output PDF file with form fields flattened using Save method //of Form object PDFFormToBeFlattened.Save("OutputPDFwithFlattenedFormFields.pdf"); } } }
以下 C# 示例使用 FlattenField 方法将特定字段与 PDF 文件合并。通过提供字段名称作为参数,您可以使用此方法展平任意数量的字段。
在 C# 中展平单个 PDF 表单字段的代码
using System; //Add Aspose.Pdf for .NET package reference //Use following namespaces to flatten PDF form Fields using Aspose.Pdf; using Aspose.Pdf.Facades; namespace FlattenPDFFormFields { class Program { static void Main(string[] args) { //Set Aspose license before flattening PDF form fields //with the help of Aspose.Pdf for .NET Aspose.Pdf.License AsposePDFLicense = new Aspose.Pdf.License(); AsposePDFLicense.SetLicense(@"c:\asposelicense\license.lic"); //create an object of Form class to initiate form field flattening Form PDFFormToBeFlattened = new Form(); //Bind the PDF file which contains the form fields to be flattened PDFFormToBeFlattened.BindPdf("SamplePDFFormwithFields.pdf"); //Use FlattenField method and specify the name of the particular field //when flattening only a single form field PDFFormToBeFlattened.FlattenField("TextFormField"); //Save output PDF file with form fields flattened using Save method //of Form object PDFFormToBeFlattened.Save("OutputPDFwithFlattenedFormFields.pdf"); } } }
请注意,在 C# 中拼合 PDF 表单字段时,您不需要Adobe Acrobat或任何其他 PDF 编辑软件。此 API 包含在 .NET 中以编程方式展平 pdf 所需的一切。
如果您仍然不清楚如何在 C# 中展平 PDF 表单字段, 可加入Aspose资源分享交流群(761297826)。
标签:form,C#,Aspose,展平,Pdf,PDF,NET 来源: https://blog.csdn.net/mnrssj/article/details/118894177
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。