Thursday, March 29, 2018

Generate Image from PDF in .net core

Generating image from PDF is one of the general requirements that we come across during our project development. PDF being most accepted document format worldwide, and showing thumbnail image of the first page is expected.

Similar requirement I stumbled upon, and paid components such as Aspose.PDF comes to your rescue, but they do  provide many other features along with  PDF to Image converter which, we might not need and off course you need to shell out $900 plus for such library.

Step back and think: 
- First, how does windows 10 shows image of PDF document page. There might be some executable that generated it. BINGO!! you are right. 
- Now next question, can we save it as PDF from our word processor? Oh my god, you are getting it all, YES!!
- Right, so we need to find an executable that does so. YES. 
- Next question is can we call the shell command from c# .net core. Oh come on this is a silly question, YES of course.

Alright, so we have all the answers to our questions. 
Now with such a big open source community, determined to provide everything we need free of cost, there must be some executable to do such work.
YES it is. 
"Where there is will there is way."

Kool (Cool), just browse the following link:

http://blog.alivate.com.au/poppler-windows/

Here you will find executable's that will help you in doing lot of PDF related operations, that you can integrate in your code.

The executable that is of interest to us for generating image is pdftoppm.exe
The below line will generate image from PDF.

var process = System.Diagnostics.Process.Start(execuatble, arguments);

command line sample to generate image is:

pdftoppm -f 1 -l-1 -png scale-to 200 "filetoconvert.pdf" "image_file.png"

-f is for first page which I have give 1
-l is for last page which is again 1 as I just want one page to be generated as image.
-png is the image format to generate
-scale-to is the parameter where you can define size of the box.



followed by two parameters : first one is the PDF file you want to convert and second one is the image file to generate.

You can see all the parameters required by the following command.
pdftoppm -help

The above will list all the arguments acceptable.

Hope you guys liked my post.

Happy Coding!!
















Monday, February 19, 2018

Setting up ASP.net Core


ASP.net core is nothing but leaner version of ASP.net 4.x.
It is more open source oriented version, providing unified platform to build web apps and API's.
More importantly it is platform independent too you can easily install and run it on Mac and Linux machines too with obvious support of its parent OS - Windows.

The following benefits can be derived from ASP.net core :

- Supports easy integration with client side frameworks such as  Angular and React. Templates for both type of projects are there.
- It has support for Typescript too, which is widely used for JavaScript programming these days.
- It has cloud ready configuration system.
- Built in Dependency Injection
- A light weight and high performance and modular http pipeline
- ability to build and run Windows, Mac and Linux

So far so good..

Installing  Core framework


  1. Go to url http://dot.net
  2. Click on Download
  3. Select Download .net core sdk
  4. Install it on your computer.
Once this is done you can go to command prompt and type
> dotnet --version

The above command will show you the version that is installed on your machine.

IDE to be used for development

You can use Visual Studio Code IDE to develop ASP.net core applications.
To download it, go to url - https://code.visualstudio.com/download

Once you are able to install it you can open it and explore around it.

In the next post I will create ASP.net core web API project.









Saturday, February 3, 2018

Beginning of new adventure

With the start of the New Year (2018) , I am looking at complete new beginning of my career as well as my life.  I am moving to Sydney, Australia from India.  Wow!! This looks exciting. Yes it is, but some of my friends look at it as a brave decision, at this point of life.  If there is any thing uniform in this universe is change,  and this has hit me big on September of 2017.
Looking at it, gives me opportunity to find change or rewrite myself which one could not do while living in a setup for long. Culturally diverse and starting from scratch gives you motivation to work towards filling in your short comings and makes you push hard to achieve the desired results.
It is still early days but looking forward to the challenge life has thrown at me.
I will keep posting my new adventure from time to time.
Looking for best wishes from you all

Monday, August 17, 2015

Memoir of Amsterdam













 






Sunday, May 10, 2015

Missing my silent, devoted companion.. Tipsy

