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