• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: Printing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Printing


  • Subject: RE: Printing
  • From: "Pierre Bernard" <email@hidden>
  • Date: Wed, 5 Feb 2003 09:16:45 +0100
  • Thread-topic: Printing

Simple, direct, on the verge of ugly. The below code more or less prints a screenshot of the current window:

public class ClientApplication
	extends EODynamicApplication
{

	// Public instance methods

	/** Most BASIC printing code.<BR>
	  *
	  * This is a simple attempt to do a print-screen like dump of the active window. No pagination, nothing fancy.
	  * Moreover this code is completely untested as running it requires more priviledges than we can get with an unsigned JAR.
	**/
	public void printActiveWindow()
		throws PrinterException
	{
		PageFormat pageFormat;
		PrinterJob printJob = PrinterJob.getPrinterJob();

		printJob.setPrintable(new Printable()
		{
			public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
				throws PrinterException
			{
				if (pageIndex > 0)
				{
					return Printable.NO_SUCH_PAGE;
				}
				else
				{
					Graphics2D graphics2d = (Graphics2D) graphics;
					graphics2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());

					activeWindow().paint(graphics2d);

					return Printable.PAGE_EXISTS;
				}
			}
		});

		pageFormat = printJob.pageDialog(printJob.defaultPage());

		if (printJob.printDialog())
		{
			printJob.print();
		}
	}

	public boolean canPerformActionNamed(String actionName)
	{
		if ("printActiveWindow".equals(actionName))
			return (activeWindow() != null);

		return super.canPerformActionNamed(actionName);
	}


	// Protected instance methods

	protected Component activeWindow()
	{
		EOWindowObserver windowObserver = windowObserver();

		return (Component) ((windowObserver == null) ? null : windowObserver.activeWindow());
	}

}

You also need an AdditionalActions WOComponent with the following HTML:

<APPLICATIONACTION actionName="printActiveWindow" categoryPriority="100" actionPriority="335" menuAccelerator="P" descriptionPath="Document/Print"/>

and a rule to activate the additional action:

        {
            author = 50;
            class = com.webobjects.directtoweb.Rule;
            rhs = {
                class = com.webobjects.directtoweb.Assignment;
                keyPath = additionalActions;
                value = AdditionalActions;
            };
        }

Moreover you need full privileges to the client machine.

Pierre.

-----Original Message-----
From: John Cassidy [mailto:email@hidden]
Sent: Tuesday, February 04, 2003 8:38 PM
To: email@hidden
Subject: Printing


Does anyone know a simple way to print from a direct to java app?  Thanks.

John





_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8.
http://join.msn.com/?page=features/junkmail
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.


**********************************************************************
This email and any files transmitted with it are intended solely for
the use of the individual or entity to whom they are addressed.
If you have received this email in error please notify the sender
of this message. (email@hidden)
This email message has been checked for the presence of computer
viruses; however this protection does not ensure this message is
virus free.
Banque centrale du Luxembourg; Tel ++352-4774-1; http://www.bcl.lu
**********************************************************************
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Printing
  • Next by Date: Postgresql and NSTimestamp
  • Previous by thread: Printing
  • Next by thread: Postgresql and NSTimestamp
  • Index(es):
    • Date
    • Thread