Article View: es.comp.lenguajes.java
Article #29544Re: �Como imprimir una p�gina?
From: Monkiki
Date: Sat, 29 Nov 1997 00:00
Date: Sat, 29 Nov 1997 00:00
124 lines
5547 bytes
5547 bytes
>Hola, estoy intentando poner un bot�n en mi formulario que ponga
>imprimir y si lo pulsas que te imprima por la impresora el propio
>formulario, y adem�s que lo imprima relleno, como para tener un
>resguardo del formulario que acabas de rellenar �es posible hacer eso?
>Si asi es �como deber�a hacerlo? con html, con java, con perl???
Hola, bonita. Pues supongo que s�, que se puede, pero creo que la cosa es un poquit�n m�s compleja.
De todas formas te mando un poco de ayuda en forma de c�digo que imprime algo. Partiendo de ah�,
puedes llegar a lo que tu quieres. Si consigues algo potable, te ruego me lo comuniques. Yo, en
especial, tengo problemas al imprimir con un drawString(). Com�ntame tus impresiones ;-)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
T I P S , T E CH N I Q U E S , A N D S A M P L E C O D E
FOR PRINTING IN JAVA, TRY THIS. JDK(tm) 1.1 provides a standard way to
print and improves on JDK 1.0 printing.
You print via the Abstract Window Toolkit (AWT). A simple example for
printing a filled-in oval looks like this:
import java.awt.*;
public class print {
public static void main(String args[])
{
Frame f = new Frame("test");
f.pack();
PrintJob pj =
f.getToolkit().getPrintJob(f, "print1", null);
if (pj != null) {
Graphics g = pj.getGraphics();
g.fillOval(5, 5, 150, 100);
g.dispose();
pj.end();
}
System.exit(0);
}
}
This example is a standalone Java program that creates an AWT frame, a
top-level GUI component for running an application. The program next
retrieves the toolkit for the frame. The toolkit for the AWT is the
interface between the abstract window layer and an actual windowing
implementation such as Windows 95 or X Windows.
Once you create the toolkit, you can initiate a print job via getPrintJob,
which causes a window to pop up on the screen asking the user for
information about which printer is being used, the number of copies to
print, and so on. This process is similar to printing in conventional
Windows applications.
Given a PrintJob object, you can obtain a graphics context and draw to it.
Such drawing, using normal graphics primitives such as fillOval, goes to
the printer instead of the screen. Calling dispose on the graphics context
object sends the page to the printer, and the print job is terminated by
calling end.
If you're using your own custom AWT components, you can use the paint
methods you define for printing without change--by passing them the
graphics context returned by getGraphics. But if you want different
behavior when you print, specialized methods can also be defined for
components as necessary.
-- Printing from applets
The example given above is a standalone Java program. But what about
printing from applets? The Java security system contains a feature that may
lock out an applet from initiating its own print job, requiring that the
initiation be done via a Web browser or applet viewer. The security area is
in a state of flux at present, and your experiences with this process may
be different.
Finally, another less portable approach to printing text is to open the
special device file that represents the printer, and do conventional file
I/O to that file. For example, "lpt1" can be used for this purpose with
Windows systems, and "/dev/lp" can be used with UNIX.
-- COPYRIGHT --
Copyright Sun Microsystems, Inc. All rights reserved.
901 San Antonio Road, Palo Alto, California 94303 U.S.A.
This document is protected by copyright. You may make a reasonable number
of copies of this document for your own use, and you may distribute this
document, subject to the following conditions: (i) all text (including this
notice) must be copied without modification and all pages must be included;
and (ii) this document may not be distributed for commercial purposes.
Sun, the Sun logo, Sun Microsystems, Java, and all Java-related trademarks
are trademarks or registered trademarks of Sun Microsystems, Inc. in the
U.S. and other countries.
>�Que he de hacer? Necesito ayuda urgentemente.
>Gracias.
De nada.
>Un saludo.
Otro para ti.
Vis�tame en:
http://www.redestb.es/personal/quickly (La p�gina de Monkiki)
E mail:
quickly@mx3.redestb.es
"Baco, por siempre loado,
os libre del cirr�tico mal y
del advenimiento gonoc�cico".
Technical Details
Message-ID:
<347ead7e.470071@news.redestb.es>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<347C2BEA.82DB1BAB@mundivia.es>Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII X-Google-Thread: f4f4a,c0fbc59632e1f4e2 X-Google-Attributes: gidf4f4a,public X-Google-Thread: 1116f3,c0fbc59632e1f4e2 X-Google-Attributes: gid1116f3,public From: quickly@mx3.redestb.es (Monkiki) Subject: Re: �Como imprimir una p�gina? Date: 1997/11/29 Message-ID: <347ead7e.470071@news.redestb.es> X-Deja-AN: 293619728 References: <347C2BEA.82DB1BAB@mundivia.es> Reply-To: quickly@mx3.redestb.es Organization: Soy muy desorganizado Newsgroups: es.comp.lenguajes.java,alt.html