Tipsy, my 10 year old german shepherd left us on 3rd April, 2015. I never realized when he became part of my life.   A german shepherd with rare white and black color, was a very handsome and beautiful dog. He was healthy and we raised him on vegetarian diet.  When we brought him to our life, he was of 20 days and was not even able to walk steadily. He used to wobble dabble here and there while he walked like a tipsy. So we named him Tipsy.
He filled a huge gap in my life, of being a companion. I used to take him out for a walk twice a day – morning and evening. He always used to wait for me when I was away and waited for me for dinner till I was back home. 
The nature and persona of Tipsy was such that whoever met him even for a while had instantly became fan of him. There are many family’s who opted for pet after seeing or meeting Tipsy. 
For us he was like another family member. My mother never leashed him. We always kept him free in our house. He always lived with us. The bonding of Tipsy with me was very close. He never left me even for a second when I was home. He slept with me in my room and we were together on weekends and played together. He used to be a happy guy whenever we played together.
He was very intelligent and humble German shepherd.  I remember how he befriend with my wife when I got married. She was very scared of dogs. She came from family who didn’t had any pet ever.  After few days after I got married, my wife was watching TV and was sitting on bed. Tipsy suddenly jumped on bed and sat on lap of hers. This made her shed her fear. Tipsy took initiative to befriend our new family member – my wife.  Years gone by, my family grew, I have two children’s both have grown up with tipsy as part of our family and I didn’t found any issues with having a dog with infants or toddlers. In fact sometimes we noticed that he used to tell us if baby is awake or is crying. Such was his devotion.
German shepherds by nature are easy to train and are one of the top intelligent breeds of the world. So we don’t have to work hard to make him learn few commands. He used to sit when we told him to sit and used to hand shake us with his right hand and on change command used to give his left hand. My mom as head of  our family  was supreme commander for him as well. He used to listen and obey to her. She had experience of handling the dogs and is fond of this animal.
In March 2015, I came back to home from a business trip after three weeks. Everything seemed normal. After two weeks of my coming back, he fell sick. We thought that it was normal. As he used to stop eating for few days  (1 or 2) when ever he felt that his stomach is upset or when season changed. This was the time when summer was setting in from winter. But after 2 days he still didn’t ate and my mom noticed that he is having fever. We called up the vet, who gave some treatment and next day he looked better but ate very less.  We noticed he was not able to walk with conviction as he used to be and his right hind leg was scratching the road and was not able to control his body.
This ringed the alarm bell and we consulted another vet, who advised us to get his blood test. The reports showed very high percentage of urea content in blood due to kidney dysfunction.  
We could not see this coming, we lost the track of his age. He completed 10 years to life with us. After trying everything we could. He left us after two weeks of fight with life.
More over he left us on my birth day to make sure we remember him, whole of my life.  When he was fighting for his life he was still looking at me with same devotion. I felt that he is fighting his death and not willing to give up my companion ship.
After his death, We buried him with his favorite toys.  My children are finding it hard to believe his demise. My daughter who is 3 and half wakes up every morning and asks if Tipsy has come back or not.
When I come back no one comes out of the door to greet me anymore, nor there is one to walk with every morning and evening.
Some way he was binding every family member with himself, which we never realized when he was alive. It’s a huge void in our life which will take time to fill.
I still feel he is with me. I regret I could not saw it coming. But dogs life span is very short.  I want to know about him after life. My son asked me to pray to god to make him man in his new life and give our address so that he can come back to us and live with us.

I pray to god for his soul may rest in peace. 









Wednesday, February 27, 2013

Using mustache templates in asp.net

For using mustache, you will need to add mime type first to allow .mustache templates to be used.
You can add mime type through web.config;



 
 

      

    






This will allow iis express to return the content of mustache template which can be parsed by handlebars.js



Tuesday, March 13, 2012

Forms in ASP.net MVC 3

The form representation is different in ASP.net MVC as compared to ASP.net.
there is no straight form tag that we were using in other version than MVC.
To create forms we need to user Html Helpers

HTML.Begin Form() method is used to define the form.

@using(HTML.BeginForm()){

// here you can define your form
// I am taking example of a product form



Product Name

     
@Html.TextBox("ProductName")

     
Product Description

     
@Html.TextArea("ProductDescription")

     



}


on the other hand to handle this form request on post.
you need to add the following code in your product controller :

   // I have created a product model in productsModel namespace where I have defined the
  // class for product..
        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                MvcAppTutorial.Models.Product myProduct = new Models.Product();
                myProduct.ProductName = collection["ProductName"];
                myProduct.ProductDesc = collection["ProductDescription"];
                ViewBag.ErrorMessage = "Data Saved";
                return View();
            }
            catch
            {
                return View();
            }
        }

