翻譯|使用教程|編輯:李顯亮|2021-07-16 09:49:39.447|閱讀 203 次
概述:當想將 PDF 表單字段與 .NET 應用程序中的內容合并,因此這些字段不可編輯時,您想知道如何在 C# 代碼中拼合 PDF 表單字段?Aspose.PDF for .NET API用幾行代碼幫助回答這個問題。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
當您想將 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 for .NET開發者指南》獲取更多幫助。
代碼如下:
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 文件合并。通過提供字段名稱作為參數,您可以使用此方法展平任意數量的字段。
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.Words 免費支持論壇中提問哦 。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn