I'm using PDFBox-1.6.0 on Windows XP SP3 with Sun JRE 1.6.0_24.
The following code fragment prints the target PDF and the job shows up in the
Windows print queue with the proper Document Name but the Owner field shows the
userID of the User that launches the program, not the text I requested
"Requesting User Name".
Is there a way to get what I want? Am I doing it wrong?
PDDocument pdDoc = null;
try
{
pdDoc = PDDocument.load( "C:\\automatic-heap-sizing.pdf" );
PrinterJob printerJob = PrinterJob.getPrinterJob();
PrintService printService = null;
PrintService[] printServices = PrinterJob.lookupPrintServices();
for( PrintService tPS : printServices )
{
if( tPS.getName().equals( "Samsung ML-4550 Series PCL 6" ) )
{
printService = tPS;
break;
}
}
if( printService == null )
{
System.out.println( "Unable to locate specified PrintService -
cannot print!" );
}
else
{
printerJob.setPrintService( printService );
printerJob.setJobName( "automatic-heap-sizing.pdf" );
PrintRequestAttributeSet as = new
HashPrintRequestAttributeSet();
as.add( new RequestingUserName( "Requesting User Name",
Locale.getDefault() ) );
printerJob.setPageable( new PDPageable( pdDoc, printerJob ) );
printerJob.print( as );
}
}
catch( IOException ioe )
{
System.out.println( "Caught IOException: " +
ioe.getClass().getName() + " - " + ioe.getMessage() );
}
catch( PrinterException pe )
{
System.out.println( "Caught PrinterException: " +
pe.getClass().getName() + " - " + pe.getMessage() );
}
catch( Throwable t )
{
System.out.println( "Caught Throwable: " + t.getClass().getName() +
" - " + t.getMessage() );
}
finally
{
if( pdDoc != null )
{
try
{
pdDoc.close();
}
catch( Throwable t )
{
System.out.println( "Caught Throwable: " +
t.getClass().getName() + " - " + t.getMessage() );
}
}
}
Regards,
Mike Kuindersma
mkuinder _at_ rogers.com