Next I will show you how to add validations to the form..

Tuesday, December 20, 2011

Sencha Touch Project Template in Visual Studio 2010

I am starting on web development for mobile devices. I am using Sencha Touch. As I have been working with Microsoft technologies from last 8+ years thus would prefer to use Visual Studio for development.

I found VS Project Template for Sencha Touch.
Here's an article that explains how to do it.
http://mahdi.mp/sencha-touch-html5-p...l-studio-2010/ 


I have got it Installed and it all looks good to me to get started.

Hopefully I will get time shortly to publish Sencha Touch Learning series shortly.


Wednesday, June 29, 2011

Staying Calm important for a Project Manager

We all face certain situations repeatedly in our lives which throw our life out of gear and for a IT Project Manager these kinds of things are routine, say reoccurring in every 3 months or so. The situation could be project running late, or client becomes insolvent or you are to busy or over loaded with other projects that you cannot oversee the things properly and now client is yelling and result of this management has also become indifferent. All the world around you seems to be against you. But this is where a project manager needs to be cautious.
The sudden setbacks can kick your brain out of sort. and could fill it with negative feelings. The first and foremost thing to get back on track is to seize control of your thoughts and feelings to ensure that your are back to your best.
The natural tendency is to react or overreact in a negative way when things go wrong. One will become angry, upset, disappointed, etc..,and all these things will certainly block or shut down major part of your brain especially thinking part of the brain which does analysis and help solve problems and make decisions.

How to Deal with this;
The question that now arises is - HOW TO DEAL WITH THIS?
The answer lies in staying calm in a crisis.
One should take a deep breath to calm your mind and then think carefully about next words and actions.
Imagine that this is a test to see what you are truly made of. Imagine everyone is watching you and observing how you respond. So be a role model and  show them the correct way to deal with the situation.
Think of the following quote by Samuel Johnson.
Things don't go wrong and break your heart so you can become bitter and give up. They happen to break you down and build you up so you can be all that you were intended to be.


Always tell yourself - You expected things differently then they have came out to be. This is normal things can go wrong but they can be rectified.


As a project manager- My obligation is not only to remain calm in these kind of situations but also to motivate the team to work effectively to resolve the problem
If a Project Manager shows the panic then to keep motivation alive in the team is impossible.
When I am in a situation then I sit back first and look at the things and analyze what went wrong.
I myself is not afraid of admitting if I am guilty and I am willing to do anything to resolve it.
Then I list out things that i need to take care on priority and sit with my team and start working on the priorities.
I sit back with my team and work with them even it takes hours by keeping my self in the things I lead them by example and also ensure that things are going as I wanted them
Instead of reacting I ask question to people and listen to their answers and accordingly make out solution.
The most Important thing is to look something postive in the problem- Like I could be in better position in future if I can challenge my self to resolve things from this point.
This way I ve always been able to motivate my self through out and hope this small article will hold something for others to be useful in tackling the day to day situations effectively.

The article is not about advocating what I am doing but of helping others if they are in same situation.

Tuesday, March 22, 2011

ASP.net Web Forms Vs. MVC


