Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Page size when printing html from JTextPane

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JTextPane that reads a .htm file and displays it. If I change the font size it changes the appearance on the JTextPane but when I try to print the data looks the same. I have a large html table and I can only get 20 columns on one page. I would like to shrink the table down so I can get more on a page. Here is the code I am using to print the JTextPane:
private void startPrint() {
try{
PrinterJob prnJob = PrinterJob.getPrinterJob();
prnJob.setPrintable(this);
if(!prnJob.printDialog())
return;
prnJob.print();
}
catch (PrinterException e) {
e.printStackTrace();
System.err.println("Printing error: "+e.toString());
}
}
public int print(Graphics pg, PageFormat pageFormat,
int pageIndex) throws PrinterException {
Dimension d = prtPane.getSize();
double panelWidth = d.width;
double panelHeight = d.height;
double pageHeight = pageFormat.getImageableHeight();
double pageWidth = pageFormat.getImageableWidth();
double scale = pageWidth/panelWidth;
int totalNumPages = (int)Math.ceil(scale * panelHeight / pageHeight);
if(pageIndex >= totalNumPages)
return Printable.NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D)pg;
g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
g2.translate(0f, -pageIndex * pageHeight);
g2.scale(scale, scale);
prtPane.print(g2);
return Printable.PAGE_EXISTS;
Does anyone have any ideas on how to fix this?
Thanks
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chris,
I want a solution from you.
Are you using textpane.setEditorKit(new HTMLEditorKit()) and
setting the doc to the textpane?? If so how to make the portion of the text in the textpane to be (bold,italic,unedrline,foreground) by selecting and clicking buttons on the toolbar on the top??
 
Chris Behr
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No I don't use the HTMLEditorKit. I just create the html in a file and then use .setPage( to insert the HTML into the JTextPane. I still haven't figured my problem out. I can change the font size and it affects how it looks on the JTextPane but when I print it always comes out the same size. Does anyone have any ideas?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chris,
I am facing the same problem while using the JEditorPane..I hope by this time u would have found solution for it..It would be highly helpful if you could let me know..
Best Regards,
Niranjan
reply
    Bookmark Topic Watch Topic
  • New Topic