I'm using Java's print. I thought a printer only has one resolution.
If you print something at a resolution which doesn't match the printer
resolution it just resizes.
I set the resolution on a printout once and it did that, like if the
printout says 300 dpi and the printer says 600 dpi it shrinks it.
First, I wrote a report writer. The report writer object has methods
(print text, draw image, etc) which create report objects specifying
what I'm printing and where on the page it prints.
I use dynamic printing. I specify how many columns of text to print
across the page. Then I measure my (fixed width) font (Lucida Sans
Typewriter) to calculate the x/y in point measurement.
Then I wrote a print preview. My preview panel extends JScrollPane.
On that pane I draw an image using it's paintComponent method.
I create an image with it's createImage method, set the size equal to a
piece of paper and draw that image on the pane's graphics (from the
paint method) with the drawImage method.
Then I just overrode it's print method to pass the printer graphics into
the paintComponent method to print the image (is there another way I
should/could do that?).
I just pass my preview panel directly into print with this generic
method:
(printComponent is the preview panel passed in)
PrinterJob myPrinterJob = PrinterJob.getPrinterJob();
// Possible Exception
myPrintService = BBsPrinter.getPrintService(myPrinterName);
PageFormat pf = myPrinterJob.defaultPage();
Paper paper = new Paper();
double margin = 36; // half inch
margin = 0;
paper.setImageableArea(margin, margin, paper.getWidth() -
margin * 2, paper.getHeight() - margin * 2);
pf.setPaper(paper);
try {
myPrinterJob.setPrintable((Printable)printComponent, pf);
BBsString.printLogMessage("Printing Printable
Component");
} catch (Exception e) {
myPrinterJob.setPrintable(new
PrintComponent(printComponent), pf);
BBsString.printLogMessage("Printing NonPrintable
Component");
}
// Possible PrinterException
myPrinterJob.setPrintService(myPrintService);
myPrintRequestAttributeSet = new
HashPrintRequestAttributeSet();
if (myCopies != null) {
myPrintRequestAttributeSet.add(myCopies);
}
if (myJobName != null) {
myPrintRequestAttributeSet.add(myJobName);
}
if (myPrinterResolution != null) {
myPrintRequestAttributeSet.add(myPrinterResolution);
}
BBsString.printLogMessage("Printing Graphics Page");
// Possible PrinterException
myPrinterJob.print(myPrintRequestAttributeSet);
public static PrintService getPrintService(String printerName)
throws Exception {
HashPrintServiceAttributeSet myPrintServiceAttributeSet = new
HashPrintServiceAttributeSet();
myPrintServiceAttributeSet.add(new
PrinterName(printerName,null));
// returns sun.print.Win32PrintService implements
java.print.PrintService
PrintService[] printServiceArray =
PrintServiceLookup.lookupPrintServices(myDocFlavor,myPrintServiceAttribu
teSet);
if (printServiceArray.length == 1) {
return printServiceArray[0];
}
throw new Exception("Printer \"" + printerName + "\" not
found");
}
________________________________
From: Marquart, Joshua D [mailto:[email protected]]
Sent: Thursday, August 25, 2011 9:53 AM
To: [email protected]
Subject: RE: How do you smooth fonts?
Attempt to increase your outgoing resolution (dots per inch).
It may create a larger file and take slightly longer, but the resulting
text may be smoother.
-Josh
From: Eric Douglas [mailto:[email protected]]
Sent: Tuesday, August 23, 2011 7:59 AM
To: [email protected]
Subject: RE: How do you smooth fonts?
I did all those rendering hints. It still looks like it has a shadow.
________________________________
From: Glenn Adams [mailto:[email protected]]
Sent: Tuesday, August 23, 2011 1:55 AM
To: [email protected]
Subject: Re: How do you smooth fonts?
enable font aliasing in whatever layer you are using for rendering
On Mon, Aug 22, 2011 at 2:57 PM, Eric Douglas <[email protected]>
wrote:
When I transform XSLFO with FOP I can send the output to PDF or AWT and
text looks sharp.
I'm trying to use the same fonts to generate graphics directly since I'm
programmatically generating the input to my FOP process and I don't
actually need the XSLFO process.
I know exactly what text I want to print, what size I want it, and
exactly where I want it on the page.
I tried putting the text on an image and putting the image on a Swing
panel and it always comes out fuzzy. It's even fuzzier if I try to save
that image to a file or send it to a printer.
I tried using the FOP classes for loading the font, using the
Java2DGraphicsState, FontInfo, and FontMetricsMapper objects to generate
the text. It's always rendered blurry. What could I be missing?
________________________________
The information in this message may be proprietary and/or confidential,
and protected from disclosure. If the reader of this message is not the
intended recipient, or an employee or agent responsible for delivering
this message to the intended recipient, you are hereby notified that any
dissemination, distribution or copying of this communication is strictly
prohibited. If you have received this communication in error, please
notify First Data immediately by replying to this message and deleting
it from your computer.