• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Printing PDF in Background  RSS feed

KR Gol
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am trying to write a program that prints PDF files in a directory without asking user for Print Dialog, Background printing.

I used, DocFlavor URL.PDF. But it is simply printing gibberish and repeating the printing forever...
However, a text document is working fine.
I don't see any MIME types application/pdf fromt he list of flavors supported from my printer. However, if I print from ACrobat Reader it works as we all know.

Any help???!!!

Here is the code:
private void doPrint(String pdfFile) {
FileInputStream psStream = null;
try {
psStream = new FileInputStream(pdfFile);
} catch (FileNotFoundException ffne) {
if (psStream == null) {
URL fileURL = null;
try {
fileURL = new File(pdfFile).toURL();
}catch(MalformedURLException mue) {

DocFlavor psInFormat = DocFlavor.INPUT_STREAM.PDF;
DocFlavor urlFileFlavor = DocFlavor.URL.PCL;

Doc myDoc = new SimpleDoc(fileURL, urlFileFlavor, null);

PrintRequestAttributeSet aset =
new HashPrintRequestAttributeSet();

aset.add(new Copies(1));

//PrintService[] services =
//PrintServiceLookup.lookupPrintServices(psInFormat, aset);
PrintService services =
if (services != null) {
System.out.println("Service :"+services.getName());
System.out.println("Is this supported:"+services.isDocFlavorSupported(psInFormat));
DocPrintJob job = services.createPrintJob();
try {
job.print(myDoc, aset);
//throw new PrintException("IGNORE THIS!");

} catch (PrintException pe) {

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!