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..