LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-04-2004, 10:48 AM   #1
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Rep: Reputation: 18
word wrap in java


i got this code for printing by googling.

Code:
import javax.print.*;
import javax.print.attribute.*;
import java.io.*;

public class Printing {
  public static void print(String args) throws Exception {
    String filename = args;
    PageFormat pageFormat 
    PrintRequestAttributeSet pras = 
      new HashPrintRequestAttributeSet();
    DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
    //flavor = DocFlavor.CHAR_ARRAY.TEXT_PLAIN;
    PrintService printService[] = 
      PrintServiceLookup.lookupPrintServices(flavor, pras);
    PrintService defaultService = 
      PrintServiceLookup.lookupDefaultPrintService();
    PrintService service = ServiceUI.printDialog(null, 200, 200,
      printService, defaultService, flavor, pras);
    if (service != null) {
      DocPrintJob job = service.createPrintJob();
      FileInputStream fis = new FileInputStream(filename);
      DocAttributeSet das = new HashDocAttributeSet();
      Doc doc = new SimpleDoc(fis, flavor, das);
      job.print(doc, pras);
    }
  }
}
when i am using this to print a .txt file ... the printer prints but it does not wrap long lines ... can neone suggest wht do i need to do.

thanks
 
Old 08-04-2004, 02:42 PM   #2
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

Rep: Reputation: 30
did you try different types of doc flavors? because you can set up different types of documents and print sizes?

what is filename? is it a file of google results or something else, because if its a of google results, you could parse the file, to make it wrap and then stream it into another or same file....just a thought.

Last edited by djgerbavore; 08-04-2004 at 02:44 PM.
 
Old 08-04-2004, 03:17 PM   #3
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Original Poster
Rep: Reputation: 18
filename is being supplied to the class. it is the name of the file to be printed. i havent even understood the code ... and am currently reading a very old tutorial on printing in java

http://www.javaworld.com/javaworld/j...020-print.html

how can i change the print sizes .... i am trying to figure tht out ... just came across the tutorial on the link above ... hopefully i will get the answers there

thanks neways
 
Old 08-11-2004, 01:16 AM   #4
german
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Debian etch, Gentoo
Posts: 312

Rep: Reputation: 30
if you're using a fixed-width font you could just count the characters between "\n"'s and when it gets to 80 or textfield.size().width/8 or whatever insert a "\n"... but that might be slow... an alternative (as previously suggested) is to check which subclass (or implementation... can't remember if it's an interface) of Document the textfield's using and even manually set it (this well may cause it to render html as plain text).

HTH
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
using sed to remove word wrap Harpune Linux - Software 2 03-02-2009 06:53 PM
restricted word wrap with Kontact (Kmail) blastradius Linux - Software 2 10-21-2005 07:39 AM
Microsoft Word won't word wrap Micro420 General 1 06-13-2005 04:36 PM
Java: Change first character in word to upper AMMullan Programming 4 04-05-2004 03:16 PM
Word Wrap Squall LQ Suggestions & Feedback 4 02-03-2004 03:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration