You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use CUPS4J to help in printing the docs with a specified Tray and media type but somehow what ever I do/give params, it prints from the default Tray of the printer.
Below is the code I am using to test out the functionality, can you please help me pointing out what am I missing here.
Rest of the params are working fine and I get the desired result except the Tray.
Commented code are the different options I tried but none worked. Please help in resolving.
-----code ------
I found a workaroud ... the printer that we are using is Lexmark brand and using the Lexmark's driver I am able to create 2 printer configuration in the CUPS server, 1 each for individual tray as default Tray (like PrinterX-T1 & PrinterX-T2) and then sending the printing command to each depending upon the need. This is clumsy I agree, but it works :)
My quest is to make it work cleaner with less management, please help!
CUPS is the linux printing system that delivers many drivers to print different file types. I never heard of a print driver for CUPS that is able to print microsoft documents.
Cups4J just helps sending print jobs to CUPS from java. So if you can find a solution for your problem, please come back and report it here.
I am trying to use CUPS4J to help in printing the docs with a specified Tray and media type but somehow what ever I do/give params, it prints from the default Tray of the printer.
Below is the code I am using to test out the functionality, can you please help me pointing out what am I missing here.
Rest of the params are working fine and I get the desired result except the Tray.
Commented code are the different options I tried but none worked. Please help in resolving.
-----code ------
package com.test.printer;
import java.io.File;
import java.net.URL;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.cups4j.CupsClient;
import org.cups4j.CupsPrinter;
import org.cups4j.PrintJob;
import org.cups4j.PrintRequestResult;
public class CupsPrintTest {
// File file = new File("FILE-PATH\ABCD.pdf"); // PDF file path
byte[] byteArray = Files.readAllBytes(file.toPath());
int copies = 1;
CupsClient cupsClient;
cupsClient = new CupsClient(cupsURI.getHost(), cupsURI.getPort(), "user");
printerName = "PR3311";//@network printer
String strPrinterURL = strCupsURI + printerName;
URL printerURL = new URL(strPrinterURL);
CupsPrinter cupsPrinter = cupsClient.getPrinter(printerURL);
boolean isDuplex = true;
// String tray = "upper";
// String tray = "middle";
// String tray = "lower";
// String tray = "Tray 1";
// String tray = "Tray 2";
// String tray = "Tray2";
String tray = "na_legal_8.5x14in";
// String tray = "legal";
mimeType = MimeTypes.PDF;
if (mimeType == MimeTypes.TEXT) {
cupsPrinter.setMimeTypesSupported(Arrays.asList("text/plain"));
isDuplex = false;
cupsPrinter.setMediaDefault(tray);
} else {
cupsPrinter.setMimeTypesSupported(Arrays.asList("application/vnd.cups-ppd"));
cupsPrinter.setMediaDefault(tray);
cupsPrinter.setMediaSupported(Arrays.asList(tray));
isDuplex = true;
}
Map<String, String> attributes = new HashMap<>();
// attributes.put("compression", "none");
// attributes.put("job-attributes", "print-quality:enum:9#fit-to-page:boolean:false#sheet-collate:keyword:collated");
// attributes.put("job-attributes", "media:keyword:bottom#media-default:keyword:bottom#media-supported:keyword:bottom#media-ready:keyword:bottom");
// attributes.put("job-attributes", tray);
// attributes.put("job-attributes", "media:bottom");
attributes.put("job-attributes", "media-source:keyword:Tray-2");
PrintJob printJob = new PrintJob.Builder(byteArray)
.userName("loggedInUser")
.jobName("JobName")
.duplex(isDuplex)
.copies(copies)
// .pageFormat(tray)
.attributes(attributes)
.build();
PrintRequestResult printRequestResult = null;
printRequestResult = cupsPrinter.print(printJob);
if (printRequestResult != null)
System.out.println(" Done with printing with ID = "+ printRequestResult.getJobId());
else
System.out.println("Did NOT print");
return true;
}
-------code ends ----------
The text was updated successfully, but these errors were encountered: