Quantcast
Channel: PDF tips & tricks
Viewing all articles
Browse latest Browse all 125

PDF to image for Windows Store applications (Windows 8, WinRT, .NET & C#)

$
0
0
     Our version of Apitron PDF Rasterizer for Windows 8 and WinRT is out, and now available for download, it's included in regular download package v.3.0.4(get it here) and corresponding dll can be found in Microsoft WinRT subfolder. Create you apps targeting Windows Store without any limitations, including Windows RT, using our native, 100% .NET solution.

Picture is worth a thousand words, see the screenshot of a running sample included with the package:

sample application(see WindowsStoreAppSample included with package)
                                                       
The sample is very simple and has lots in common with other  samples we already posted here or included with the product package, but there are a few things I'd like to highlight.

1) here is XAML code that main page uses

<Page x:Class="WindowsStoreAppSample.MainPage"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:local="using:WindowsStoreAppSample"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<GridBackground="{StaticResourceApplicationPageBackgroundThemeBrush}">
   <Image x:Name="myImage"HorizontalAlignment="Left" Height="717" Margin="33,24,0,0"VerticalAlignment="Top" Width="567"/>
        <Button x:Name="btnExit" Content="Exit"HorizontalAlignment="Left" Margin="812,232,0,0"VerticalAlignment="Top" Click="btnExit_Click"RenderTransformOrigin="0.787,9.187" Width="82"/>
        <Button x:Name="btnRender" Content="Render"HorizontalAlignment="Left" Margin="812,163,0,0"VerticalAlignment="Top" Click="btnRender_Click"/>
    </Grid>
</Page>

only 2 butons and an image control

2) How the rendering works

///<summary>
/// Handles rendering button click event
///</summary>
privateasyncvoidbtnRender_Click(object sender, RoutedEventArgs e)
{
    // get the assets folder for the app
    StorageFolder folder = awaitWindows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");

    // get the file included in app assets
    StorageFile file = awaitfolder.GetFileAsync("3bigpreview.pdf");

    // open the file and render first page
    using (Stream stream = awaitfile.OpenStreamForReadAsync())
    {
        Document doc = newDocument(stream);

        Apitron.PDF.Rasterizer.Page page = doc.Pages[0];

        ErrorLogger logger = newErrorLogger();
               
        WriteableBitmap bm = page.Render((int) page.Width, (int) page.Height, newRenderingSettings(), logger);               

        myImage.Source = bm;               
    }
}

The code looks similar to previously posted samples, the only differences are that we used the file from application Assets folder(but you may use other available locations),
and WritableBitmap class is used here instead of System.Drawing.Bitmap that doesn't exist for .NET applications targeting Windows Store.





Viewing all articles
Browse latest Browse all 125

Trending Articles