Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
එක පැකේජ් එකයි මාසෙටම Unlimited Internet. තාමත් DATA CARD දාන්න සල්ලි වියදම් කරනවද? අඩුම මිලට අපෙන්.
sayuru bandara
Updated:
Tuesday at 12:30 PM
Ad icon
ඉන්ටර්නෙට් එකෙන් හරියටම සල්ලි හොයන්න සහ Success වෙන්න කැමතිද? 🚀 (E-Money & Success Stories)
siri sumana
Updated:
Saturday at 11:44 PM
Gemini AI PRO 18 months Offer
Hawaka
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
JAVA
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="akhilapraveen" data-source="post: 10769769" data-attributes="member: 104181"><p>Malla i can give u coding a print a text file using java. when you click tha button, yur doc will be printed!</p><p>but malla for direct printing you need to know the bit patterns.</p><p>search google for tht.</p><p></p><p><span style="color: Blue">import java.awt.*;</span></p><p><span style="color: Blue">import java.awt.font.*;</span></p><p><span style="color: Blue">import java.awt.geom.*;</span></p><p><span style="color: Blue">import java.awt.print.*;</span></p><p><span style="color: Blue">import java.text.*;</span></p><p><span style="color: Blue">/**</span></p><p><span style="color: Blue">* The PrintText application expands on the</span></p><p><span style="color: Blue">* PrintExample application in that it images</span></p><p><span style="color: Blue">* text on to the single page printed.</span></p><p><span style="color: Blue">*/</span></p><p><span style="color: Blue">public class JavaApplication12 implements Printable {</span></p><p><span style="color: Blue">/**</span></p><p><span style="color: Blue">* The text to be printed.</span></p><p><span style="color: Blue">*/</span></p><p><span style="color: Blue">private static final String mText ="YOUR DATA HERE";</span></p><p><span style="color: Blue">/**</span></p><p><span style="color: Blue">* Our text in a form for which we can obtain a</span></p><p><span style="color: Blue">* AttributedCharacterIterator.</span></p><p><span style="color: Blue">*/</span></p><p><span style="color: Blue">private static final AttributedString mStyledText = new AttributedString(mText);</span></p><p><span style="color: Blue">/**</span></p><p><span style="color: Blue">* Print a single page containing some sample text.</span></p><p><span style="color: Blue">*/</span></p><p><span style="color: Blue">static public void main(String args[]) {</span></p><p><span style="color: Blue">/* Get the representation of the current printer and</span></p><p><span style="color: Blue">* the current print job.</span></p><p><span style="color: Blue">*/</span></p><p><span style="color: Blue">PrinterJob printerJob = PrinterJob.getPrinterJob();</span></p><p><span style="color: Blue">/* Build a book containing pairs of page painters (Printables)</span></p><p><span style="color: Blue">* and PageFormats. This example has a single page containing</span></p><p><span style="color: Blue">* text.</span></p><p><span style="color: Blue">*/</span></p><p><span style="color: Blue">Book book = new Book();</span></p><p><span style="color: Blue">book.append(new JavaApplication12(), new PageFormat());</span></p><p><span style="color: Blue">/* Set the object to be printed (the Book) into the PrinterJob.</span></p><p><span style="color: Blue">* Doing this before bringing up the print dialog allows the</span></p><p><span style="color: Blue">* print dialog to correctly display the page range to be printed</span></p><p><span style="color: Blue">* and to dissallow any print settings not appropriate for the</span></p><p><span style="color: Blue">* pages to be printed.</span></p><p><span style="color: Blue">*/</span></p><p><span style="color: Blue">printerJob.setPageable(book);</span></p><p><span style="color: Blue">/* Show the print dialog to the user. This is an optional step</span></p><p><span style="color: Blue">* and need not be done if the application wants to perform</span></p><p><span style="color: Blue">* 'quiet' printing. If the user cancels the print dialog then false</span></p><p><span style="color: Blue">* is returned. If true is returned we go ahead and print.</span></p><p><span style="color: Blue">*/</span></p><p><span style="color: Blue">boolean doPrint = printerJob.printDialog();</span></p><p><span style="color: Blue">if (doPrint) {</span></p><p><span style="color: Blue">try {</span></p><p><span style="color: Blue">printerJob.print();</span></p><p><span style="color: Blue">} catch (PrinterException exception) {</span></p><p><span style="color: Blue">System.err.println("Printing error: " + exception);</span></p><p><span style="color: Blue">}</span></p><p><span style="color: Blue">}</span></p><p><span style="color: Blue">}</span></p><p><span style="color: Blue">/**</span></p><p><span style="color: Blue">* Print a page of text.</span></p><p><span style="color: Blue">*/</span></p><p><span style="color: Blue">public int print(Graphics g, PageFormat format, int pageIndex) {</span></p><p><span style="color: Blue">/* We'll assume that Jav2D is available.</span></p><p><span style="color: Blue">*/</span></p><p><span style="color: Blue">Graphics2D g2d = (Graphics2D) g;</span></p><p><span style="color: Blue">/* Move the origin from the corner of the Paper to the corner</span></p><p><span style="color: Blue">* of the imageable area.</span></p><p><span style="color: Blue">*/</span></p><p><span style="color: Blue">g2d.translate(format.getImageableX(), format.getImageableY());</span></p><p><span style="color: Blue">/* Set the text color.</span></p><p><span style="color: Blue">*/</span></p><p><span style="color: Blue">g2d.setPaint(Color.black);</span></p><p><span style="color: Blue">/* Use a LineBreakMeasurer instance to break our text into</span></p><p><span style="color: Blue">* lines that fit the imageable area of the page.</span></p><p><span style="color: Blue">*/</span></p><p><span style="color: Blue">Point2D.Float pen = new Point2D.Float();</span></p><p><span style="color: Blue">AttributedCharacterIterator charIterator = mStyledText.getIterator();</span></p><p><span style="color: Blue">LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, g2d.getFontRenderContext());</span></p><p><span style="color: Blue">float wrappingWidth = (float) format.getImageableWidth();</span></p><p><span style="color: Blue">while (measurer.getPosition() < charIterator.getEndIndex()) {</span></p><p><span style="color: Blue">TextLayout layout = measurer.nextLayout(wrappingWidth);</span></p><p><span style="color: Blue">pen.y += layout.getAscent();</span></p><p><span style="color: Blue">float dx = layout.isLeftToRight()? 0 : (wrappingWidth - layout.getAdvance());</span></p><p><span style="color: Blue">layout.draw(g2d, pen.x + dx, pen.y);</span></p><p><span style="color: Blue">pen.y += layout.getDescent() + layout.getLeading();</span></p><p><span style="color: Blue">}</span></p><p><span style="color: Blue">return Printable.PAGE_EXISTS;</span></p><p><span style="color: Blue">}</span></p><p><span style="color: Blue">}</span></p><p><span style="color: Blue"></span></p><p><span style="color: Blue"><strong>if you dont get the methods follow this steps.</strong></span></p><p><span style="color: Blue"><a href="http://download.oracle.com/javase/tutorial/2d/printing/set.html" target="_blank">http://download.oracle.com/javase/tutorial/2d/printing/set.html</a></span></p><p><span style="color: Blue"></span></p><p><span style="color: Blue">oracle is a graet way to learn java!</span></p><p><span style="color: Blue"></span></p></blockquote><p></p>
[QUOTE="akhilapraveen, post: 10769769, member: 104181"] Malla i can give u coding a print a text file using java. when you click tha button, yur doc will be printed! but malla for direct printing you need to know the bit patterns. search google for tht. [COLOR=Blue]import java.awt.*; import java.awt.font.*; import java.awt.geom.*; import java.awt.print.*; import java.text.*; /** * The PrintText application expands on the * PrintExample application in that it images * text on to the single page printed. */ public class JavaApplication12 implements Printable { /** * The text to be printed. */ private static final String mText ="YOUR DATA HERE"; /** * Our text in a form for which we can obtain a * AttributedCharacterIterator. */ private static final AttributedString mStyledText = new AttributedString(mText); /** * Print a single page containing some sample text. */ static public void main(String args[]) { /* Get the representation of the current printer and * the current print job. */ PrinterJob printerJob = PrinterJob.getPrinterJob(); /* Build a book containing pairs of page painters (Printables) * and PageFormats. This example has a single page containing * text. */ Book book = new Book(); book.append(new JavaApplication12(), new PageFormat()); /* Set the object to be printed (the Book) into the PrinterJob. * Doing this before bringing up the print dialog allows the * print dialog to correctly display the page range to be printed * and to dissallow any print settings not appropriate for the * pages to be printed. */ printerJob.setPageable(book); /* Show the print dialog to the user. This is an optional step * and need not be done if the application wants to perform * 'quiet' printing. If the user cancels the print dialog then false * is returned. If true is returned we go ahead and print. */ boolean doPrint = printerJob.printDialog(); if (doPrint) { try { printerJob.print(); } catch (PrinterException exception) { System.err.println("Printing error: " + exception); } } } /** * Print a page of text. */ public int print(Graphics g, PageFormat format, int pageIndex) { /* We'll assume that Jav2D is available. */ Graphics2D g2d = (Graphics2D) g; /* Move the origin from the corner of the Paper to the corner * of the imageable area. */ g2d.translate(format.getImageableX(), format.getImageableY()); /* Set the text color. */ g2d.setPaint(Color.black); /* Use a LineBreakMeasurer instance to break our text into * lines that fit the imageable area of the page. */ Point2D.Float pen = new Point2D.Float(); AttributedCharacterIterator charIterator = mStyledText.getIterator(); LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, g2d.getFontRenderContext()); float wrappingWidth = (float) format.getImageableWidth(); while (measurer.getPosition() < charIterator.getEndIndex()) { TextLayout layout = measurer.nextLayout(wrappingWidth); pen.y += layout.getAscent(); float dx = layout.isLeftToRight()? 0 : (wrappingWidth - layout.getAdvance()); layout.draw(g2d, pen.x + dx, pen.y); pen.y += layout.getDescent() + layout.getLeading(); } return Printable.PAGE_EXISTS; } } [B]if you dont get the methods follow this steps.[/B] [url]http://download.oracle.com/javase/tutorial/2d/printing/set.html[/url] oracle is a graet way to learn java! [/COLOR] [/QUOTE]
Insert quotes…
Verification
Dahaya deken beduwama keeyada?
Post reply
Top
Bottom