Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-11-2003, 04:26 PM   #1 (permalink)
laurence10
Registered User
 
Join Date: Mar 2003
Location: England
Posts: 1
laurence10 is on a distinguished road
Problem printing, please help me

Hello all,

I am having trouble printing I have spent just too long with this task now & I need to resolve it...therefore I was hoping that someone here could maybe help me?

The class is requested here:



if (event.getSource() == print)
{
printMenu = new printUtility(this.getGraphics(),theResult);
}
if (event.getSource() == newProfessional)



And then attempts to print the contents of the passed text area as below, the problem is that it starts up the dprint dialog :-) & even starts the printer :-) but sadly prints nothing :-(
Could anyone help me discover what I am doing wrong please?


import java.awt.*;
import java.awt.print.*;

public class printUtility implements Printable {
private Component componentToBePrinted; //holds the component for printing
private PrinterJob printJob;
Graphics printGraphics;

public printUtility(Graphics g, Component textArea)
{
printJob = PrinterJob.getPrinterJob();
printGraphics=g;
componentToBePrinted=textArea;
printJob.setPrintable(this);

if (printJob.printDialog())
try {
printJob.print();
} catch(PrinterException pe) {
System.out.println("Error printing: " + pe);
}
}

//print method of printable interface with arguments:
//graphics(the context that is used to write to the printer)
//pageformat(provides details of the page size, position & size of the printable area on screen & orientation)
//pageindex(carries an index value for the page 1stpage = 0, 2nd = 1 etc)
public int print(Graphics g, PageFormat pageFormat, int pageIndex)
{
if (pageIndex > 0)
{
return NO_SUCH_PAGE; //only want 2 print 1 page so if more return
} //NO_SUCH_PAGE to stop printing
else
{
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(Color.black);
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); //translate method moves the user
componentToBePrinted.paint(g2d); //coordinates so that 0,0 is
return PAGE_EXISTS; //positioned @ the top left corner
} //of the printable page
}
}
laurence10 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with editing profile cheawick Feedback 0 04-28-2004 10:26 PM
strange posting problem on my website......... trevor PHP 2 12-19-2003 12:25 PM
Help debugging a power problem Belisarius Lounge 0 10-25-2003 04:44 PM
This is a windows/C problem UnderWing Standard C, C++ 6 03-28-2003 06:17 AM


All times are GMT -8. The time now is 09:33 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting