如何用itextsharp更改PDF Formular的Button图标? [英] How to change a Button Icon of a PDF Formular with itextsharp?

查看:243
本文介绍了如何用itextsharp更改PDF Formular的Button图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用itextsharp填写预定义的表单。一切都很好,除了添加图像。之前已经使用了Adobe的FDF工具包,该工具包已编译成.NET 1.1。这不再适用于.NET 4.0,我切换到了itextsharp。
之前添加图像的方式是通过更改预定义表单中按钮的图标。这正确地旋转和缩放图像。不幸的是,我找不到任何使用itextsharp执行此操作的方法。
代码为:

I'am currently trying to fill out a predefined Form with itextsharp. All works well except adding an image. This worked already before with the FDF toolkit from Adobe, which was compiled into .NET 1.1. This isn't working with .NET 4.0 anymore and I switched to itextsharp. The way the image was added previously was by changing the icon of a button in a predefined form. That rotateted and scaled the image correctly. Unfortunatly I couldn't find any Method to do this with itextsharp. The code was:

FdfAcX_Doc.FDFSetAP("img", 0, "path\\to\\img.pdf", 1);

(Doc: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/FDFtkRef.pdf

现在我正在尝试使用itextsharp并尝试手动添加图像,例如:

Now I was experimenting with itextsharp and trying to add the image manually, e.g.:

PdfContentByte pdfContentByte = pdfStamper.GetOverContent(1);
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(picfile);
iTextSharp.text.Rectangle imageRect = new iTextSharp.text.Rectangle(338f, 65f, 250f, 200f, 270);
img.ScaleToFit(imageRect.Width, imageRect.Height);
img.SetAbsolutePosition(65, 250);
pdfContentByte.AddImage(img);

但不幸的是,首先图像没有正确旋转,其次图像太大了。我尝试了几个设置,但无法找到正确的设置。有没有人知道我做错了什么?

But unfortunatly firstly the image is not rotated corretly and secondly the image is way too big. I tried several settings but couldn't hit the correct one. Does anyone have an idea what I'm doing wrong?

PDF表格可以在这里下载: http://www26.zippyshare.com/v/24914063/file.html

PDF Form can be downloaded here: http://www26.zippyshare.com/v/24914063/file.html

请帮助,我一直在这个问题上坐了一天,想不出更多。
谢谢!

Please help, I've been sitting at this problem for a day now and can't think of anything more. Thanks!

推荐答案

您的代码示例与标题中的问题不一致。

Your code sample isn't consistent with the question in the title.

在您的代码示例中,您将图像添加到页面内容中。在标题中,您要求替换按钮字段中的图标。按钮字段不是内容的一部分。它们使用小部件注释进行可视化。

In your code sample, you're adding an image to the content of a page. In your title, you're asking to replace the icon in a button field. Button fields aren't part of the content. They are visualized using widget annotations.

我希望代码看起来像这样:

I would have expected code that looks like this:

AcroFields form = stamper.AcroFields;
PushbuttonField ad = form.GetNewPushbuttonFromField(buttonFieldName);
ad.Layout = PushbuttonField.LAYOUT_ICON_ONLY;
ad.ProportionalIcon = true;
ad.Image = Image.GetInstance(pathToNewImage);
form.ReplacePushbuttonField("advertisement", ad.Field);

这篇关于如何用itextsharp更改PDF Formular的Button图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