Link to home
Create AccountLog in
Java

Java

--

Questions

--

Followers

Top Experts

Avatar of mariec
mariec🇨🇦

java.awt.print VS javax.print
Hello everyone,

I have to create a class that will print out a document that has a barcode (graphic) in it. This document will be created in the code (don't know which type of object yet) and does not come from the HD (maybe this makes a difference, i don't know).

I've been reading about different ways to acheive this and found that there are many packages that offer printing possibilities.

My question is, what's the main difference between JAVA.AWT.PRINT and JAVAX.PRINT ? Which one would be best ?

Thanks

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of mariecmariec🇨🇦

ASKER

Points increased.

Avatar of mariecmariec🇨🇦

ASKER

since nobody seems to really know this, are there any examples of how to print some text with some images? Is it possible to format the elements on a page ?


ASKER CERTIFIED SOLUTION
Avatar of johnknappjohnknapp

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of mariecmariec🇨🇦

ASKER

Thanks, this looks like what i needed.

Is the PrintableDocument interface from the com.davidflanagan.examples.print package? If not, does is implement Pageable and Printable anyway?

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


SOLUTION
Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

SOLUTION
Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

By The By,

where did you get the info on the bar code stuff, which bar code is it? I have a client in which I had to use a third party software package for bar coding . . . I couldn't find the open standards, except for the really simple barcodes . . .

Oh and I also forgot,

If you want to print without user intervention and send the stuff to a chosen printer directly, you can bypass the whole print dialog with code similar to the following

Cheshire2UpPrintableDocument cheshDoc = new Cheshire2UpPrintableDocument(); // pretend already initialized

PrintService[] services = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);

/*
 * I have a client properties thing where I keep a default printer stored, and then get the correct print service this way
 */
String dpName = ClientProperties.getString("defaultprinter", null); // gets the value specified by key defaultprinter, with null as a backup value if not found
PrintService defaultPrintService = null;
if (dpName == null) {
    // tell client no dp printer chosen
    return;
} else {
    for (int i = 0; i < services.length; i++) {
        if (serivces[i].getName().equals(dpName))
            defaultPrinterService = services[i];
    }
}

if (defaultPrinterService == null) {
    // warn user could not find default printer -maybe disconnected ? or name changed? have them rechoose
    return;
}

try {
    cheshDoc.print(defaultPrinterService); // or whichever one matches the criteria
} catch (Exception e) {
    // handle print exception
}

Avatar of mariecmariec🇨🇦

ASKER

I doubled points because this is very helpful and more than I was expecting!


The barcode stuff comes from a third party package (ww.java4less.com) that our client gave us for developing their solution. Usually it is distributed as a package but they got the source code and in it is says that it can be modified for our needs. There are many standards included.

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.

Java

Java

--

Questions

--

Followers

Top Experts

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.