Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing multiple pages from a Java Browser  RSS feed

 
Manjula Rao
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i have created a browser purely in Java. while i give the printing functionality to it i am having the following problems.
1) if the content for printing spans over multiple pages then only the first page prints properly and the rest of teh pages are ejected as blank pages.
2) if the current page is a multi-frame page then the print command yields only one blank page, no matter how long the actual page is.
for more information: i have implimented Printable and Pageable interface.
thanx
Manjula
 
vikas de
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i have a prob regarding Printing in Java and maybe u can help me...
my prob is that i want also add a fuction to my app which prints the file...please help me or guide me how to use the print function in Java because i have no knowledge about that in Java...
Thanx a lot..
Please reply as soon as possible...**its urgent** or mail me
vikasde@usa.net & vikasde@rediffmail.com
vikas
 
Manjula Rao
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Vikas,
to get u started on printing here is some code sample that prints text. this will help u to understand not only how printing is done "in java" (as u stress) but also give u an idea of how multi pages are printed ("in java;").
import java.awt.*;
import java.awt.print.*;
public class testPrint implements Printable
{
private static String s[];
private static Font f;
private static int nLines;
public static void main (String arg[])
{
s = new String[50];
f = new Font("Arial", Font.BOLD, 14);
int i;
s[0] = "This is a printer test";
for (i=1; i<50; i++)
{
s[i] = "The next line";
}
nLines = 50;
testPrint.print ();
}
public static void print ()
{
PrinterJob pj;
Book b = new Book();;
PageFormat pf = new PageFormat();
pj = PrinterJob.getPrinterJob();
pf = pj.defaultPage(pf);
b.append (new testPrint(), pf, 2);
try {
pj.setPageable (b);
pj.print();
}
catch (Exception e) { System.out.println ("Error"); }
}
public int print (Graphics g1, PageFormat pf, int n)
{
int x,y,i,fa,fh;
FontMetrics fm;
Graphics2D g = (Graphics2D) g1;
fm = g.getFontMetrics (f);
fa = fm.getMaxAscent();
fh = fm.getHeight();
x = (int)pf.getImageableX();
y = (int)pf.getImageableY() + fa;
g.setFont (f);
g.setColor(Color.black);
if (n==1){
for (i=0; i<20; i++)
{
g.drawString (s[i], x, y);
y += fh;
}
return PAGE_EXISTS;
}
else {
for (i=20; i<nLines; i++) >
{
g.drawString (s[i], x, y);
y += fh;
}
return PAGE_EXISTS;
}
return PAGE_EXISTS;
}
}
Hope this helps u.
Manjula Rao
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!