Support us on YouTube by Subscribing our YouTube Channel. Click here to Subscribe our YouTube Channel

Thursday 27 August 2015

Convert Word Document to PDF using Spire.Doc

Recently, I am working on a project in which I have to give functionality to convert Word Document to PDF. I searched a lot and found Spire.Doc (a product of e-iceblue company which provides .NET, Silverlight and WPF development components).

Spire.Doc for .NET is a professional Word. NET library specially designed for developers to create, read, write, convert and print Word document files from any .NET( C#, VB.NET, ASP.NET) platform with fast and high-quality performance.

You can also download Free edition of Spire.Doc. Free Spire.Doc for .NET is a Community Edition of the Spire.Doc for .NET, which is a totally free word component for commercial and personal use with some limitation.

Free Spire.Doc for .Net

I have downloaded Spire.Office which includes Spire.Doc as well as other components (Spire XLS, Spire.Presentation, Spire.PDF, Spire.DataExport, Spire.PDFViewer, Spire.DocViewer and Spire.BarCode). You can also Download Spire.Office or Spire.Doc from these links.

After Downloading, Install the Spire.Office or Spire.Doc (whatever you have downloaded).

Let's Begin:
Create New Windows Form Application. I have selected .Net framework 4.
Right Click on References in Solution Explorer and Click on Add Reference.
In Reference Manager, Click on Browse tab
Now go to  C:\Program Files (x86)\e-iceblue\Spire.Office\Bin\NET4.0 and Add Spire.Doc.dll in your project.

After Adding, you will see Spire.Doc dll reference added to your project.
Now, Drop a button(named as btnConvert) control on the form and double click on it to create its Click event.
Add Spire.Doc and Spire.Doc.Documents namespace in .cs Code.
Add the following lines of Code in button Click event:
private void btnConvert_Click(object sender, EventArgs e)
{
    //Load Document
    Document doc = new Document();
    //Pass path of Word Document in LoadFromFile method
    doc.LoadFromFile(@"C:\Users\Anoop Kumar Sharma\Desktop\Coding.Docx");
    //Pass Document Name and FileFormat of Document as Parameter in SaveToFile Method
    doc.SaveToFile("Convert.PDF",FileFormat.PDF);
    //Launch Document
    System.Diagnostics.Process.Start("Convert.PDF");
}
Build and Run the application. When you click on the Convert button, Coding.Docx i.e our Word Document is converted into PDF Document. You can find the converted PDF document in Bin/Debug/ Directory of your project.
I hope you like this article. Thanks.

Wednesday 5 August 2015

Localization in Windows Phone 8 Application

In this article, We will learn How to make an application which provides support multiple languages or for specific culture. In previous article, we saw:


What is Localization?
From the Wikipedia-
"Localization is a process of translating a product into different languages or adapting a product for a specific country or region."

Let's Begin:
Create a new Windows Phone application and select Windows Phone 8.0 as the target Windows Phone OS for this application and click on OK.
Create Windows Phone Project
Windows Phone 8 Application Contains a folder named as Resources which contains Resource file(which is a xml file) with a special .resx extension. Windows Phone 8 Application template also contains a LocalizedStrings class which provides access to resources. An instance of this class is created in app.xaml with the key LocalizedStrings. Open AppResources.resx file and add some Name-Value string Pairs.
LocalizedStrings
Now open the properties of the project
Under the Application tab, Go to Supported culture section and Tick the languages you want your application to support. I am Selecting Hindi and English U.S.(Selected by Default ).
When you select the new language(I selected Hindi), Visual Studio automatically adds a new AppResources file named as AppResources.hi-IN.resx accoording to selected Culture/Language. Double click on AppResources.hi-IN.resx file to open it.
Now replace the value(the translated text) according to language/culture. I have translated the value of Key PageName, DemoText according to Hindi language. Then save and build your application.
Databind the text property of TextBlock or other control to StaticResource with a key LocalizedStrings.
Source Code:
<Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="Demo APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
            <TextBlock Text="{Binding Source={StaticResource LocalizedStrings},Path=LocalizedResources.PageName}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" Padding="0 10"/>
        </StackPanel>
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <StackPanel>
                <TextBlock Text="{Binding Source={StaticResource LocalizedStrings},Path=LocalizedResources.DemoText}" FontSize="32"></TextBlock>
            </StackPanel>
        </Grid>
</Grid>
Build and Run the application.
Preview:
Now let's change the Language of our device to Hindi. Go to Settings ->  Langauge + region.
Change Phone Language to Hindi.
Click on restart Phone. After your phone restarts, Open your application and you see our application is now supported for Hindi Language/culture.
I hope you like this. Thanks.
[Download Source Code via Google Drive]

Subscribe us on YouTube

Subscribe Now

Popular Posts

Contact us

Name

Email *

Message *

Like us on Facebook