pdf links

PDF Rendering
Convert PDF to Image (.NET)
Convert PDF to image on Android (Xamarin)
Convert PDF to image on iOS (Xamarin)
Convert PDF to image in Windows Store apps (.NET)
Convert PDF to image in Windows Phone apps (.NET)
PDF to image in Universal Windows Store apps (.NET)
Free PDF Viewer control for Windows Forms (.NET)
How to integrate PDF Viewer control in WPF app (.NET)
Creating WPF PDF Viewer supporting bookmarks (.NET)
Cross-platform PDF Viewer using GTK# (MONO)
Silverlight PDF viewer control (Silverlight 5)
Multithreaded PDF rendering (.NET)
Convert pdf to image in Silverlight app (C# sample)
How to set fallback fonts for PDF rendering (C#)
Avoiding the out-of-memory exception on rendering (C#)
PDF viewer single page application (WebAPI, AngularJS)
PDF viewer control for Windows 10 universal applications
Use custom ICC profile for CMYK to RGB conversion
PDF layers - separate images, text, annotations, graphics

PDF Forms Creation PDF Security
Conversion to PDF/A
Other topics
PDF Document Manipulation
PDF Content Generation
Fixed and Flow layout document API (.NET)
Creation of grids and tables in PDF (C# sample)
How to create interactive documents using Actions (C# sample)
Text flow effects in PDF (C# sample)
How to generate ordered and bulleted lists in PDF (C# sample)
Convert HTML to PDF using flow layout API (C# sample)
How to use custom fonts for PDF generation (.NET)
Create document with differently sized pages (C#)
Create PDF documents using MONO (C#/MONO/Windows/OSX)
How to use background images for content elements (C#/PDF Kit/FlowLayout)
Add transparent images to PDF document (C#)
Draw round rect borders in PDF documents(C#)
ICC color profiles and and ICC based colors in PDF (C#)
How to use bidirectional and right to left text in PDF (C#)
Create PDF documents from XML templates (C# sample)
How to resize PDF pages and use custom stamps (C#)
Add header and footer to PDF page (.NET sample)
How to use clipping mask for drawing on PDF page
Fill graphics path with gradient brushes in PDF (Shadings)
Apitron PDF Kit and Rasterizer engine settings
Add layers to PDF page (optional content, C# sample)
How to create free text annotation with custom appearance

PDF Content Extraction
PDF Navigation

PDF to TIFF conversion
Contact us if you have a PDF related question and we'll cover it in our blog.

2013-10-02

PDF viewer sample, free WPF application with bookmarks support

     In Apitron PDF Rasterizer for .NET 3.5.0 we’ve added support for bookmarks that many documents contain to simplify navigation. Using classes from  Apitron.PDF.Rasterizer.Navigation namespace you may easily find and render pages linked by bookmarks.

    To show this functionality in action and to help you get familiar with it, we have created a sample C# WPF application that demonstrates usage patterns and provides you with code snippets which you may use in your own applications. It also can be a good base for your custom viewer if you wish to create one, showing yet another way to convert pdf file to images.

    Download component package, unzip it, and open the \Samples\WpfPdfViewer folder. You are ready to check the app out. Open the sample project, run it and select the file to open(File->Open).
The sources are also available at codeplex.


Here are a few screenshots of the actual app (with PDF specification loaded):

Pic.1 Folded bookmarks tree

Pic.2 Unfolded bookmarks tree
You can navigate either by using Pages tab or Bookmarks tab, zoom in and out, scroll etc.

The code 

    In order to get WPF  databinding working with our Document class, we wrapped it with a custom view model implementing INotifyPropertyChanged interface. See DocumentViewModel class in our sample. 

    Access to document bookmarks is provided by Document.Bookmarks property, while navigation through the document has been implemented using DocumentNavigator class.


You may use DocumentNavigator class as follows:


      1)       go to page referenced by bookmark and render it
/// <summary>
/// Renders the page referenced by bookmark as an <see cref="ImageSource"/>
/// </summary>
/// <param name="bookmark">The bookmark.</param>
/// <returns>Image source that represents current page, otherwise null.</returns>
public ImageSource RenderPageReferencedByBookmark(Bookmark bookmark)
{
BitmapSource bitmapSource = null;

if ( document.Navigator.GoToBookmark(bookmark) )
{
Page page = document.Navigator.CurrentPage;

int imageWidth = (int)page.Width;
int imageHeight = (int)page.Height;

byte[] image = page.RenderAsBytes(imageWidth, imageHeight, new RenderingSettings());

bitmapSource = BitmapSource.Create( imageWidth, imageHeight, 72, 72, PixelFormats.Bgr32, null, image, 4 * imageWidth );
}

return bitmapSource;
}


      2)       use its MoveForward, MoveBackward, Move, GoToPage and respond to Navigated event


      3)       retrieve its state by checking CurrentPage or CurrentIndex properties



    Another nice thing that you may get out of the sample is a TreeView template that was used for bookmarks tree.

     <TreeView Background="LightGray" Name="Bookmarks" ItemsSource="{Binding Bookmark.Children}" SelectedItemChanged="OnBookmarkSelectionChanged">
               <TreeView.ItemTemplate>
                  <HierarchicalDataTemplate ItemsSource="{Binding Children}">
                     <TextBlock Text="{Binding Title}"/>
                  </HierarchicalDataTemplate>
               </TreeView.ItemTemplate>
     </TreeView>


         If you have any questions or suggestions regarding this or other code samples feel free to contact us or leave a comment here.





2 comments:

  1. Impressive! Is it possible to implement copy/paste functionality ?

    ReplyDelete
    Replies
    1. Hello, yes, but we didn't release the corresponding product yet. Sign up for our newsletter or follow us on twitter and we'll keep you updated.

      Delete