tip

You are currently browsing articles tagged tip.

Printing is not an easy task.  It is easy to get tied into intricate details of environment specific configuration settings such as margins and paper size. Therefore, printing a PDF without a library is not recommended unless you have a lot of time or are really interested in that sort of thing.  There are two libraries that can perform this task already.   One will be exampled today, and another tomorrow.

Today’s library is PDFRenderer https://pdf-renderer.dev.java.net/.   This library was released by Sun a couple of years ago.   Note that this example does not map a FileChannel object as some examples do.  Using a FileChannel made the file not able to be deleted until garbage collection was run.  See the bug in the code comments for more details.

try
{
File f = null;
RandomAccessFile fis = null;
FileChannel fc = null;
ByteBuffer bb = null;
String printer = YOUR_PRINTER_NAME;
PrintService printService = PrintHelper.getPrintService(printer);

f = YOUR_PDF_FILE;
//Read only access would work too
fis = new RandomAccessFile(f, "rw");
fc = fis.getChannel();
bb = ByteBuffer.allocate((int)fc.size());
fc.read(bb);


//Do not map the file to a ByteBuffer as the examples show.
// There is a reason why in java bug #474038
// http://bugs.sun.com/view_bug.do?bug_id=4724038
//fc.map(FileChannel.MapMode.READ_WRITE, 0, fc.size());
//bb = fc.map(FileChannel.MapMode.READ_WRITE, 0, fc.size());

PDFFile pdfFile = new PDFFile(bb); // Create PDF Print Page
PDFPrintPage pages = new PDFPrintPage(pdfFile);
// Create Print Job
PrinterJob pjob = PrinterJob.getPrinterJob();
pjob.setPrintService(printService);

PageFormat pf = PrinterJob.getPrinterJob().defaultPage();

pf.setOrientation(PageFormat.PORTRAIT);

Paper paper = new Paper();

//This is to fix an error in PDF-Renderer
//View http://juixe.com/techknow/index.php/2008/01/17/print-a-pdf-document-in-java/ for details
//Printing a PDF is also possible by sending the bytes directly to the printer, but
//  the printer would have to support it.

paper.setImageableArea(0,0,paper.getWidth() * 2,paper.getHeight());

pf.setPaper(paper);

pjob.setJobName(f.getName());

Book book = new Book();
book.append(pages, pf, pdfFile.getNumPages());
pjob.setPageable(book);
pjob.print();

}
catch (FileNotFoundException e)
{
//do your error action
}
catch (IOException e)
{
//do your error action
}
catch (PrinterException e)
{
//do your error action
}
finally
{
try
{
if (fc != null)
{
fc.close();
fc = null;
}
}
catch (IOException e)
{
log.error(e);
//handle error here
}
try
{
if (fis != null)
{
fis.close();
fis = null;
}
}
catch (IOException e)
{
//handle error here
}
if (bb != null)
{
bb.clear();
}
}

Because this library has the bug that makes it not want to print in half size when printing a portrait-oriented PDF,  I cannot recommend using this library unless you find it is the only thing that will do the job.    Such obvious bugs that have been around for over a year point to unmaintained code or some other upstream issues.  Tune in tomorrow for another library that is maintained that will get the job done as well.

Tags: , ,

You’re trying to connect to an OS X box and your vnc viewer just doesn’t seem to work. Then, after many a google serch, you discover that OS X’s remote access protocol is incompatible with most VNC servers.  Tuning to Apple for help yeilds a solution, for a small(large) fee.

Thankfully, there is a better way.  There is a free VNC server for OS X called Vine.  Download it and install the server.  Now you should be able to connect through a typical VNC client.

Remember, if you use tightVNC to connect, use the F8 key to bring up the menu that allows you to switch to fullscreen and disconnect the session.

Tags: , ,

The storms that went through yesterday had an interesting effect on the available wifi networks in the area.   It wasn’t so much the storms that caused this, it was more the lack of power in the area when the lightning started striking.   Here is what the wireless situation looks like with and without power:

Before power goes out

Before power goes out

A UPS on internet equipment is something that I haven’t seen in too many places.  Apparently, not many people in my complex have heard of it either.

Power just went out

Power just went out

And finally, I win.  The Xantrax Xpower 400 actually kept the Internet up for over 8 hours after the power outage.

I stand alone

I stand alone

Of course, the server didn’t do as well, and I had to turn it down after 20 minutes.  It’s tough to have 99% uptime off of home DSL.

Tags: ,

Some content is taken from http://forums.ebay.co.uk/thread.jspa?threadID=1200182458.

I tried to link my ebay account to my paypal account and it would just simply not work. After going through the prompts many times, it would still say that there was no association. There is a fix in an odd location.

Go to account settings -> addresses
Click on all addresses
Then click on add paypal addresses

This gives yet another paypal login. After login, I was greeted with a message thanking me for creating a paypal account. Hmmm.

Tags: ,

Sometime, you just don’t know which dll files to register.  Enlighten yourself with dependancy walker .

Tags: , ,

They’ve been out for over a year, but I just stumbled upon them this week.  Redhat release some very high quality and non-encumbered fonts.   Most distibutions will have them in a package named liberated-fonts.  They are substitues for some very popular fonts such asTimes New Roman, Thorndale, Nimbus Roman, and Bitstream Vera Serif.  Check em out at https://www.redhat.com/promo/fonts/.

Tags: ,

Check out http://www.favicon.cc/ for your various favicon needs.

Tags: , ,

When double clicking on apps don’t seem to open the correct program anymore on almost every file, there is most likely an issue with the MIME database.  The MIME database tells the desktop environment which program should open a file.  Try this to re-associate things.

update-mime-database ~/.local/share/mime

This tip was found after searching the net and landing on this page.

Tags: , ,