1
我想用itextsharp在現有的pdf中添加一個按鈕。我找到了添加文本字段的示例,但我無法獲得任何示例在pdf文件的特定位置添加按鈕。使用iTextSharp在pdf文件中添加按鈕
我想用itextsharp在現有的pdf中添加一個按鈕。我找到了添加文本字段的示例,但我無法獲得任何示例在pdf文件的特定位置添加按鈕。使用iTextSharp在pdf文件中添加按鈕
使用PdfStamper將PushbuttonField添加到現有PDF。指定頁面上的位置,字段的名稱和頁碼。
static void AddPushbuttonField(string inputFile, iTextSharp.text.Rectangle buttonPosition, string buttonName, string outputFile)
{
using (PdfStamper stamper = new PdfStamper(new PdfReader(inputFile), File.Create(outputFile)))
{
PushbuttonField buttonField = new PushbuttonField(stamper.Writer, buttonPosition, buttonName);
stamper.AddAnnotation(buttonField.Field, 1);
stamper.Close();
}
}
您還應該看看iText in Action。 Chapter 8有創建按鈕字段的例子和許多您可以設置的不同屬性。