-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi friends!
I have a doubt and I want to share it with all of you.
I would like to print a document directly. I dont want to show the document content in a PDF or any other viewer. I just want to print using a button. Is it possible?
Hi, scerro
you can call the javascript's API like this
For ZK5
<button label="print" xmlns:w="http://www.zkoss.org/2005/zk/client" w:onClick="window.print();"/>
thank you for your answer as1225,
but I dont really want to print the window I am showing. I just want to print a document that is located into the database or in a server folder but I would like do it without show the document at all.
thanks
Could you tall me what type of the document you want to print ?
txt, doc, xls or zul?
I want to print PDF, DOC, Excel, CSV, TXT...
Hi,
first of all you can't bypass the print dialog:
http://stackoverflow.com/questions/945691/automatically-print-image-from-website
Via the print dialog you can only print content which is supported directly by the browser. Without any special browser-plugins this is just good old HTML and images.
Cheers, Maik
As Maik wrote, PDF, DOC & Co. is done by a browser-plugin (if there is one installed).
In my projects i create a print-preview-page with automatic print(dialog) and close. [1]
I've not tested this trick (for hide printing), but this sounds good:
Create your print area is a 1x1 iframe inside your side.
print the iframe (which is invisible for the use)
However printing xls, pdf is difficult inside html and depends on the plugins. I've seen a resolution working with javaapplets.
This works, but requires the installed Java-Plugin.
/Robert
[1] See here.
- press "Anonym" (no login)
- press "the Preise / Kalkulation" icon in the upper/right corner
- press the "Drucken" button
--> the print dialog open, after print the previewpage will be closed
Here the code using an own printwindow:
The mainfunction, code when print button is clicked:
..
// open print.zul in a new window public void onPrint(Event event) { StringBuffer sb = new StringBuffer(); sb.append("print.zul?id="); sb.append(model.getPlanung().getId()); sb.append("&kid="); sb.append(model.getPlanung().getKunde().getId()); sb.append("&rab="); sb.append(model.getPlanung().getRabatt()); sb.append("&netto="); sb.append(true); System.out.println("Url " + sb.toString()); Executions.getCurrent().sendRedirect(sb.toString(), "Print Window"); } ..
The PrintController (print.zul: ...<window id="printWin" apply="${printController}"----)
@Repository("printController") @Scope("prototype") public class PrintController extends GenericForwardComposer { private static final long serialVersionUID = -7456868519044922719L; private AnnotateDataBinder binder; ... @Autowired LoginData loginData; @Override public void doAfterCompose(Component _win) throws Exception { super.doAfterCompose(_win); binder = new AnnotateDataBinder(_win); binder.bindBean("controller", this); checkParms(); // parse url load(); // load the plan binder.loadAll(); // load UI (databinding) Clients.print(); // fire the printdialog Clients.evalJavaScript("window.close()"); // close the printwindow }
If i found some time, i try the iframe-variant. This shoudl really an invisible solution:
inside the main.zul
<iframe id="printarea" width="1px" height="1px"/>
and instead of:
Executions.getCurrent().sendRedirect(sb.toString(), "Print Window");
-->
printarea.setSrc(sb.toString());
/Robert
Hi guys I'm new to the zk and I'm kinda lost
I found it very interesting project robertpic71 only
I did not understand what he did.
Could someone explain to me how it's done printing through the browser? If someone can get me a code or project, so I can understand, can be small examples how to print an image.
Thanks guys
Asked: 2010-03-10 04:10:10 +0800
Seen: 3,714 times
Last updated: Aug 05 '11