Java Utililty Methods Printer Usage

List of utility methods to do Printer Usage

Description

The list of methods to do Printer Usage are organized into topic(s).

Method

voidprint(PrintService printService, byte[] pdf)
print
final DocPrintJob job = printService.createPrintJob();
final Doc doc = new SimpleDoc(pdf, DocFlavor.BYTE_ARRAY.PDF, null);
final PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new Copies(1));
aset.add(MediaSizeName.ISO_A4);
aset.add(Sides.ONE_SIDED);
job.print(doc, aset);
voidrefreshPrinterList()
refresh Printer List
Class<?>[] classes = PrintServiceLookup.class.getDeclaredClasses();
for (Class<?> classe : classes) {
    if (classe.getName().equals("javax.print.PrintServiceLookup$Services")) {
        sun.awt.AppContext.getAppContext().remove(classe);
        break;
voidshowAttributes(PrintRequestAttributeSet aset)
show Attributes
Attribute tab[] = aset.toArray();
for (int i = 0; i < tab.length; i++) {
    Attribute attr = tab[i];
    System.out.println("  - " + i + ". " + attr.getName() + " " + attr.toString());
voidtestSPS()
Test Stream Print Services
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
PrintService[] pss = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, pras);
for (int i = 0; i < pss.length; i++) {
    PrintService ps = pss[i];
    String name = ps.getName();
    if (name.indexOf("PDF") != -1 || name.indexOf("Acrobat") != -1) {
        System.out.println("----");
        System.out.println(ps);
...
intvalidateDPI(int dpi)
Validates the dpi value.
if (dpi <= 0)
    dpi = ResolutionSyntax.DPI;
if (dpi <= 0)
    dpi = DEFAULT_DPI;
return dpi;