After working and gaining some confidence in ASP.net MVC. I feel , now I am in a position to write up my views on this topic.
After having worked on Web Forms for over 5 years and before graduating to web forms having experience with classic ASP and VB6.0.  I felt the gradual change that brought advantages and after using these changes what disadvantages were felt and change was again introduced and so forth.
Sticking to the principle – “Change is inevitable”.
When I started on web programming, and having worked as vb6.0 developer for windows applications, the first choice was to go for Microsoft technology. So I started with ASP 3.0.  VB6.0 was involved as programming so was easy to learn with some principle fundamentals of POST and GET and Form collections with HTML and Java Script.
After working on few projects I felt the need that as the project grows,  while developing in ASP the managing of the project becomes difficult. There was not structure  or pattern defined, but we still follow to use include folder to contain asp pages that we needed to include. Handling actions were difficult and sometimes hard to debug, which consumed most of the time. Having graduated to web programming after spending 2+years in Window application development, always  felt the need for event driven programming for web.
Microsoft then introduced revolutionary .net platform. With .net platform came ASP.net 1.1. This was a complete makeover from vb6.o to fully object oriented VB and introduction of C# as programming languages which is object oriented.  In ASP.net the web programming was devised on web form technology, which was similar to event driven programming that we followed in windows application development for Visual Studio 6. You just need to understand and handle the post back  and you can easily code in ASP.net.
There was no include needed, and neat separation of Design and code file was introduced. The design is in .aspx file and code is in .aspx.cs or .aspx.vb file. This brought the much needed code and design separation  for better code management. Along with this advanced data bound controls and binding technology was introduced with ADO.net.
Web Forms completely changed the way web programming was done and introduced RAD (Rapid Application Development) in web development.
But as said change  defies the earlier disadvantages, but use of this brings up other change needs.
With introduction of AJAX, things again changed in web programming stage. There was need for reducing the post backs to the server and enhancing the user experience.
Microsoft,  always wanted there developers to enjoy the RAD advantage, introduced AJAX Control tool kit. Which has the update panel, which took care of the details of the ajax implementation. But there is a big performance issue related. The page usually took ages to get update, as behind the scene whole page got post back to the server .  Thus this invoked the need to handle the ajax using some generic methods.  Secondly, server side controls provided the rapid way of doing things, but if the application demanded some customization then  it used to take more time then what it took for development.
Various patterns were introduce to follow the programming. Which was needed for further abstraction of the code when the application complexity increases. But the following of the patterns has not been consistent, there are ways to tweak through the pattern following. 
Other problem was use of viewstate. The Web form s were dependent of viewstate, that kept the data for the server control in use.  Even the viewstate data is in encrypted form but their existence makes the page heavier and some what  compromises the data security.
Also with the introduction of JQuery, things changed rapidly  and demand for light weight pages with multiple functionality and generic, smooth and efficient Ajax implementation increased. Microsoft , keeping in consideration of the need for change and demand,  introduced MVC pattern for web development.
MVC is not the replacement for web form but another way of getting things done. But you will need to know in which project you need to follow  MVC or Web Forms.
If your project is complex and involved the modules that needs testing before implementation, then MVC is the best. As MVC provides TDD – Test Driven Development , where developer can test the Action inside the controller before implementing the view.
Another advantage of MVC is the strict following of Model View Controller. There is not tweak available.  The pattern is followed in strict consistent manner.
Usage of JQuery has enhanced the user experience and through jquery many things are possible which other wise using Web Forms would have been very difficult.
Eradication of viewstate has made the page lighter.
But still ASP.net MVC is not the substitute of Web Forms. If the application in consideration is to be developed in quick turnaround time or it does not involves much complexity then developers should prefer for web forms hands down.
I know the above is not the sufficient information, which answers this question. But I have tried sincerely to find this. I will keep myself and this blog updated with more information as needed.
Looking for comments on this.

Sunday, November 15, 2009

How Web Application Works?

A web application is different from window application, in many ways. First and foremost difference is this, that web application does not run on a single thread as window application runs. Second main difference is to run window application there’s an executable file which runs the application, but to run a web application, browser application executable is used, i.e to work with web application, you need a browser, through which you can use web application, so there is a dependency of browser application to run web application on users system.
There are two key players in running the show for the web application are: Web Browser and Web Server.
Web Browser works on user (client ) side and Web Server works on Server Side. The following steps are usually involved in the communication process between browser and web server are as follows:
1. A user initiates a request by typing in a url in address bar of the web browser (say: http://www.yahoo.com).
2. A request is send to the web server using HTTP protocol, and GET method to web server hosting the web application.
3. The Web Server (Yahoo.com web server), processes the request, as this request is for default page (Home Page), retrieves the code for the default page, and run it.
4. After running the code, the output produced is in the form of html and java script, which is sent back to the web browser using same HTTP protocol.
5. The web browser then processes the response and displays the web page (www.yahoo.com home page).
6. User may then fill in some data in the form provided in the web page (Say for login to yahoo, user name and password, or for registration some information ), and sends the request with the data filled using POST method to the web server again using HTTP protocol.
7. Web server will receive the request and process the data and send back the response to the web browser.
8. Web browser will receive the response and will display the web page.
This process is repeated over a web application session. Therefore this concludes that the key players for web application is HTTP Protocol for communication, Web Browser – Software to display web page and web form, and process HTML and Java Script, and Web Server- Server, to process the request of the user sent from web browser.