I am using Jdk-8 in my system and trying to run a standalone java program to validate printing in the printer. The full PrintTest
class is mentioned below as:
import java.io.*;
import java.awt.print.PrinterJob;
import java.io.FileInputStream;
import java.util.concurrent.TimeUnit;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.Sides;
import javax.print.PrintException;
import javafx.print.Paper;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.printing.PDFPrintable;
import org.apache.pdfbox.printing.PDFPageable;
public class PrintTest{
public static void main(String[] args) {
try{
final String path = "C:/projects/printFile.docx";
File file = new File(path);
if (!file.exists())
return;
PDDocument document = PDDocument.load(file);
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(Sides.DUPLEX);
PrinterJob job = PrinterJob.getPrinterJob();
job.setPageable(new PDFPageable(document));
job.print(pras);
System.out.println("Print completed...");
} catch(PrintException pe){
pe.printStackTrace();
} catch(Exception ex){
ex.printStackTrace();
}
}
}
But I'm getting below errors everytime while compiling from the command prompt javac PrintTest.java
file.
- error: package org.apache.pdfbox.printing does not exist
- error: package org.apache.pdfbox.pdmodel does not exist
- error: package javafx.print does not exist
Not able to resolve these errors. It is not maven project that I can add dependency. Please help to compile and run the program smoothly.
If I commented out the error lines and tried to compile then it ran without any errors. But I need all the lines to be compiled.