Apr 4, 2009

Blog moved to new site

Could not import the blog posts and comment here to my wordpress blog. Had to copy and paste the posts instead without the comment.

Please update your bookmark :)

Future post will be updated at moongster.com

Labels:

Jan 19, 2009

Tiff to PDF Conversion

On a certain Friday evening, just as you're about to head home for a relaxing weekend, you were informed that the client was expecting pdf files, while the images scanned were in tiff format. So, what can you do?

First option, we can download a free pdf writer (such as CutePDF) and painfully print each image to pdf format. Bear in mind that each image may contain thousands of pages, so the pain is multiplied by a thousand times!

Second option, look for a way to convert the files in batches.

I took the first option to see if our files were possible to be converted in the first place. OK, so this was possible and would provide me with a fallback plan.

Next, I took on the second option. Majority of the batch conversion programs need to be purchased. Since this extra work was not covered in the original project costing, no budget was available. So, I decided to look for an open source library and hack together a little program to do the batch conversion.

In the end, I used iTextSharp, and developed a program on MonoDevelop. The little program, known as TiffToPDF (duh!) is available here for free. Hope it'll be useful for those who need it!

To run this program, you'll need to install .Net 2.0 Framework. Next, you need to download the iTextSharp dll and place it in the same folder as TiffToPDF.exe.

Limitation: Doesn't work for Tiffs with JPEG compression in them. This is due to exception in loading the bitmap, the same issue you get when you try to load them in MS Paint or Windows Viewer.

Labels: ,

Sep 12, 2008

CakePHP 1.2 - Cancel button for form

I was looking for a solution to create cancel buttons for the add/edit views that allow user to return to the list view.

Ways I have tested but did not work too well:
1) Creating a button and redirect to list view using javascript (href.location). This generates an error of not having access to the specific directory.
2) Using history.back() or history.go(-1) to go back to previous page. This does not work well if user tries to add and fail validation multiple times, it would only return user to the previous page with those validation error messages and not to the list view.

I came up with this solution after much research and testing.

For example, in the add view, I have this:

<?php
echo $form->create('Post');
echo $form->input('title');
echo $form->input('body', array('rows' => '3'));
?>


<?php echo $form->submit('Save Post', array('div'=>false, 'name'=>'submit')); ?>
<?php echo $form->submit('Cancel', array('div'=>false, 'name'=>'cancel')); ?>


<?php
echo $form->end();
?>

And, in my controller add function, I have this:

if (array_key_exists('cancel', $this->params['form'])) {
$this->flash('Cancelled adding new post.','/posts');
}
else {
if (!empty($this->data)) {
if ($this->Post->save($this->data)) {
$this->flash('The Post has been saved.', '/posts');
}
}
}

With the above solution, we can also extend to further check for other button clicks and allow the controller to react accordingly.

Labels: ,