Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8863779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:04:27+00:00 2026-06-14T16:04:27+00:00

I’m working on the printing system, and need to add arbitrary text to each

  • 0

I’m working on the printing system, and need to add arbitrary text to each printed document (like author, document hash, some sysvars and else). We use Java Printing Service (javax.print) as printing client and Cups as server.

Cups has some procedures of document postprocessing called “filters”.

Filter – is a program, that will be launched by Cups. Cups passes filter some params – “job attributes” among them.

So, I decided to pass custom attributes from java to cups and add attributes as text to document in filter. Everything works without exception, document is printed, but I don’t get my attributes in filter. They are not even passed to Cups (saw that in packet sniffer).

I already used getSupportedAttributeCategories() to see the list of supported (by printer?) attributes. Maybe I should somehow add mine to that list, but I don’t understand how.

I’m not limited to “attributes”, I just need to pass arbitary data from java to Cups filter. How can I do it?

My java code is like:

MyAttrSet attrs = new MyAttrSet();
attrs.add(new MyAttr(42));
attrs.add(new Copies(18));  

PrintService service = PrintServiceLookup.lookupDefaultPrintService();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc doc = new SimpleDoc(is, flavor, null);
DocPrintJob job = service.createPrintJob();

job.print(doc, attrs);

Filter is a simple bash script, that prints everything passed to it:

#!/bin/bash
echo "All args:" > /tmp/f1.log
for var in "$@"
do
        echo "$var, " >> /tmp/f1.log
done

/tmp/f1.log looks like:

All args:
87, 
oroboros, 
 Java Printing, 
18, <- number of pages is passed! But not MyAttr
some useless crap like job uuid and else...

MyAttr:

class MyAttr extends IntegerSyntax implements PrintRequestAttribute {

    protected MyAttr(int value) {
        super(value);
    }

    public Class<? extends Attribute> getCategory() {
        // TODO Auto-generated method stub
        return MyAttr.class;
    }

    public String getName() {
        // TODO Auto-generated method stub
        return "somemycustop5";
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:04:28+00:00Added an answer on June 14, 2026 at 4:04 pm

    You can use cups4j

    Map attributes = new HashMap();
    attributes.put("job-attributes", "print-quality:enum:3#media:keyword:iso_a5_148x210mm");
    printJob.setAttributes(attributes);
    

    See the following article of how CUPS upgrade on Linux broke Java libraries and CUPS libraries:
    http://www.cups.org/articles.php?L433+TFAQ+Q

    Now, since you can print I assume its not an issue. But I am not sure what MyAttrSet is, it should be a HashPrintRequestAttributeSet.

    try:

    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(2));
    

    See if this attribute is read in, then try adding yours to such a set, does it work or not.
    You might want to try implementing other Attributes:

    The Sides attribute looks like this:

    public class Sides
      extends EnumSyntax
      implements DocAttribute, PrintRequestAttribute, PrintJobAttribute
      {
      public final Object getCategory()
        {
        return Sides.class;
        }
      ...
      }
    

    Similarly Copies:

    public final class Copies
    extends IntegerSyntax
    implements PrintRequestAttribute, PrintJobAttribute
    

    perhaps try adding the additional implements of PrintJobAttribute

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.