• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java code printing junk characters in PDF

 
Suhel Sayyed
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a JAVA code that reads a PDF file from remote server. It then merges it with an existing PDF file and print the resultant. However, sometimes I observe that the PDF printed contains gibbersih data. It doesn't happen always. Is it some issue with the fonts used in PDF? Or some inherent issue of Java, while printing PDF files.

I use a print job object to print PDF file. Logic for printing the PDF file is as following

private boolean printDocument(String fileName){
System.out.println("printComplianceDocument : Begin");
boolean result = false;
PDDocument document = null;
PDPage page = new PDPage();

try {
document = PDDocument.load(fileName);
PrinterJob pjob = PrinterJob.getPrinterJob();

PrintRequestAttributeSet attr_set = new HashPrintRequestAttributeSet();
attr_set.add(Sides.DUPLEX);
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, attr_set);
for(PrintService service : services){
if (service.getName().equalsIgnoreCase(SystemProp.getInstance().getWorkStation().getDfltRptPrinter().getAddress().trim())){
System.out.println("Printing Document to printer: " + service.getName());
pjob.setPrintService(service);
pjob.setPageable(document);
pjob.print(attr_set);
result = true;
break;
}
}

//Try printing to Default Printer if appropriate Print Service is not found
if(!result){
PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
System.out.println("Printing Document to Default Printer: " + defaultPrintService.getName());
pjob.setPrintService(defaultPrintService);
pjob.setPageable(document);
pjob.print(attr_set);
result = true;
}

} catch (IOException e) {
// Exception
} catch (PrinterException e) {
// Exception
}
System.out.println("printDocument : End");
return result;
}

Please share your ideas and suggest solutions if you could. Thanks
 
Suhel Sayyed
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have also verified the PDF kept on remote server, they are good.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic