harwey / cups4j

Cups4j Java printing library for CUPS/IPP
http://cups4j.org
GNU Lesser General Public License v3.0
130 stars 64 forks source link

cannot set resolution & metadata (user & jobname) not set #47

Open marcelser opened 3 years ago

marcelser commented 3 years ago

I'm currently using this code block to print over my remote linux cups server:

org.cups4j.PrintJob printJob = new PrintJob.Builder(payload.toByteArray())
  .jobName("cupboard-api.label")
  .resolution("300x600dpi")
  .userName("cupboard-api")
  .pageFormat("w54h144.1")
  .build();

It prints the document just fine without the resolution but if I look at the job in the CUPS server the jobname and username is not set and the page format is probably also ignored and it only works because that's also the default pageformat of the printer. However I don't know how to look at the exact details of a job like printer settings.

Now comes the bigger problem. If I try to set resolution like "300x600dpi" or "300x600 DPI" I always get a Numberformat Exception because the string is split by ',' and it excpets to get 3 parts. But setting it to "300,600,DPI" also doesn't work because it doesn't like "DPI" so I'm completely lost on how to correctly set the resolution now. This is the lines from the PPD:

*Resolution 300dpi/300 DPI: "<</HWResolution[300 300]>>setpagedevice"
*Resolution 300x600dpi/300x600 DPI: "<</HWResolution[300 600]>>setpagedevice"

Please have a look and fix especially the resolution stuff.

FYI: I'm using cups 2.3.3

Thanks a lot

harwey commented 3 years ago

Hi Marc, have you tried to use the IPP way of specifying the resolution like 300,300,3. 3 Indicates dots per inch, 4 would indicate dots per cm. As a hint for other attributes you might want to set: You can check possible printer attributes with the class org.cups4j.PrinterAttributes in the test package in the project. This class is a simple gui that will show all printers from localhost.

Regards Harald

marcelser commented 3 years ago

Hi Harvey,

I tried setting the resolution in ipp way with 300,600,3 which does not result in a NumberFormatException and the print job runs. But it is ignored although the printer reports of beeing able to accept resolution attribute. But maybe it also expects some kind of string or sth. But it always get's printed in the way the printer settings are set to, but not what I pass it as parameters

harwey commented 3 years ago

Hi Marc, You could try to set LogLevel debug2 in /etc/cups/cupsd.conf restart cups and check your logs to see if cups f.ex. tells that it ignores those values and why they are ignored. This would help to see what exactly happens in your setup. Also you might send a complete code sample to check your code. Harald

mm-mkkm commented 3 years ago

@marcelser I had a similar sort of issue, when I was trying to define the .pageFormat("iso-a5"), it didn't print in a5 size as I expected. Rather was printing in a6, which is my printer's default setting. Then I figured out that if I were to use .pageFormat("dnp6x8") instead, it was able to print correctly as expected in a5 size, though my printer's default settings still is a6. So the real question is where did I get this string dnp6x8 ?. I got it from my printer's ppd file which is usually located in /etc/cups/ppd/. Probably, if you could look into your printer's ppd file and figure out what this text is and use it, I guess it should override the default settings. Please let me know how it goes. Curious to know how it went. Cheers, Mani

gmuth commented 12 months ago

By using ipp-client you can set the resolution via printerResolution(300,600,DPI)