Hi,
I have tried to print a document (see attachment) but the pages are completely
empty. Also text extraction is not working. Has anybody an idea what is going
wrong ?
I am creating the document with iText 2.1.7 and use the checked out version of
pdf-box (1.5) from 17/02/2011. Furthermore the document has an embedded OTF
font inside with ANSI encoding.
Here is my code:
private void printPDF(byte[] barrayBs) throws IOException,
CryptographyException, InvalidPasswordException, PrinterException {
String password = "";
String printerName = null;
PDDocument document = null;
try {
document = PDDocument.load(new ByteArrayInputStream(barrayBs));
//document = PDDocument.load("/Users/selfemp/Desktop/pr2.pdf");
//PDFont font = PDTrueTypeFont.loadTTF( document, new
File("/Users/selfemp/Desktop/fonts/TeXGyreAdventor-Regular.ttf"));
//PDFont font2 = PDTrueTypeFont.loadTTF( document, new
File("/Users/selfemp/Desktop/fonts/TeXGyreAdventor-Bold.ttf"));
if (document.isEncrypted()) {
document.decrypt(password);
}
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setJobName("WIST-Report");
if (printerName != null) {
PrintService[] printService = PrinterJob.lookupPrintServices();
boolean printerFound = false;
for (int i = 0; !printerFound && i < printService.length; i++) {
if (printService[i].getName().indexOf(printerName) != -1) {
printJob.setPrintService(printService[i]);
printerFound = true;
}
}
}
document.silentPrint(printJob);
} finally {
if (document != null) {
document.close();
}
}
}