使用动态网址打印到Google云打印 [英] Print to Google Cloud Print with dynamic URL

查看:105
本文介绍了使用动态网址打印到Google云打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网站上使用打印按钮来打印带有Google云打印的文档,但我希望目标的网址 - PDF文件 - 在按钮被删除后动态更改点击(特别是根据AJAX调用返回的内容)。

I'd like a "print" button on my web-site to print a document with Google Cloud Print, but I want the "url" of the target – a PDF file – to change dynamically, after the button has been clicked (notably, based on what's returned from an AJAX call).

GCP Web元素(GCPWE)似乎具有类似的功能,但不是我想要的。特别是,似乎只能在单击按钮之前更改目标(通过调用 setPrintDocument )。

The GCP Web Element (GCPWE) seems to have similar functionality, but not quite what I desire. In particular, it seems as though one can only change the "target" (by calling setPrintDocument) before the button is clicked.

点击按钮后有没有办法指定GCPWE的URL?

Is there a way to specify the URL for GCPWE after the button has been clicked?

以下是GCPWE网站的示例代码:

Here's the example code from the GCPWE site:

<div id="print_button_container"> </div>


<script src="http://www.google.com/cloudprint/client/cpgadget.js">
</script>
<script defer="defer">
    var gadget = new cloudprint.Gadget();
    gadget.setPrintButton(
          cloudprint.Gadget.createDefaultPrintButton("print_button_container"));
    gadget.setPrintDocument("url", "[document title]", "[document URL]");
</script>

我考虑隐藏< div id ='print_button_container'> ; 并在点击可见的打印按钮后触发 .click 事件,但这似乎相当不优雅&不当。我已经查看了上面链接的 gpwidget.js ,但是代码已经被最小化并且无法理解(对我来说,无论如何)。

I've considered hiding the <div id='print_button_container'> and triggering a .click event on it after a visible print button has been clicked, but this seems rather inelegant & improper. I've looked at the gpwidget.js linked to above, but the code has been minimized and is unintelligible (to me, at any rate).

我想要的是一个Javascript print 函数,您传递了[文档URL]和[文档标题]到。

What I seem to desire is a Javascript print function that you pass a [document URL] and [document title] to.

有没有更好的方法来实现所需的功能,而不是点击隐藏的按钮我想出了什么?

Is there a better way to achieve the desired functionality, rather than the 'clicking the hidden button' I've come up with?

感谢您阅读。

推荐答案

您可以随时打开打印对话框,只需致电:

You can open print dialog whenever you want that, just call:

gadget.openPrintDialog()

,这将打开打印机对话框。
因此,对于您的情况,您可能希望使用静态方法创建打印按钮:

and that will open printer dialog. So for your case you might want to create print button using static method:

cloudprint.Gadget.createDefaultPrintButton("print_button_container");

然后附上按钮的自定义处理程序,无论何时准备好,只需致电:

then attach custom handlers for the button, and whenever you are ready just call:

var gadget = new cloudprint.Gadget();
gadget.setPrintDocument(...);
gadget.openPrintDialog();

这篇关于使用动态网址打印到Google云打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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