Jugal Inani
Jugal Inani

Reputation: 133

Printing issue with Java.awt.print.PrinterJob

Using this PrinterJob i would like to print the pdf file where we dont want user to select the format of printing and filename. I mean that the file name and path will be given from code as that file is to be reused. Currently my code is

PrinterJob pJob = PrinterJob.getPrinterJob();
Paper paper = new Paper();

PageFormat pageFormat = new PageFormat();
pageFormat.setPaper(paper);
printJob.setPrintable(this, pageFormat);

if (printJob.printDialog() == false)
{
    return false;
}

try
{
    preparePrintJob(); // This method will create all header,detail and footer
    printJob.print();
}
catch (Exception e)
{
}

This is just a sample code where there is no issue in printing but my requirement is to not to show dialog for which i will remove the printJob.printDialog() line and then how can i set the filepath and filename? Also the format of file should be pdf as the saved file is to be fetched and reused

Upvotes: 0

Views: 973

Answers (2)

VDanyliuk
VDanyliuk

Reputation: 1049

Use method print(PrintRequestAttributeSet attributes). So You can manually set all required attributes.

Upvotes: 0

Neil Masson
Neil Masson

Reputation: 2689

Consult the PrinterJob API to find the setJobName method.

Upvotes: 0

Related Questions