Thursday 30 June 2011

Scanning to PDF using .NET

I had a request recently to modify a .NET application I wrote years ago. The application was scanning letters and store them in SQL database linked with specific record. The new requirement was to allow saving these scanned documents as Acrobat Reader (.pdf) files.

First time I used iText API - http://www.itextpdf.com/itext.php

After I scan the document I save it as pdf like this:

public static bool SavePDFAs(string picname, IntPtr bminfo, IntPtr pixdat)
        {
            SaveFileDialog sd = new SaveFileDialog();

            sd.FileName = picname;
            sd.Title = "Save file as...";
            sd.Filter = "PDF file (*.pdf)|*.pdf";
            sd.FilterIndex = 1;
            if (sd.ShowDialog() != DialogResult.OK)
                return false;
            
            Document doc = new Document(PageSize.A4);

            try
            {
                FileStream PDFfs = new FileStream(sd.FileName, FileMode.Create); 

                PdfWriter.GetInstance(doc, PDFfs);

                doc.Open();

                Bitmap bmp = BitmapFromDIB(bminfo, pixdat);
                
                bmp.SetResolution(300, 300);

                byte[] imageBytes;

                using (MemoryStream ms = new MemoryStream())
                {
                    // Convert Image to byte[]
                    bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                    imageBytes = ms.ToArray();
                }

                bmp.Dispose();

                iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(imageBytes);
                
                png.ScalePercent(24f);
                png.SetAbsolutePosition(0, 0);

                doc.Add(png);
            }
            catch (DocumentException dex)
            {
                MessageBox.Show(dex.Message);
            }
            catch (IOException ioex)
            {
                MessageBox.Show(ioex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
            finally
            {
                doc.Close();
            }

            return true;
        }

Wednesday 29 June 2011

Some great free iPhone apps

I've been doing a research for apps I can install on iPhone 4 before ordering one.I’ve had my iPhone for couple of weeks so I could try those apps that I could not try on the iPod and find some new ones in the process. This is the list of free apps I have installed and find quite useful:

GooCal (Google Calendar™ sync) By

Tuesday 28 June 2011

Office SharePoint Server Search crashing

I've had Office SharePoint Server Search service crash several times in the past couple of years. Normal service restart made it hang and crash completely. Service status got stuck in Stopping and there was no way to restart it.
.

A quick server reboot would bring things back to normal but apparently there is a quicker way to solve this problem:

You can kill the service using this command:

taskkill /F /IM mssearch.exe /T
 or you can open the task manager in the MOSS box and end 'mssearch.exe' process.

After you kill the service using any of the two methods above, make sure you start the service and in few minutes MOSS search will be fully functional.

Wednesday 22 June 2011

Network Attached Storage (NAS) for home use


After several little scares that I recently had with my family photos and videos, I decided I need to shift and get some backup sorted.

First I looked into external USB drive but soon realised that Network Attached Storage (NAS) would suit me much better. In my household there are 2 desktop PCs, one notebook, one llaptop and one MacBook. Consuming LAN also are 2 xbox consoles, Wii console, 2 DS handhelds, 2 iPods and 2 smartphones too. So rather than sorting out the backup manually from each device into external USB drive, I decided to get a server sorted so I can backup and share data.

So I looked and searched anything I could find available for home use and in the end settled for QNAP TS-210 and 2 x 2Tb Seagate ST2000DL003 drives.Full package just under £260. Two external USB drives of 2Tb each would cost me in the region of £140 so almost half of what I paid for NAS but I felt that USB drives would just end up like extra storage and that's it - fragmented backup, poor file sharing, etc.

Here are some of the factors that made me decide to go for NAS:

Backup, backup, backup. With 2Gb (in Raid 1) should be able to backup all devices (not just one or two PCs). I should be able to sleep much better knowing that all my computers are backed up. Also organising backups will be much simpler since all devices will have hassle free access to NAS.

Streaming. Big bonus is the option to watch family videos from any device in the house. Or stream music to any device. Or build the DVD library easily accessible. I plan to use the main Sony Bravia TV, iPod, iPhone and Notebooks as and when needed.

Access. I want to be able to drop files in and get them out when ever and where ever I am. I can think of several times when I could do with this feature when I was at work, shopping, on holiday, etc.

Convenience. All devices can connect to it directly without having to have any particular PC switched on. Sharing the printer as well is a great bonus as I was getting really annoyed having to switch on the PC connected to the printer.Also having all photos, all videos and all music in one place is a great bonus too. With NAS all photos, videos will go in the same place. Same for music we buy online. It is going to be easier to organise too. Documents will be stored on it centrally too, so it won't matter any more which PC we were using last time we worked on a document.

Tuesday 21 June 2011

MonoTouch - use C# and .NET to create iPhone, iPad, and iPod Touch applications

I was totally surprised when I stumbled upon MonoTouch today. Even more so when I read that it has been out for quite some time.

Basically: "MonoTouch allows developers to create C# and .NET based applications that run on Apple's iPhone, iPad, and iPod Touch devices, while taking advantage of the iPhone APIs and reusing both code and libraries that have been built for .NET, as well as existing skills."

If you were developing using C#  and .NET like I was for the last 8 years then you'll be very happy with this news. Of course you will still need a Mac with Intel processor but you'd need that with Xcode too.


However, my enthusiasm faded immediately when I saw the prices:

Professional Enterprise Enterprise 5 Student
Develop iPhone/iPod Touch applications
checkmark-green.png
checkmark-green.png
checkmark-green.png
checkmark-green.png
Ad-hoc distribution
checkmark-green.png
checkmark-green.png
checkmark-green.png
checkmark-green.png
Commercial Use
checkmark-green.png
checkmark-green.png
checkmark-green.png
Apple AppStore distribution
checkmark-green.png
checkmark-green.png
checkmark-green.png
Enterprise distribution 
checkmark-green.png
checkmark-green.png
License expiration Never Never Never Never
Product updates 1 Year 1 Year 1 Year 1 Year
License Ownership 1 Named User 1 Seat 5 Seats 1 Seat
Price (USD)  $399  $999  $3,999  $99

I will try the demo but more likely I'll stick to Objective-C for now... at least until I can see how it goes taking one project from start to finish. I'm saying for now, but knowing me, by the time I'm rolling out apps I'll be used to Objectice-C and Xcode so I will not want to make a change.

iOS Developer Programs

I was just checking the iOS Developer Program and prices. I think I’ll wait until I have some app ready before I give them $100 as it is annual charge.

Got my iPhone 4 (finally)

Ever since iPhone first came out I've been thinking about getting one, but could never justify the price. Everything that I could do in iPhone, I could do in my Nokia phone (which costs less than half of what iPhone costs).

Well, Nokia got old, scratched and broken so the time came to get a new phone. And this time I went with the trend and got an iPhone 4. I'm hopping it will replace my camera and flip so I don't have to bring them when I go out and about. Also no need for my iPod touch any more. I can put all my music in the iPhone and my kindle books too.

So yeah, I installed a bunch of useful apps and I think I barely scratched the surface. It is mind-blowing how many apps are in the App store.

I'm planing to do a run-down of all apps I find useful in a week or two. Hopefully I will soon write my own app to go in that list too. The biggest problem will be to develop something new, because anything you can think of, it's there... and it is usually free.

Wednesday 15 June 2011

Cool Snow Leopard features I did not know about

Found these video podcasts accidentally today and they were a big revelation for me. How come these things don't reach us Windows people? I really think some features on OSX are way ahead of Windows and I don't think enough people know about it, which is why I thought I best spread the word.

Automation in Snow Leopard:
http://www.podtrac.com/pts/redirect.mov/pixelcorps.cachefly.net/mbkv_235_540p_h264.mov

Automation in Snow Leopard (part 2):
http://www.podtrac.com/pts/redirect.mov/pixelcorps.cachefly.net/mbkv_236_540p_h264.mov

Automation in Snow Leopard (part 3):
http://www.podtrac.com/pts/redirect.mov/pixelcorps.cachefly.net/mbkv_237_540p_h264.mov

Tuesday 14 June 2011

Key Remap for MacBook

I've been searching the net for days to find a solution for a keyboard problem I have on my MacBook.

Basically, for an unknown reason to me, the Caps Lock key is bound to Left arrow key and no matter which one of these two I press, I get both functions: Caps Lock changes ON/OFF and cursor moves to the left.

Similar, for Ctrl key and number 8 key, but not quite the same. When I press either of these two, I get only Ctrl function. This means I don't have number 8 or * in my keyboard. To say the least it's been very annoying and I just couldn't find any solution anywhere.

Today after repeated searching I stumbled upon this application KeyRemap4MacBook (http://pqrs.org/macosx/keyremap4macbook/index.html). First thing I'm going to do when I get home is install it and see what happens. I hope it will pick up the two sets of bonded keys and give me an option to either remove it or overwrite with a new setting. Fingers crossed...

Friday 10 June 2011

Addictive Speed Run in DiRT 3

So far I think these challenge game modes, like speed runs, are the only improvement form Dirt 2. I spent some two hours last night to nail this speed run for a platinum medal. You can make uploads direct to youtube but they are fairly low quality, take ages to prepare and upload and the maximum clip length is 30 seconds. I had  to upload two clips to youtube for this one, download them from youtube and put the together in Windows Movie Maker before uploading it as one clip. I definitely need to get a capture device.

Wednesday 8 June 2011

Developing Objective-C on Windows PC


As I'm using Windows PC most of the day I wanted to look into finding a way to try and learn Objective-C while on Windows PC. I just managed to compile and run my first "Hello World!" code so thought might be useful to make a note how I got there.

I thought I'll be able to find something I can plug-in to Visual Studio to be able to write and compile Objective-C but couldn't. Searching the internet I found a Mac forum where number of people asked the question - how to code Objective-C in Windows PC? The answer was short (Apple style) - Go to www.gnustep.org!

So visited GNUstep site and found GNUstep installer for Windows: www.gnustep.org/experience/Windows.html. From this page I downloaded and installed in order (as advised in the page):


GNUstep MSYS System Required 0.28.1 - MSYS/MinGW System
GNUstep Core Required 0.28.0 - GNUstep Core
GNUstep Devel Optional 1.3.0 - Developer Tools

The installation procedure created a program group in the Start/All Programs menu called GNUstep and in there I found Shell application which simulates Unix console.

I used Notepad to create a simple Objective-C file:

#import <Foundation/Foundation.h>

    int main (int argc, const char * argv[])

    {

        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

        NSLog(@"Hello World!");

        [pool drain];

        return 0;

    }

and saved the file with ".m" extension. When I tried to compile it the first time it failed to find the file so I moved it under C:\GNUstep\msys\1.0\home\dreriMIX folder which was created by the installer.

I ran the command
gcc `gnustep-config --objc-flags` -L /GNUstep/System/Library/Libraries objC1.m -lgnustep-base -lobjc
and that created an application called a.exe which when I run (use ./a in the console) I get:

2011-06-08 11:27:14.354 a[20272] Hello World!

Success!

Starting to develop for iPhone

I've been thinking for a while that it would be great to develop some little mini-apps for my iPhone/iPod. I'm a total Apple n00b but finally, I decided to bite the bullet and look into it.

First of all I was pleasantly surprised when I found out that I need to use Objective-C. I used to love programming on C some 20 years ago.

Then I looked in what I need:
  1. Mac computer, going to use MacBook.
  2. Sign up as to become registered iPhone developer... done in 2 minutes.
  3. Download the software development kit - got Xcode 3.2.6... long download...
  4. Then I realise that I have Leopard (OS X 10.5.x) so had to upgrade to Snow Leopard (OS X 10.6.x) in order to use this version of Xcode.. oh well, ordered from Amazon Mac OS X version 10.6.3 Snow Leopard.
  5. Got some books:
    Programming in Objective-C 2.0 (2nd Edition) by Stephen G. Kochan
    Learn Objective-C on the Mac (Learn Series) by Mark Dalrymple, Scott Knaster
    Beginning iPhone Development: Exploring the iPhone SDK by Dave Mark, Jeff LaMarche 
  6. Bookmarked some links:
    iOS Dev Center
    Objective C Programming Language (Apple site)
    iDeveloper TV
So I'm ready to go. AppleWorld, here I come!

Portal 2

I've recently had a 5 days Portal 2 marathon. I rented the game from Blockbuster as spur of a moment and had to concentrate on it to try and finish it.

If you have played the original Portal game from Orange Box or Portal arcade game then Portal 2 will not be a novelty for you. If my memory serves me right it looks very similar and the gameplay is more or less the same. Even though I have not played Portal for couple of years, when I started Portal 2 I was a bit disappointed they have not changed it a bit more. But as I started solving the puzzles I realised that there are plenty new types of puzzles so the game started to bewitch me as the original game did.

In total there are two sets of maps, one for single player and the other for co-op game mode.

The single player maps can be played during the story mode or with developer commentary, which is a great touch. Story mode is great. You get brilliant puzzles to solve using all sorts of chamber features (won't give any details as it might spoil it for someone), the story is interesting and Glados is as funny as it was. You can also choose to play the game with developer commentary which is the same as the story mode except you can't save and you get comment bubbles here and there to open the developer's commentary.

Co-op section does not run as a story but you do have to play it sequentially the first time you play. You get one learning chapter and then another 5 chapters with different types of puzzles to solve. The puzzles are absolutely brilliant, simply work of a genius. You can play co-op on split screen or via xbox live. If you play over xbox live you can play with friends or any random dude. You do get a reminder from developers that the game is best played with friends and there is a reason for that. Communicating during puzzle solving is great part of the gameplay. Not just in working out how to get form a to b, but the banter around it is priceless. You can create traps for each other and laugh your head off with comments from Glados and the different ways you can die.

I had to take it back but will definitely buy the game to finish the remaining 2 co-op chapters.

9/10 from me :D

Wednesday 1 June 2011

Gears of War 3 trailer

Probably seen it but in case you haven't here it is:



I was a bit disappointed, I thought they'd show us a bit more story details. We knew Adam Fenix
Image

was going to have a part (from the teaser they showed before). So unless I'm missing something there isn't anything knew on this trailer.