iTextSharp按钮字段的多个动作 [英] iTextSharp multiple actions for pushbuttonfield
问题描述
在PDF中,我可以设置一个按钮
In a PDF, I can set up a button to
- 将FDF数据提交给我的RestAPI
- 重定向到网页(告诉用户'谢谢')并且效果很好。
但我需要这样做使用代码......我使用以下方式使用iTextSharp:
But I need to do this using code... I am using iTextSharp in the following way:
-
pb
是我的按钮... -
sURL
是我需要数据去的网址...
pb
is my pushbutton...sURL
is the URL I need the data to go to...
这是我的代码:
PdfFormField pff = pb.Field;
pff.SetAdditionalActions(PdfName.A, PdfAction.CreateSubmitForm(sURL, null, PdfAction.SUBMIT_XFDF));
af.ReplacePushbuttonField("submit", pff);
这确实用提交操作替换了按钮。如何保持页面重定向或如何在代码中设置?
我也尝试过基于示例的 PdfName.AA
和 PdfName.U
我不确定是什么不同的名字是为了。但没有任何作用。 : - /
This does replace the button with the submit action. How do I keep the page redirect or how do I set it in code?
I have also tried PdfName.AA
and PdfName.U
based on examples and I am not certain what the different names are for. But nothing works. :-/
显然, SetAdditionalActions()
会替换现有的操作。
Apparently, the SetAdditionalActions()
replaces the existing actions.
我也尝试过使用注释,只添加一个不存在的按钮。
I have also tried using annotations and just adding a button that doesn't exist.
推荐答案
你正在寻找一个名为链式动作的概念,如 PrintTimeTable 示例:
You are looking for a concept called chained actions as demonstrated in the PrintTimeTable example:
Chunk chunk = new Chunk("print this page");
PdfAction action = PdfAction.javaScript(
"app.alert('Think before you print!');", stamper.getWriter());
action.next(PdfAction.javaScript(
"printCurrentPage(this.pageNum);", stamper.getWriter()));
action.next(new PdfAction("http://www.panda.org/savepaper/"));
chunk.setAction(action);
在这种情况下,我们有一个动作,显示警告,打印页面并重定向到URL 。这些操作使用 next()
方法相互链接。
In this case, we have an action that shows an alert, prints a page and redirects to an URL. These actions are chained to each other using the next()
method.
在C#中,这将是:
Chunk chunk = new Chunk("print this page");
PdfAction action = PdfAction.JavaScript("app.alert('Think before you print!');", stamper.Writer);
action.Next(PdfAction.JavaScript("printCurrentPage(this.pageNum);", stamper.Writer));
action.Next(new PdfAction("http://www.panda.org/savepaper/"));
chunk.SetAction(action);
另见图书示例的C#端口。
这篇关于iTextSharp按钮字段的多个动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!