Friday, October 24, 2014

An ode to my beloved grandfather

A few lines that I penned (typed) out in the couple of minutes after hearing about the loss of a loved one .Helped with the mourning process
An ode to my thatha

The heart stops, The blood gets stagnant
The body starts to get cold
I watch it all confused for that body was I


Relatives come check the pulse of the now dead me
Sorrow and cries frantic calls to doctors and family
I watch from my chair confused and flustered
For it has not sunk in


The body cage is finally cremated
I have no body to return to
Now I know I have clinically died


Was that really me?
Who am I Oh Lord for I have lost my identity


A Divine light shines engulfing me and my surrounds
I hear the cosmos within me and around me
A set of Golden stairs in front beckon
I bless my family for its my time to go
In a second my whole life flashes in my mind
Oh what a glorious life I have had


I start to climb the stairs
I climb and climb and climb
For 3 days and 3 nights I climb
There is no tiredness no fatigue
I am growing younger
I am now the lad I once knew at 18
Full of joy and life

I come to the end of my journey
I see all my loved ones
People whom I seem to have known for an eterntiy
I merge with my divine family
I am now part of them and they are part of me
Joy permeates me 


Friday, June 27, 2014

Apaches PDFBox

With 2 kids to manage I am always looking out for interesting activities to keep them occupied and not tear down the house The elder one is now taking an interest in writing and reading so I download worksheets for her print them out and hand them to her .I need to print 20-30 pages for her on a daily basis so I wrote a small program to merge pdfs by directory ,name etc. I had used IText before but PDFBox is even easier
public void mergeFiles(File[] filesInFolder, String destinationFile)
   throws COSVisitorException, IOException {
  PDFMergerUtility mergePdf = new PDFMergerUtility();
  for (File file : filesInFolder) {
   mergePdf.addSource(file);
  }
  mergePdf.setDestinationFileName(destinationFile);
  mergePdf.mergeDocuments();

 }

List out all files that have an extension of pdf

class PDFExtFilter implements FilenameFilter {
  private String ext;

  public PDFExtFilter(String ext) {
   this.ext = ext;
  }

  public boolean accept(File dir, String name) {
   return (name.endsWith(ext));
  }
 }

private static final String ext = ".pdf";

private File[] getFiles(String folder, PDFExtFilter filter) {
  File dir = new File(folder);
  File[] filesInFolder;
  filesInFolder = dir.listFiles(filter);
  return filesInFolder;
 }
When files are encrypted we will need to decrypt them first then ask PDFBox to merge them

public void decrpyt(String folder, File[] files) 
throws IOException, CryptographyException, COSVisitorException {
  for (File file : files) {
          PDDocument doc=null;
   try{
   doc = PDDocument.load(file);
   if (doc.isEncrypted()) {
    doc.decrypt("");
    doc.setAllSecurityToBeRemoved(true);
    doc.save(file);
   }}
   finally {
    doc.close();
   }
  
 }}