Print job goes to print queue and then disappear

Hi Experts,

I have an issue with printing documents thru our web app(Tomcat). The printer works OK from other applications, but it doesn’t print thru our web app even though the print job goes to print queue.(it goes to print queue and then just disappear and nothing prints.) .
I don't see any error message from the log either.

I have asked other code related question before with similar issue and now I have this printing issue.

public void sendPDFToPrinter(byte[] pdf, String printerQ) throws PrintUtilException {
		
		boolean printed = false;
		 //DocFlavor pdfFlavor = DocFlavor.BYTE_ARRAY.PDF;
		//DocFlavor pdfFlavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
		DocFlavor pdfFlavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
		 Doc pdfDoc = new SimpleDoc(pdf, pdfFlavor, null);
		
		PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
		      
 		if(services != null) {
		
			for(PrintService service : services) {
				 PrintServiceAttributeSet atts = service.getAttributes();
				if(atts == null) {					
					continue;
 				}
				Attribute theAtt = atts.get(javax.print.attribute.standard.PrinterName.class);
				
				if(theAtt.toString().equals(printerQ)) {
					
					DocPrintJob job = service.createPrintJob();
					job.addPrintJobListener(new WTFListener());
					
					PrintRequestAttributeSet psas = new HashPrintRequestAttributeSet();				
					psas.add(Sides.DUPLEX);
					
					try {
						job.print(pdfDoc, psas);
						printed = true;
						break;
					} catch (PrintException pe) {
						pe.printStackTrace();
						throw new PrintUtilException(pe.getMessage());
					} 
				}
			}
		}
...
...

Open in new window


thanks,
dkim18Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
You said you got it working. So what happened?
0
hdhondtCommented:
I believe that Java does not support PDF printing under Windows - unless your printer (what model do you have?) directly supports PDF printing. When printing from other applications, the driver converts the PDF to whatever the printer can understand. Under Java you can access external applications, so you can call Acrobat to do the printing.

Have a look at these links:
https://www.idrsolutions.com/jpedal/print-pdf-files-in-java
https://blog.idrsolutions.com/2010/01/printing-pdf-files-from-java/
0
dkim18Author Commented:
CEHJ,

The previous question was about invalid flavor and data is not of declared type error message. I resolved that and I thought I was able to print pdf thru the web app.

hdhondt,

I am testing with Samsung M2020 Series printer. I also have Brother HL 5140(this is a bit old model.)

I ran this code:
  public static void main(String args[]){
        PrintService[] allServices = PrintServiceLookup.lookupPrintServices(null, null);
            
        
        String printerQ = ResourceUtils.getEhrPropsResourceValue("printpdf.printerQ");
       // PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
       
        for (PrintService ps : allServices)
        {
        	
        	if(ps.getName().matches(printerQ)){
        		System.out.println(ps + " supports :");
        		DocFlavor[] flavors = ps.getSupportedDocFlavors();
        		for (int i = 0; i < flavors.length; i++)
        		{
        			System.out.println("\t" + flavors[i].getMimeType());

        		}
        		
        		System.out.println(ps + " supports :");
        		
        		try {
        			FileInputStream fis = new FileInputStream("C:/pdf_test.pdf");
        			System.out.println("Total file size to read (in bytes) : "+ fis.available());
        			Doc pdfDoc = new SimpleDoc(fis, null, null);

        			DocPrintJob printJob = ps.createPrintJob();

        			printJob.print(pdfDoc, new HashPrintRequestAttributeSet());

        			fis.close();
        			
					
				} catch (Exception e) {
					System.out.println("Printing error : " + e.getMessage());
				}
        	}
        }
               
	}

Open in new window


and got this result:

Win32 Printer : Samsung M2020 Series#:13 supports :
      image/gif
      image/gif
      image/gif
      image/jpeg
      image/jpeg
      image/jpeg
      image/png
      image/png
      image/png
      application/x-java-jvm-local-objectref
      application/x-java-jvm-local-objectref
      application/octet-stream
      application/octet-stream
      application/octet-stream
Win32 Printer : Samsung M2020 Series#:13 supports :
Total file size to read (in bytes) : 26500
Printing error : null argument(s)

So, the samsung printer does not support pdf printing under windows?
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

hdhondtCommented:
You misunderstood. Your printer can print PDFs under Windows, but does not support PDF direct printing (i.e. sending the PDF direct to the printer).

If you print under Windows, then the PDF is passed to the driver, which converts it into something the printer does understand. In the case of the M2020, that is a printer bitmap (this printer does not support any printer language like PostScript, PCL, or PDF). The Brother HL 5140 supports PCL and PS, but not PDF.

As I understand it, Java does not support that conversion if you are running under Windows.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dkim18Author Commented:
hm...my development environment is windows. Any other options other than obtaining printer that supports PDF?
0
hdhondtCommented:
The 2 links I gave in my first post give other suggestions. I also mentioned using Acrobat (from Java) to do the printing.
0
CEHJCommented:
It looks like you'd have to find a way in Java to convert from PDF to GDI if you want to use the Samsung printer
0
dkim18Author Commented:
one last question...
what if I obtain a printer that supports those languages(ps, pdf, etc...)? Can you list some inexpensive printers?
0
CEHJCommented:
Why don't you just use the Brother?
0
dkim18Author Commented:
hdhondt said:

Brother HL 5140 supports PCL and PS, but not PDF
0
CEHJCommented:
what if I obtain a printer that supports those languages(ps, pdf, etc...)?
is what you just asked
0
dkim18Author Commented:
If this issue is resolved by getting one of the printers that supports PDF, then I am thinking getting one. If that is the case, I want to get some list of printers.
0
CEHJCommented:
Quite a difficult one to ascertain, i think, as it's not normally an issue or requirement
0
hdhondtCommented:
Many Xerox and hp printers do. I'll have a look for a low cost model later today (it's 7 am here now)
BTW why not use my suggestion of passing the job to Adobe acrobat (or other software). That will work with any printer
0
dkim18Author Commented:
BTW why not use my suggestion of passing the job to Adobe acrobat (or other software). That will work with any printer

