2012-11-24 40 views
1

我一直在努力,但沒有成功我有一個現有的PDF,我要加載到我當前的C#應用​​程序,並且想要創建一個simpe按鈕給它,plaese引用了一些工作代碼pdf的默認目錄是「C:\ abc.pdf」。使用itext創建現有pdf上的按鈕sharp

我使用iTextSharp的,C#VS 2010 感謝

回答

1

最接近的解決方案,我能找到的是類似於下面的東西。

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(); 
    } 
} 

這是來自這裏,但沒有被列爲解決方案。代碼看起來不錯,並基於我對itextsharp的經驗,我認爲這會做到這一點。

來源: Adding button in a pdf file using iTextSharp

0
Rectangle _rect; 
         _rect = new Rectangle(50, 100, 100, 100); 
         PushbuttonField button = new PushbuttonField(writer, _rect, "button"); 
         PdfAnnotation widget = button.Field; 
         button.BackgroundColor = new GrayColor(0.75f); 
         button.BorderColor = GrayColor.GRAYBLACK; 
         button.BorderWidth = 1; 
         button.BorderStyle = PdfBorderDictionary.STYLE_BEVELED; 
         button.TextColor = GrayColor.GRAYBLACK; 
         button.FontSize = 11; 
         button.Text = "Text"; 
         button.Layout = PushbuttonField.LAYOUT_ICON_LEFT_LABEL_RIGHT; 
         button.ScaleIcon = PushbuttonField.SCALE_ICON_ALWAYS; 
         button.ProportionalIcon = true; 
         button.IconHorizontalAdjustment = 0; 
+0

請更多信息編輯。代碼只和「試試這個」答案都望而卻步,因爲它們不包含搜索的內容,並沒有解釋爲什麼有人要「試試這個」。我們在這裏努力成爲知識的資源。 –