📅  最后修改于: 2022-03-11 14:52:34.348000             🧑  作者: Mango
import com.spire.pdf.*;
import java.awt.print.*;
public class Print {
public static void main(String[] args) {
//load the sample document
PdfDocument pdf = new PdfDocument();
pdf.loadFromFile("Sample.pdf");
PrinterJob loPrinterJob = PrinterJob.getPrinterJob();
PageFormat loPageFormat = loPrinterJob.defaultPage();
Paper loPaper = loPageFormat.getPaper();
//remove the default printing margins
loPaper.setImageableArea(0,0,loPageFormat.getWidth(),loPageFormat.getHeight());
//set the number of copies
loPrinterJob.setCopies(2);
loPageFormat.setPaper(loPaper);
loPrinterJob.setPrintable(pdf,loPageFormat);
try {
loPrinterJob.print();
} catch (PrinterException e) {
e.printStackTrace();
}
}
}