LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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, 11:48 AM   #1
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Rep: Reputation: 17
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, 03:42 PM   #2
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 443

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 03:44 PM.
 
Old 08-04-2004, 04:17 PM   #3
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Original Poster
Rep: Reputation: 17
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, 02: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 07:53 PM
restricted word wrap with Kontact (Kmail) blastradius Linux - Software 2 10-21-2005 08:39 AM
Microsoft Word won't word wrap Micro420 General 1 06-13-2005 05:36 PM
Java: Change first character in word to upper AMMullan Programming 4 04-05-2004 04:16 PM
Word Wrap Squall LQ Suggestions & Feedback 4 02-03-2004 04:25 PM


All times are GMT -5. The time now is 12:49 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration