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.


PDF to image on Android, easy steps with Xamarin

      Let’s assume that you are developing an Android version of the already existing .NET application (desktop or web).And this application processes PDF files and saves them as images somewhere.

      I would personally look for a cross –platform solution that would reduce the amount of code I’d have to rewrite in order to target all these platforms.

      One of the solutions that could be easily found is to use Xamarin - a great project based on Mono and now becoming very popular for writing apps working on iOS, Mac, Windows and Android.

      That’s the base part, but I also need a library that works fine with Xamarin and can do PDF to image conversion. In my previous post  Creatingcross-platform PDF viewer using GTK# I demonstrated how we can create a simple application that shows PDF content on Windows and Mac OS X , and now it’s Android app’s turn.

So let’s follow step-by-step approach taken in previous posts and get this working.

STEP I - Setup

      Refer to the post Creatingcross-platform PDF viewer using GTK#  on how to setup environment, download latest Apitron PDF Rasterizer for .NET package and unzip it to the desired location. 

STEP II – Getting things built

       To make things simpler we provide a sample project called AndroidSample  that can be found in Samples folder inside the downloaded package. Open it using desired IDE, I will use MS VS.
       If everything is set up correctly project opens fine and builds without errors. If build fails, make sure that correct component dll is referenced. Remove the old reference and add new one, navigating to [Package_Folder]\ Microsoft.NET v2.0Android\Apitron.PDF.Rasterizer.dll.
                Otherwise it might be something wrong with environment setup, please read Xamarin documentation or post a comment here, I’ll try to help.

STEP III - Playground

       Ok, you’ve got it compiled! And now to make it more interesting, let’s not use the default PDF file provided with the sample (you may still use it, no problem, just hit Run). I’m going to add a new file, from
       For those decided to go this way, download the file by the link above and put in into Assets directory of the project, don’t forget to include it in project with AndroidAsset build action. Also  navigate to MainActivity.cs  and change button_click handler, replacing “testfile.pdf” to “3bigpreview.pdf”.

Build and hit Run, you should see the similar screen as below:

I used physical device connected to the PC, but you may want to run it on emulator also, to do it - click Start emulator image and run desired emulator.

So click OK and application deployment begins… once it’s finished, the application starts:

You see that application has very simple UI layout with just one button that says “Click me to start rendering”, let’s click it and see what happens.

Application starts processing the file that we have placed into its Assets folder, and when it finishes the following screen appears:



Here is the actual code that renders and saves image to storage, it is located in MainActivity.cs

// load the linked sample pdf file
using (Stream stream = Assets.Open("3bigpreview.pdf"), ms = new MemoryStream())

    ms.Position = 0;

    // create focument from the stream and request first page
    Document doc = new Document(ms);

    Page page = doc.Pages[0];

    // render the page using default settings
    int[] bitmapData = page.RenderAsInts((int)page.Width, (int)page.Height, new RenderingSettings());

    // convert given data to an android bitmap
    Bitmap bm = Bitmap.CreateBitmap(bitmapData, (int)page.Width, (int)page.Height, Bitmap.Config.Argb8888);

    // save image to device's gallery
    string imageUri = MediaStore.Images.Media.InsertImage(this.ContentResolver, bm, "MyImage", "An image created using Apitron.PDF.Rasterizer");

    // try to open the newly created image
    StartActivity( new Intent( Intent.ActionView,  Android.Net.Uri.Parse(imageUri)) );

No comments:

Post a Comment