Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Printing the string

892578Oct 5 2011 — edited Oct 19 2011
The below code is print the data in the cheque.For this i create a template and replace in the template with data.

StringBuffer checkTemplate = new StringBuffer();
checkTemplate.append(" VENDOR_NUMBER______ VENDOR_NAME________________________ CHECK_DATE\n");
checkTemplate.append(" \n");
checkTemplate.append(" REF_NUMBER_A INVDATE_A GROSS_AMOUNT_A DISC_TAKEN_A NET_AMT_PAID_A\n");


I replace this with my data later and place it in a string
and this string is passed as a parameter to the below function.
void printIt(String printString) {
InputStream textStream = new ByteArrayInputStream(printString.getBytes());
DocFlavor myFormat=DocFlavor.INPUT_STREAM.AUTOSENSE ;
Doc myDoc = new SimpleDoc(textStream, myFormat, null);

if (printJob.printDialog()){
try {
printService=printJob.getPrintService();
printJob.setPrintService(printService);
job = printService.createPrintJob();
PrintJobWatcher pjw = new PrintJobWatcher(job);
job.print(myDoc, aset);
pjw.waitForDone();
print = true;
}catch(Exception pe){
pe.printStackTrace();
}
}
}




My problem is when i send this string to the laser printer, The string contains the line character "\n" .Even though it contains the new line character laser printer doesnot print line by line. it prints all the string at one line

Please help me.

Edited by: 889575 on Oct 5, 2011 2:41 AM

Edited by: 889575 on Oct 5, 2011 2:44 AM

Edited by: 889575 on Oct 6, 2011 4:11 AM

Edited by: 889575 on Oct 6, 2011 10:42 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 16 2011
Added on Oct 5 2011
4 comments
245 views