Retrieving PDF File in Windows Phone 7

In this article we are going to explore how to retrieve PDF files in Windows Phone 7.


In this article we are going to explore how to retrieve PDF files in Windows Phone 7. We will also see see how it is possible to do the retrieval of a PDF file in Windows Phone 7. We are going to discuss in details how to do this. To do it you should download and install the WP7 control Component'sOne control for Windows Phone 7. When you have downloaded it then use it. Now we are going to write some steps explaining how it is used and you should follow these steps which are given below.

Step 1: In this step first of all we have to open a Windows Phone application; let us see how you will open it.

  • Go to Visual Studio 2010
  • File->New->Project
  • Select the template named as silverlight for Windows Phone
  • Select the Windows Phone application
  • Give it a name as you want.   



Step 2: In this step we will see how you add the pdfViewer control inside the toolbox; for this you see the figure given below.

First of all you go to the Toolbox and right-click on it then click to choose an item, as shown in the figure given below.


In this figure you just see that the chosen component is the one that is selected; click ok to show it inside the Toolbox.


Now you just see that the control has been added to the Toolbox as shown in the figure given below.


Step 3: In this step you will add a PDF file to the application; let's see how to add it.




Step 4: In this step we will see how to change the property of the PDF file named BuildAction; let's see how you will do that:


In the given figure you will change the property named BuildAction whose value is None by default and change it to Resource as shown in the figures given below.

Step_4_2fig.jpg      Step_4_2_2fig.jpg

Step 5: In this step you will see the code for the MAinPAge.xaml file which is shown below.










    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"

    FontFamily="{StaticResource PhoneFontFamilyNormal}"

    FontSize="{StaticResource PhoneFontSizeNormal}"

    Foreground="{StaticResource PhoneForegroundBrush}"

    SupportedOrientations="Portrait" Orientation="Portrait"

    shell:SystemTray.IsVisible="True" xmlns:my="clr-namespace:C1.Phone.PdfViewer;assembly=C1.Phone.PdfViewer" Loaded="PhoneApplicationPage_Loaded">

    <!--LayoutRoot is the root grid where all page content is placed-->

    <Grid x:Name="LayoutRoot" Background="Transparent">


            <RowDefinition Height="Auto"/>

            <RowDefinition Height="*"/>


        <!--TitlePanel contains the name of the application and page title-->

        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">

            <TextBlock x:Name="PageTitle" Text="Pdf App" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}">


                  <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">

                     <GradientStop Color="Black" Offset="0" />

                     <GradientStop Color="#FFA1FFFF" Offset="1" />





        <!--ContentPanel - place additional content here-->

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">


                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">

                    <GradientStop Color="Black" Offset="0" />

                    <GradientStop Color="#FFFFD5D5" Offset="1" />



            <my:C1PdfViewer HorizontalAlignment="Left" Margin="12,21,0,0" Name="MyPdfViewer1" VerticalAlignment="Top" Width="438" />




Step 6: In this step you will see the code for the MainPage.xaml.cs file which is shown below.


using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using Microsoft.Phone.Controls;

namespace Mypdf


    public partial class MainPage : PhoneApplicationPage


        // Constructor

        public MainPage()



            Loaded += new RoutedEventHandler(PhoneApplicationPage_Loaded);


        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)


            var MyPdf = Application.GetResourceStream(new Uri("MyPdf;component/BeggPhoneGap.pdf", UriKind.Relative));


            MyPdfViewer1.FontSize = 20;

            MyPdfViewer1.Height = 550;




Step 7: In this step you will see the design of the MainPage.xaml file which is shown below.


Step 8: Now in this step we are going to run the application by pressing F5 and the output regarding is given below.

Output 1: In this output you just see that it has read the PDF file; this shows it's front page.


Output 2: Whenever you scroll the page then you just see it shows the PDF page index and for zooming a page you will click twice or more on the page as you can see in the figure given below.


Here are some other useful resources which may help you.

Sending Mail from Gmail and Save the file in PDF Format
HJ PDF in C#
How to embed HTML file in Windows Phone 7
PDF File GeneratorHow to create PDF file using itextsharp