Java printing of custom Swing Components

If you are implementing printing in Java, there is a really good tutorial showing how to add printing support to any Swing component. Printing generally works very well and we use it in our PDF library to provide printing of PDF files. The example uses a PrinterJob to print via Java – essentially, your Swing…

Read More

Java File handling – when is a file actually saved

Consider the following code…. File ff=File.createTempFile(“page”,”.bin”, new File(ObjectStore.temp_dir)); BufferedOutputStream to = new BufferedOutputStream(new FileOutputStream(ff)); to.write(currentDisplay.serializeToByteArray(null));          to.flush();            to.close(); pagesOnDisk.put(key,ff.getAbsolutePath()); It stores a serialised Java Object (currentDisplay) on disk and then stores the file location so we can reuse it. So in theory,  if the value is in the Map pagesOnDisk, we should…

Read More

Printing PDF files from Java

Printing PDF files from Java is something that raises a lot of general questions, so this short article is a general guide to the options available. Java itself contains a built-in print system (JPS). JPS itself does not internally support the PDF file format. There are 3 ways to print PDF files in Java:- 1…

Read More