PDF hostContainer回调 [英] PDF hostContainer callback

查看:282
本文介绍了PDF hostContainer回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此之后做方案<一href="http://stackoverflow.com/questions/5934211/getting-notified-when-the-user-clicks-a-link-in-an-embedded-pdf">here通知在PDF文档中点击事件的客户,怎么可能通知客户端时的PDF使用this.myPDF.submitForm被提交由客户端(本地主机/ Handler.ashx?R = 2)功能?

Following this SO solution here to notify clients of a click event in a PDF document, how is it possible to notify the client when the PDF gets submitted by the client using this.myPDF.submitForm("localhost/Handler.ashx?r=2) function?

PDF文件中的用户控件,然后渲染成HTML对象内部创建的:

The PDF File is created inside a user control then rendered into a HTML object:

string container = ("<object data='/myfile.pdf' type='application/pdf'></object>");

连接到PDF的JS文件是这样做的:

The JS file attached to the PDF is done like this:

 var webClient = new WebClient();
 string htmlContent = webClient.DownloadString(fileurl + "pdf_script.js");
 PdfAction action = PdfAction.JavaScript(htmlContnent, pdfstamper.Writer);
 pdfstamper.Writer.SetOpenAction(action);

和JS文件的内容:

this.disclosed = true;
if (this.external && this.hostContainer) {

function onMessageFunc(stringArray) {
     try {
          this.myPDF.submitForm("http://localhost/Handler.ashx?EmpNo=12345" + "#FDF", false);

        }
        catch (e) {

        }
    }
    function onErrorFunc(e) {
        console.show();
        console.println(e.toString());
    }
    try {
        if (!this.hostContainer.messageHandler);
        this.hostContainer.messageHandler = new Object();
        this.hostContainer.messageHandler.myPDF = this;
        this.hostContainer.messageHandler.onMessage = onMessageFunc;
        this.hostContainer.messageHandler.onError = onErrorFunc;
        this.hostContainer.messageHandler.onDisclose = function () { return true; };
    }
    catch (e) {
        onErrorFunc(e);
    }
}

在submitForm调用时的PDF内容(表单域)通过执行此操作获得成功保存和警报显示在PDF:

When the submitForm call is made the PDF contents (form fields) get saved successfully and an alert is displayed in the PDF by doing this:

message = "%FDF-1.2
                   1 0 obj
                   <<
                   /FDF
                   <<
                      /Status("Success!")
                   >>
                   >>
                   endobj
                   trailer
                   <</Root 1 0 R>>
           %%EOF");
return message;

我试图做的是获得的PDF表单提交调用此客户端发送后回调的客户端,这是一种认识的客户端表单已经提交,而不是在一个警报的形式,而是,一个方法来触发主机中的功能(该容器,的iframe,对象...等)。

What I'm trying to do is to get the PDF to callback the client after the form submit call sent from this client, a way to acknowledge the client that the form has been submitted, not in a form of an alert, but rather, a way to trigger a function in the host (the container, an iframe, object...etc).

推荐答案

您使用的FDF反应是未知的我,所以我已经学到新的东西从你的问题。我研究了AcroJS参考和FDF规范的PDF参考,现在我有一个更好的了解你的code一样。谢谢你。

The FDF response you used was unknown to me, so I've learned something new from your question. I've studied the AcroJS Reference and the FDF specification in the PDF Reference, and now I have a better understanding of what your code does. Thank you for that.

我假设你已经知道如何使用从PDF的JavaScript调用来触发在HTML文件中的JavaScript消息。请参阅 createMessageHandler()的<一个href="http://www.javabeat.net/2011/04/javascript-communication-between-html-and-pdf-in-itext/">JavaScript HTML和PDF 文章之间的通信。

I assume that you already know how to trigger a JavaScript message in an HTML file using a JavaScript call from a PDF. See the createMessageHandler() in the JavaScript Communication between HTML and PDF article.

我除preT你的问题如下:?如何我调用成功提交的数据后,此方法

I interpret your question as: "How to I invoke this method after a successful submission of the data?"

如果有一个解决这个问题的,它会涉及到的JavaScript。我看到,人们可以在FDF文件添加JavaScript,但我不知道如果JavaScript可以说话的HTML。我不知道,如果你可以在你的FDF响应初始PDF调用JavaScript函数。如果有可能,你应该一个JavaScript项添加到您的PDF类似/状态条目。

If there's a solution to this question, it will involve JavaScript. I see that one can add JavaScript in an FDF file, but I'm not sure if that JavaScript can 'talk to' HTML. I'm not sure if you can call a JavaScript function in your initial PDF from the FDF response. If it's possible, you should add a JavaScript entry to your PDF similar to the /Status entry.

本项的值是一个字典,是这样的:

The value of this entry is a dictionary, something like:

<<
/Before (app.alert\("before!"\))
/After (app.alert\("after"\))
/Doc [/MyDocScript1, (myFunc1\(\)),
      /MyDocScript2, (myFunc2\(\))
>>

在你的情况,我会删除/前后/文件键。我不认为你需要的时候,我会减​​少字典:

In your case, I would remove the /Before and /Doc keys. I don't think you need them, I'd reduce the dictionary to:

<<
/After (talkToHtml\(\))
>>

其中, talkToHtml()是一个方法已经present在PDF:

Where talkToHtml() is a method already present in the PDF:

function talkToHtml() {
    var names = new Array();
    names[0] = "Success!";
    try{
        this.hostContainer.postMessage(names);
    }
    catch(e){
        app.alert(e.message);
    }
}

我不知道这是否会工作。我从来没有尝试过自己。我基础上的规范我的答案。

I don't know if this will work. I've never tried it myself. I'm basing my answer on the specs.

我不知道你是否真的需要使用FDF。您是否尝试添加JavaScript到你的submitForm()方法?是这样的:

I don't know if you really need to use FDF. Have you tried adding JavaScript to your submitForm() method? Something like:

this.myPDF.submitForm({
    cURL: "http://localhost/Handler.ashx?EmpNo=12345",
    cSubmitAs: "FDF",
    oJavaScript: {
        Before: 'app.alert("before!")',
        After: 'app.alert("after")',
        Doc: ["MyDocScript1", "myFunc1()",
              "MyDocScript2", "myFunc2()" ]
    }
});

如果您提交的FDF这仅仅工作。我不认为有一个解决方案,如果你提交一个HTML查询字符串。

This will only work if you submit as FDF. I don't think there's a solution if you submit an HTML query string.

如果你想知道什么 MyDocScript1 MyDocScript2 是:

In case you're wondering what MyDocScript1 and MyDocScript2 are:

文档定义的数组定义额外的JavaScript脚本能   加入到那些在文档的名称的JavaScript的条目定义   字典。该数组包含偶数的元素,组织   成对。每对的第一个元素是一个名称和所述第二   是一个文本字符串或文本流定义相应的脚本   该名称。每个所定义的脚本将被添加到那些已经   在名字典定义,那么脚本之前执行   在进入之前定义的执行。 (ISO-32000-1表245)

Doc defines an array defining additional JavaScript scripts to be added to those defined in the JavaScript entry of the document’s name dictionary. The array contains an even number of elements, organized in pairs. The first element of each pair is a name and the second is a text string or text stream defining the script corresponding to that name. Each of the defined scripts is added to those already defined in the name dictionary and then executed before the script defined in the Before entry is executed. (ISO-32000-1 Table 245)

我不知道,如果这一切都将在实际工作中。请让我知道,无论哪种方式。

I'm not sure if all of this will work in practice. Please let me know either way.

这篇关于PDF hostContainer回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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