1) XAML for main page is very simple, we have
only title, button, and container image placed on page
<phone:PhoneApplicationPage
x:Class="WindowsPhoneAppSample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource
PhoneFontSizeNormal}"
Foreground="{StaticResource
PhoneForegroundBrush}"
SupportedOrientations="Portrait"
Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page
content is placed-->
<Grid x:Name="LayoutRoot"
Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name
of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="10,10,10,10"
Orientation="Horizontal">
<TextBlock Text="PDF
to Image sample by Apitron" Style="{StaticResource
PhoneTextNormalStyle}" Margin="12,0" VerticalAlignment="Center"/>
<Button x:Name="Render" Click="OnRenderClicked" Content="Render"
/>
</StackPanel>
<!--ContentPanel - place
additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Image
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="myImage"/>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
2) PDF to image rendering code (C#)
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
/// <summary>
/// Handles
Render button click event
/// </summary>
/// <param
name="sender"></param>
/// <param
name="e"></param>
private async void
OnRenderClicked(object sender, RoutedEventArgs e)
{
// get the assets
folder for the app
StorageFolder folder
= await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");
// get the file
included in app assets
StorageFile file = await folder.GetFileAsync("3bigpreview.pdf");
// open the file and
render first page
using (Stream stream
= await file.OpenStreamForReadAsync())
{
Document doc = new Document(stream);
Apitron.PDF.Rasterizer.Page page =
doc.Pages[0];
ErrorLogger logger
= new ErrorLogger();
WriteableBitmap bm =
page.Render((int) page.Width, (int)
page.Height, new RenderingSettings(),
logger);
myImage.Source = bm;
}
}
}