0

Print documents without show the content

asked 2010-03-10 04:10:10 +0800

scerro gravatar image scerro
273 3 9
www.desarrolloagil.es

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?

delete flag offensive retag edit

13 Replies

Sort by ยป oldest newest

answered 2010-03-10 19:07:49 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

updated 2010-03-10 19:08:05 +0800

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();"/>

link publish delete flag offensive edit

answered 2010-03-11 01:06:52 +0800

scerro gravatar image scerro
273 3 9
www.desarrolloagil.es

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

link publish delete flag offensive edit

answered 2010-03-11 19:17:59 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Could you tall me what type of the document you want to print ?
txt, doc, xls or zul?

link publish delete flag offensive edit

answered 2010-03-12 01:43:55 +0800

scerro gravatar image scerro
273 3 9
www.desarrolloagil.es

I want to print PDF, DOC, Excel, CSV, TXT...

link publish delete flag offensive edit

answered 2010-03-12 03:26:16 +0800

mjablonski gravatar image mjablonski
1284 3 5
http://www.jease.org/

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

link publish delete flag offensive edit

answered 2010-03-12 08:35:21 +0800

robertpic71 gravatar image robertpic71
1275 1

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

link publish delete flag offensive edit

answered 2010-12-15 21:46:45 +0800

dara gravatar image dara
3

hi Robert,

could you please give us the code?
thanks in advance

dara

link publish delete flag offensive edit

answered 2010-12-16 05:13:29 +0800

robertpic71 gravatar image robertpic71
1275 1

updated 2010-12-16 05:15:39 +0800

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

link publish delete flag offensive edit

answered 2011-07-07 16:53:41 +0800

luisfernando gravatar image luisfernando
15

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

link publish delete flag offensive edit

answered 2011-07-08 08:07:11 +0800

luisfernando gravatar image luisfernando
15

Help me guys!

Thanks

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-03-10 04:10:10 +0800

Seen: 3,707 times

Last updated: Aug 05 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More