public static void printPdf(InputStream is, String jobName,
			boolean showPrintDialog) throws IOException, PrinterException {
		int BUFSIZE = 1024;

		ByteArrayOutputStream out = new ByteArrayOutputStream(BUFSIZE);

		byte[] buffer = new byte[BUFSIZE];

		int length;
		while ((length = is.read(buffer)) != -1) {
			out.write(buffer, 0, length);
		}

		ByteBuffer bb = ByteBuffer.wrap(out.toByteArray());

		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();
		
		/*
		 * This is a hack by "Barrett" to fix layout problems.
		 * It's described here:
		 * http://juixe.com/techknow/index.php/2008/01/17/print-a-pdf-document-in-java/
		 */
		Paper paper = new Paper();
		paper.setImageableArea(0,0,paper.getWidth() * 2,paper.getHeight());
		pf.setPaper(paper);

		
		pjob.setJobName(jobName);
		Book book = new Book();
		book.append(pages, pf, pdfFile.getNumPages());
		pjob.setPageable(book);

		if (showPrintDialog) {
			if (pjob.printDialog()) {
				pjob.print();
			}
		} else {
			// Send print job to default printer
			pjob.print();
		}
	}