我一直在努力,但没有成功我有一个现有的PDF,我要加载到我当前的C#应用程序,并且想要创建一个simpe按钮给它,plaese引用了一些工作代码pdf的默认目录是“C:\ abc.pdf”。使用itext创建现有pdf上的按钮sharp
我使用iTextSharp的,C#VS 2010 感谢
我一直在努力,但没有成功我有一个现有的PDF,我要加载到我当前的C#应用程序,并且想要创建一个simpe按钮给它,plaese引用了一些工作代码pdf的默认目录是“C:\ abc.pdf”。使用itext创建现有pdf上的按钮sharp
我使用iTextSharp的,C#VS 2010 感谢
最接近的解决方案,我能找到的是类似于下面的东西。
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的经验,我认为这会做到这一点。
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;
请更多信息编辑。代码只和“试试这个”答案都望而却步,因为它们不包含搜索的内容,并没有解释为什么有人要“试试这个”。我们在这里努力成为知识的资源。 –