>>In our web app, there is an option that check multiple documents and send print queue without opening adobe acrobat.
0
hdhondtCommented:
I cannot see why your script could not send multiple jobs to Acrobat but have a look at the Docuprint 3105. See pages 90-91 of the User  (https://www.google.com.au/url?sa=t&source=web&rct=j&url=https://www.fujixeroxprinters.com.au/downloads/uploaded/DP3105_User_Guide%2520(English)_5ef6.pdf&ved=0CBkQFjAAahUKEwiRuMmh5IbJAhXF36YKHRcCCok&usg=  )
0
dkim18Author Commented:

I cannot see why your script could not send multiple jobs to Acrobat....


The above script just doesn't work for my samsung/brother printer.

The Docuprint 3015 is for small-medium business and it is not really popular in US I think.
I was told 'HP LaserJet Pro P1102W' supports PDF.
0
hdhondtCommented:
The P1102W is a GDI printer, like your Samsung. It does not understand PDF or any printer language.

You'll find that most cheap printers are the same. It costs more to build a language into a printer than it does to let Windows do the work. So you'll always pay more for a PDF printer. High-end Laserjets support it, but they usually need some software to send the PDF. For that matter, even the DP 3105 requires at least LPR (part of Windows) to send the job. Can your script use LPR?
0
dkim18Author Commented:
My co-worker has the P1102W printer and it supports PDF according to him. I know his dev environment is Linux. Maybe that is why?

My script can use LPR, but it will be only for my dev environment since production box is Linux with tomcat.
0
hdhondtCommented:
Linux may do the conversion from PDF to printer bitmap, but the printer itself does not support it. If you look at the specs, you'll see the language is "host based". That means GDI or equivalent. Or, as I said before, the printer does NOT support ANY language, it lets Windows (or linux) do the job of converting the page into dots on the paper.

Linux also supports lpr (it originally comes from Berkeley Unix, before there was Windows).
0
CEHJCommented:
You could probably also use Ghostscript which will convert between PDF and Postscript (on both your platforms)
0
hdhondtCommented:
@CEHJ I suggested that before (as well as Acrobat), but dkim18 says that can't be done with the script.
0
CEHJCommented:
Sorry -  i don't remember that
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Printers and Scanners

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.