user1838130
user1838130

Reputation: 51

Creating a button on an existing pdf using itext sharp

I have been trying for long but no success i have an existing pdf that i wan to load to my current C# app and want to create a simpe pusbutton to it , plaese cite some working code the default directory of the pdf is "C:\abc.pdf".

I am using itextsharp, C# VS 2010 Thanks

Upvotes: 1

Views: 1093

Answers (2)

Chirag patel
Chirag patel

Reputation: 1

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;

Upvotes: 0

Jammin411
Jammin411

Reputation: 418

The closest solution I can find is something like the following.

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

This came from here, but was not ranked up as a solution. The code looks good and based on my experience with itextsharp I think this will do the trick.

Source: Adding button in a pdf file using iTextSharp

Upvotes: 1

Related Questions