Printing in java sets the name somewhere in "Java Printing"

The following code works, but when I type in the PDFCreator printer driver, its default name is "Print in Java". (I suspect this is true for Adobe Distiller, since if you do a google search for PDFs using Java Printing , you will get many results.)

Is there a way to change this from "Java Printing" to another line?

package com.example.test.gui; import java.awt.Graphics; import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; public class TestPrint implements Printable { @Override public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { if (pageIndex != 0) return NO_SUCH_PAGE; graphics.drawString("Hi there", 100, 100); return PAGE_EXISTS; } public void printPage() throws PrinterException { PrinterJob job = PrinterJob.getPrinterJob(); boolean ok = job.printDialog(); if (ok) { job.setPrintable(this); job.print(); } } public static void main(String[] args) { try { new TestPrint().printPage(); } catch (PrinterException e) { e.printStackTrace(); } } } 
+6
source share
2 answers

You tried this setJobName (String jobName).

 job.setJobName("New Printing Name"); 

The API says this is the name of the document to print. A.

I run my code on Ubuntu, it does not print the title, so I can’t check if it works or not.

+8
source

Same answer, but for DocPrintJob :

 PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); pras.add(new JobName("your job name", Locale.getDefault())); docPrintJob.print(docToPrint, pras); 
+3
source

Source: https://habr.com/ru/post/889708/


All Articles