Results 1 to 2 of 2
  1. #1
    rameshZSL is offline Member
    Join Date
    Jan 2011
    Rep Power

    Default Plzz Help...Issue when doing Text Printing from Java to Canon iR1018, iR1020

    When printing a text file through a Java program to a Cannon iR1018 and iR1020 the print job vainishes when it reaches the printer.
    From the printer specification it says PCL is optional and UFR is standard for both the printers.

    Could you please update ASAP what could be the root cause of this issue.

    The same program works fine when I print to the Cannon iR1022 and iR1024 printer and I am getting the page printed with "HelloWorld" string.
    The issue when I print to the Cannon iR1018 & iR1020 is the page not getting printed though I can see the print job is spooled out from the workstation where the print is initiated. There are no expection been thrown.

    JRE version : 1.6.0_13


    Below is the test program attached :

    Java Code:
    import java.awt.print.Book;
    import java.awt.print.PageFormat;
    import java.awt.print.PrinterJob;
    import java.nio.ByteBuffer;
    import java.nio.channels.FileChannel;
    import javax.print.*;
    import javax.print.attribute.AttributeSet;
    import javax.print.attribute.HashAttributeSet;
    import javax.print.attribute.HashPrintRequestAttributeSet;
    import javax.print.attribute.PrintRequestAttributeSet;
    import javax.print.attribute.standard.Copies;
    import javax.print.attribute.standard.OrientationRequested;
    import javax.print.attribute.standard.PrinterName;
    import com.sun.pdfview.PDFFile;
    public class PrintTest {
    	public static void main(String[] args) throws IOException {
    //		PrintTest pt = new PrintTest();
    //		pt.printPDF();
    		// we are going to print "printtest.txt" file which is inside working
    		// directory
    //		 File file = new File("C:\\temp\\test.txt");
    //		File file = new File("D:\\BH.pdf");
    //		InputStream is = new BufferedInputStream(new FileInputStream(file));
    		String str = "HelloWorld";
    		byte[] originalContent = null;
    		originalContent = str.getBytes();
    		 ByteArrayOutputStream	out = new ByteArrayOutputStream();
    		// Discover the default print service. If you call
    		// PrintServiceLookup.lookupPrintServices
    		// then it will return an array of print services available and you can
    		// choose a
    		// printer from them
    		//PrintService service [] = PrintServiceLookup.lookupDefaultPrintService();
    		PrintService service [] = null;
    		// Doc flavor specifies the output format of the file (Mime type + Char
    		// encoding)
    		// You can retrieve doc flavors supported by the printer, like this
    		// DocFlavor [] supportedFlavors = service.getSupportedDocFlavors();
    		DocFlavor docFlavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
    		// Find a particular service by name;
    		AttributeSet asset = new HashAttributeSet();
    		asset.add(new PrinterName("LEX02", null));
    		service  = PrintServiceLookup.lookupPrintServices(null, asset);
    		// Create the print job
    		DocPrintJob job = service[0].createPrintJob();
    		// Create the Doc. You can pass set of attributes(type of
    		// PrintRequestAttributeSet) as the
    		// 3rd parameter specifying the page setup, orientation, no. of copies,
    		// etc instead of null.
    		Doc doc = new SimpleDoc(str.getBytes("cp1252"), docFlavor, null);
    		PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    		aset.add(new Copies(1));
    		// Order to print, (can pass attributes instead of null)
    		try {
    			job.print(doc, aset);
    		} catch (PrintException e) {
    		// DocPrintJob.print() is not guaranteed to be synchronous. So it's
    		// better to wait on completion
    		// of the print job before closing the stream. (See the link below)
    		System.out.println("Printing done....");
    Last edited by Eranga; 01-21-2011 at 12:43 PM. Reason: code tags added

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Colombo, Sri Lanka
    Blog Entries
    Rep Power

Similar Threads

  1. plain text printing with java
    By berkeleybross in forum Advanced Java
    Replies: 3
    Last Post: 04-04-2011, 02:01 AM
  2. text printing service in java
    By rameshkondur in forum AWT / Swing
    Replies: 1
    Last Post: 04-08-2009, 04:56 AM
  3. Java Text Printing
    By vivekn in forum Introductions
    Replies: 0
    Last Post: 03-13-2009, 09:05 AM
  4. printing simple text as text on printer
    By Nicholas Jordan in forum Advanced Java
    Replies: 0
    Last Post: 12-01-2008, 02:42 AM
  5. Issue with printing line
    By Azndaddy in forum Advanced Java
    Replies: 1
    Last Post: 04-04-2008, 08:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts