The following code works, but when I print to the PDFCreator printer driver, its default title is “Java Printing”. (I suspect this is true for Adobe Distiller as well, since if you search google for PDFs with Java Printing, you get a lot of results.)
Is there a way to change this from “Java Printing” to another string?
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();
}
}
}
Have you tried this setJobName( String jobName ) .
The API says that it is the name of the document to be printed.
I am running my code on Ubuntu, it doesn’t print the title, so I am unable to verify whether it works or not.