• Advertisement

Archived

This topic is now archived and is closed to further replies.

[java] Printing Graphics

This topic is 6304 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve searched all my books and came up with nothing on this. How can I print graphics from java? All I want to do it print boxes around pieces of text, but according to my books, I can only print text. Does anyone know, perhaps, a workaround for this? I was thinking about exporting the information to a file and writing a program in C++ to do the printing, but that''s not very conveniant to the user. E:cb woof!

Share this post


Link to post
Share on other sites
Advertisement
I don''t know how you are trying to print your document, so I can''t be of much help. Here is a link to the Javasoft Printing topics page. Maybe one of these references has your answer.

http://java.sun.com/printing/index.html

Share this post


Link to post
Share on other sites
I found some code that looks like what I need. However, I still get an error. The link I found is at: http://molsun.ophth.uiowa.edu/~tscheetz/java/awt/print-ex1.html.

Here it is:

public void print_hello()
{
PrintJob pjob;
Properties p = new Properties();
Graphics pgraphics;
String hello = new String("Hello World!");
String name = new String("Print Job Name");
int x, y;

pjob = getToolkit().getPrintJob(this, name, props);
if(pjob != null) {
pgraphics = pjob.getGraphics();
if(pgraphics != null) {
pgraphics.setFont(new Font("Serif",Font.PLAIN,14));
x = 50;
y = 50;
pgraphics.drawString(hello,x,y);
pgraphics.dispose();
}
pjob.end();
}

}

Now, most of this works. The only place I'm getting an error now, is at the "getPrintJob(this, name, props)" method. It can't convert "this" to a frame. I have the code inside of a Java Applet. Does it need to be inside a Java Application?

What I'm trying to do is print graphics. (a rectangle in this case) This method above allows that.

E:cb woof!

Edited by - Dog135 on October 16, 2000 5:24:39 PM

Share this post


Link to post
Share on other sites

  • Advertisement