I want to use PDFBox for printing PDF files created by iText. I have tried this successfully with PDDocument class and its method print(). You can find docu
import java.awt.print.PrinterException;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
public class Print {
public static void main(String[] args) throws IOException, PrinterException
{
PDDocument pdf=PDDocument.load("d:\\filename.pdf");
pdf.print();
}
}
use the above code to print pdf using apache Pdfbox
EDIT: version 2.0.0
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.File;
import java.io.IOException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.printing.PDFPageable;
public class JPrint {
public static void main(String[] args) throws IOException, PrinterException {
String filename;
filename = "C:\\pdf.pdf";
try {
PDDocument pdf = PDDocument.load(new File(filename));
PrinterJob job = PrinterJob.getPrinterJob();
job.setPageable(new PDFPageable(pdf));
job.print();
} catch (Exception e) {
System.out.println(e);
}
}
}