2

I'm here to ask you a solution to this problem:

I have this code:

    public void print(String ip, int port, String printService, byte[] message, String jobName) throws PrinterException{

    PrintService service = getPrintService(printService);

    try {

        Doc doc = new SimpleDoc(message, DocFlavor.BYTE_ARRAY.AUTOSENSE, null);

        DocPrintJob job = service.createPrintJob();

        PrintRequestAttributeSet arset = new HashPrintRequestAttributeSet();
        arset.add(convertMediaSize(mediaSize));
        arset.add(Finishings.STAPLE);
        arset.add(MultipleDocumentHandling.SEPARATE_DOCUMENTS_COLLATED_COPIES);
        arset.add(convertPageSides(pageSides));
        arset.add(new Copies(copies==0?1:copies));
        job.print(doc, arset);

    } catch (Exception e) {
        throw new PrinterException(e);
    }   

}

the message is a byte array generated from a PDF.
When I execute this code printing on a Canon iR-ADV 400/500 PLC5e (setted as default printer) output is ok.
When I execute this code printing on a Canon iR-ADV c5235/5240 PCL5c, output is lots of pages full of strange chars: strange chars

Both printers are network printers in the same network, if I try to print on both printers using word or Notepad or Acrobat Reader... output is ok.

I'm trying to print from Windows, not from Linux.

"message" is generated in this way (in my test)

                File file = new File(inputFile);
                byte[] b = new byte[(int) file.length()];
                FileInputStream fis = new FileInputStream(file);
                fis.read(b);
                wp.print(null, 0, printService, b, null);

Any ideas? thanks

  • Can you try to open a normal pdf and send it to the printer using your code to check if it's a problem with the driver's java interface ? – Javier Toja Nov 14 '16 at 09:05
  • Hi Kareless, I updated the post. the message passed is generated taking a normal PDF. Please, can you tell me how to test your suggestion? thanks – Stefano Figini Nov 14 '16 at 09:44
  • Well, Stefano in the same way os you post on your update, maybe is a problem with the pdf printer support can you check this library https://pdfbox.apache.org/, and this post http://stackoverflow.com/questions/16293859/print-a-pdf-file-using-printerjob-in-java – Javier Toja Nov 14 '16 at 09:55

0 Answers0