pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thierry.mat...@havells-sylvania.com
Subject Beginner's question....
Date Tue, 09 Jun 2015 08:45:06 GMT


I'm a french beginner either in Java and using PDFBox...

I want to use PDFBox to print PDF files stored on a disk.
No problem to get the PDF from disk, but my problem is to print the PDF
file with correct attributes...

I have "simple" PDF files (format A4, portrait, no duplex print), but I
have also other attributes (A3 and/or Landscape and/or duplex) that can
And I want a complete Silent print...

I've tried with this class, but this doesn't work :

public class PDFmanager {
	private String filename;
	private String size;
	//private String orientation;
	private Integer copies;
	private PrintService printer;
	private PrintRequestAttributeSet aset;
	private DocAttributeSet asetD;
	private DocFlavor flavor;

	public PDFmanager(String size, boolean duplex) {
		flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
		PrintRequestAttributeSet aset = new

		if (size == "A4"){
		} else if (size == "A3"){

		if (duplex){

		} else {


		PrintService[] pservices =
		PrintServiceLookup.lookupPrintServices(null, null);

		if (pservices.length > 0) {
		   for (PrintService selprinter : pservices) {
		        System.out.println("Printer: " + selprinter.getName()+"
Attr : "+ selprinter.getAttributes().toString());
		        /* TODO : modifier MYPRINTER par nom imprimante STE */
		        if (selprinter.getName().equals("\\\\svgendc01
\\PNGEN0029")) {
	                printer = selprinter;

	public void printPDF() throws IOException, PrinterException {

	    if (!(printer == null)) {
		PrinterJob job = PrinterJob.getPrinterJob();

	    PDDocument doc = PDDocument.load(filename);
	    } else {
	                "Pas d'imprimante valide pour l'impression des
Notices !",

	public String getFilename() {
		return filename;

	public void setFilename(String filename) {
		this.filename = filename;

	public String getSize() {
		return size;

	public void setSize(String size) {
		this.size = size;

	public Integer getCopies() {
		return copies;

	public void setCopies(Integer copies) {
		this.copies = copies;

	public PrintService getPrinter() {
		return printer;

	public void setPrinter(PrintService printer) {
		this.printer = printer;


I use  INPUT_STREAM.AUTOSENSE   because  INPUT_STREAM.PDF  doesn't work...
And the printer I select can print with any of selected attributes (Kyocera

The attributes were used to select the Printer Service, but no printer was
selected when I did this. Now, they are not used...
But, the printing is not correct (no A3, content not adjusted to page
Is it possible to set attributes at the moment I start the print ?

Maybe I'm not using PDFBox the right way....

What can I do ?

Cordialement / Best regards

Thierry MATHEY
IT EDI Expert


T +33 (0)1 55 51 11 64
M +33 (0)6 71 01 87 06
This e-mail and any attachments may contain confidential and privileged information. If you
are not the intended recipient, please notify the sender immediately by return e-mail, delete
this e-mail and destroy any copies. Any dissemination or use of this information by a person
other than the intended recipient is prohibited and may be unlawful.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message