• Post Reply Bookmark Topic Watch Topic
  • New Topic

Issue when doing Text Printing from Java to Canon iR1018 & iR1020  RSS feed

 
RamHi ReddyDar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.

JRE version : 1.6.0_13

Could you please help as urgent what could be the root cause of this issue.


Thanks.

Below is the test code been used :



 
Rob Spoor
Sheriff
Posts: 21117
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Ramesh!

Ramesh Subbu wrote:Could you please help as urgent what could be the root cause of this issue.

Please EaseUp.

So, you're sending a job to the printer. You're not getting any exceptions. But the job finishes immediately after it has started, doing nothing at all. Is that correct?

What happens if you try to read the data from the Doc manually?
 
RamHi ReddyDar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Posts: 21117
85
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you can print just fine from other programs?
 
RamHi ReddyDar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


package com.bh.print.printer;

import java.awt.print.Book;
import java.awt.print.PageFormat;
import java.awt.print.PrinterJob;
import java.io.*;
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 {
String str = "HelloWorld";
byte[] originalContent = null;
originalContent = str.getBytes();
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(originalContent);
out.flush();
out.close();

PrintService service [] = null;
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();
Doc doc = new SimpleDoc(str.getBytes("cp1252"), docFlavor, null);

PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new Copies(1));

try {
job.print(doc, aset);
} catch (PrintException e) {
e.printStackTrace();
}

System.out.println("Printing done....");
}

}
 
RamHi ReddyDar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To answer your question - No. The above program is a simple java print code which prints a 'HelloWorld' string a Canon printer iR1022, iR1024.
The same program does not give any print job in a Canon printer iR1018, iR1020. And When we see the difference btw the printers :
iR1022/iR1024 - Supports PCL and UFR as standard.
iR1018/iR1020 - Only Supports UFR and not PCL.

Hope that helps.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think he meant to ask whether those printers work from, say, Notepad or Word -- i.e., do they work at all?
 
Rob Spoor
Sheriff
Posts: 21117
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't ask about Java programs. I was asking if programs like MS Word can print to those printers properly. Because if they can't either then the problem is in your printer driver / connection, not the Java program.

Edit: what Ernest said.
 
RamHi ReddyDar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh Sorry, with the notepad directly printing to the printer works fine. Also I tried a java program converting to PDF and that as well works and printed the HelloWorld string.
Below is the code snippet for the PDF conversion and printing :
 
RamHi ReddyDar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


strBuff = new StringBuffer("HelloWorld");
text = strbuff.toString();
Document document = new Document(PageSize.ARCH_A, 36, 72, 0, 0);
PdfWriter.getInstance(document,new FileOutputStream("D:\\pdfFile.pdf"));
document.open();
document.add(new Paragraph(text));
System.out.println("Text is inserted into pdf file");
document.close();
File f = new File("D:\\pdfFile.pdf");
FileInputStream fis = new FileInputStream(f);
FileChannel fc = fis.getChannel();
ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
PDFFile pdfFile = new PDFFile(bb); // Create PDF Print Page
PDFPrintPage pages = new PDFPrintPage(pdfFile);
// Create Print Job
PrinterJob pjob = PrinterJob.getPrinterJob();
PageFormat pf = PrinterJob.getPrinterJob().defaultPage();
pjob.setJobName(f.getName());
Book book = new Book();
book.append(pages, pf, pdfFile.getNumPages());
pjob.setPageable(book);
// Send print job to default printer
pjob.print();
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16045
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't double-click the code button. Make sure that the source code is between the [code] and [/code] tags.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!