Another big release is now available for our
users, a version of Apitron PDF Rasterizer for Windows Phone 8.
It seems that if you have to develop an
application for Windows Phone 8 and need PDF to image conversion you are quite
limited in this matter.
But we have solved this problem and now you can
get it done using Apitron PDF Rasterizer (see http://apitron.com/Downloads ).
We also created a sample for you, and below
are highlights from Windows Phone 8 app
showing it in action(complete code sample is included with download package and can be found in Samples\WindowsPhoneAppSample folder):
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;
}
}
}
3) resulting app, running on a Windows Phone 8 Device, I used
our lovely test file here and as you can see it looks the same on as on
"big" screens.
PS:
The sample assumes that you have the Windows
Phone SDK installed, you may get it here
http://dev.windowsphone.com/en-us/downloadsdk