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.

2015-08-09

How to use Apitron Silverlight PDF viewer control

Introduction


While developing Silverlight business applications you often have to deal with PDF documents and present these documents to users of your app in some way. That means you have to create your own, or purchase a Silverlight PDF Viewer control capable of handling large PDF documents and it also should make you able to do it in the restricted environment where Silverlight apps live. With the latest Silverlight release you may create trusted apps, but it’s not always the case, and most of the apps continue to run as untrusted on users’ side. 

What Trusted vs. Untrusted actually means for PDF viewer? PDF is mostly about text and its representation, and for correct viewing you need fonts. Untrusted apps can’t access fonts installed on user’s system, and therefore they have to solve this problem somehow.

Apitron PDF components for Silverlight can work in all trust modes, making you able to create, process and render PDF documents in a truly platform independent way if needed. They provide API for font resolving and have fallback mechanisms which you can use in untrusted mode to provide you own fonts for document processing.

Apitron PDF Viewer control for Silverlight we are going to cover in this article is a simple control aiming to help you implement PDF preview in your Silverlight apps. It’s based on Apitron PDF Rasterizer.NET component, and is free to use if you have an application license for Apitron PDF Rasterizer. Get it as Nuget package or download from our website, it’s very extensible and you can upgrade it yourself, integrating search, bookmarks and other features coming with the Apitron PDF Rasterizer API it’s based on (we can provide you with the sources if needed).

Sample project


Download Apitron PDF Controls package from our website (link). Go to samples folder and open PDFControlsSilverlightSampleApp solution. This sample shows how to use Apitron PDF Viewer control for Silverlight.

The image below shows main application page design surface:

Pic. 1 Sample Silverlight app that uses Apitron PDF Viewer control

Pic. 1 Sample Silverlight app that uses Apitron PDF Viewer control

The gray toolbar and the area below the “Open PDF File…” button represent the PDF viewer control. Once the app is loaded you can set the currently displayed document using its Document property. You can navigate between pages directly using built-in arrows, or programmatically using document’s DocumentNavigator property.

If you have used Apitron PDF Rasterizer before, you might be already familiar with this navigation approach. If not, you can read about it in this blog post. Current page text box can also navigate you to the desired page, just type the number in and press enter. The viewer also features zooming and “fit-to-width” display mode, and once we publish sources on GitHub, you’ll be able to modify it as you wish by adding any required functionality. 

Here is the code for “Open File…” click handler, showing how to load PDF document and set it for preview.

private void OnOpenFile(object sender, RoutedEventArgs e)
{
    OpenFileDialog openFileDialog = new OpenFileDialog();
    openFileDialog.Filter = "*.pdf | *.pdf";

    bool? dialogResult = openFileDialog.ShowDialog();

    if (dialogResult!=null && dialogResult==true)
    {
        pdfViewer.Document = new Document(openFileDialog.File.OpenRead());
    }
}


The complete sample also contains the code for registering own fonts for non-trusted mode. See the image below, it demonstrates the app opened in browser:

Pic. 2 Apitron PDF Viewer control usage sample (running application)

Pic. 2 Apitron PDF Viewer control usage sample (running application)

Conclusion


In this article we have shown how one may use Apitron PDF Viewer Silverlight control for PDF preview implementation. But it’s only the part of the story. You actually can create your own custom viewer controls based on the rendering engine it employs – the Apitron PDF Rasterizer library.

It’s provides you with an ability to render PDF documents, search and highlight text, work with bookmarks and links for all supported platforms. You may use it for creation of Windows apps (mobile, desktop, web), iOS and Android apps (via Xamarin), Mono apps, and apps running on every system .NET CLR implementation exists for. And if you need to create and process PDF documents, we have Apitron PDF Kit for .NET - ready to use and powerful PDF manipulation library.

Contact us if you have any questions, need help, or just want to learn more.

Downloadable version of this article can be found by the following link [PDF].

No comments:

Post a Comment