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.

2014-12-25

Convert PDF to image in Universal Windows Store App

For those who are going to create Universal apps requiring PDF rendering for both Windows Phone Store and Windows Store we have prepared a sample showing our Apitron PDF Rasterizer for .NET component in action.

This C# sample is called ProgressiveRenderingSample and it was created using Visual C#\Store Apps\Universal Apps\Blank App template. Sample is included into the product download package, see Samples folder (get it here). The solution contains two specific projects each targeting its own platform (Windows 8.1 and Windows Phone 8.1) and a shared code project.

In this sample we demonstrate that the same code can be used to render PDF to image on both platforms and the technique called “progressive rendering”. Both apps render PDFs using special rendering thread and update their views asynchronously taking the load off the UI thread. It makes the app more responsive to user actions and gives him perfect feedback.

Screenshots, showing 2 apps side by side:

windows store app
Windows 8.1 app

windows phone app
Windows Phone app

Both apps use the same code and library for rendering and they even look similar having the same layout for their main pages. Try it yourself or contact us if you have any questions or comments.

Create, read, edit and sign PDF documents using single .NET component. (C# samples)

If you need a PDF .NET component providing easy-to-use and clean API then it’s time to take a look at the Apitron PDF Kit for .NET. This product is designed to help you on a way with creation, manipulation, and all kind of processing related to PDF documents. These files can be of different origin: created using all possible versions of the PDF specification and various optimization techniques, e.g. linearized or tagged PDFs.  They can also be password-protected or digitally signed, so simply speaking - everything created according to PDF specification can be processed using our component.

Apitron PDF Kit for .NET is a fully managed .NET library that supports literally all features defined for PDF by Adobe, assemblies are available for any .NET framework version starting from 2.0 and it also works on Mono and Xamarin.  Xamarin Studio + Apitron PDF Kit can be used to create PDF processing apps running on OS X for example. Futhermore it's possible to create apps for iOS and Android using Xamarin.iOS and Xamarin.Android. Files created using this component can be viewed on all platforms and devices where a decent PDF viewer exists (and furthermore we have own viewer and rasterizer components as well).

Using this component you’ll be able to:


  • Extract, modify and add graphics (text, images, drawings)
  • Split or merge PDF documents
  • Fill or create PDF forms
  • Add or remove document fields
  • Examine resources within a document - fonts, embedded files
  • Digitally sign and check existing signatures on PDF documents
  • Search for specific text
  • Protect document with a password, edit its permissions
  • Work with navigation objects, e.g. create bookmarks or links
  • Control viewer settings for PDF file
  • Use full support for annotations
  • Use full support for PDF actions
  • Use all fonts defined by specification
  • Use various supported colorspaces and color profiles, e.g. you may draw in RGB, CMYK, gray, or whatever colorspace you like.
  • Save files to other “subtypes” of PDF – Linearized or PDF/a for example. If you require a specific functionality and are unsure about whether it is supported, please review our online help you contact support so we'll be able to handle this.
  • Use Fixed layout API, implemented to be 100% PDF specification compatible, it unlocks full power of the PDF for you. Any complex PDF creation or manipulation task can be completed instantly.
  • Use Flow layout API, a styles-driven content generation API similar to HTML+CSS provides you with ability to create stunning documents, reports, bills, catalogs and more in minutes. Compact and easy to use, supports creation of XML templates and much more.
  •  Create cross-platform PDF processing apps targeting Windows, iOS, Android, OS X and other systems .NET/MONO implementation exists for.

This list is rather incomplete but it gives an idea of component's capabilities. It’s also worth mentioning that we provide first-class support and response within 24h is guaranteed.

Component’s package contains many beautiful samples for both Fixed and Flow layout APIs and can be downloaded here. There are samples showing how to sign the document, draw something on PDF page, generate simple report using grid, set document password and more. Whenever you have a need, all developer guides and component's documentation are available online on our website.

Below I’m going to show you a simple “Hello world” PDF creation sample:

The code


/// <summary>
/// "Hello World" PDF generation sample, flow layout.
/// </summary>       
class Program
{
    static void Main(string[] args)
    {
        ResourceManager resourceManager = new ResourceManager();
           
        // create document and set margin
        FlowDocument document = new FlowDocument() { Margin = new Thickness(5)};

        document.Add(new TextBlock("Hello world with Apitron PDF Kit for .NET!") { Font = new Font(StandardFonts.Helvetica,20)});
         
        string fileName = "HelloWorld.pdf";

        // save and open
        using (Stream stream = File.Create(fileName))
        {
            document.Write(stream, resourceManager, new PageBoundary(Boundaries.A4));
        }

        Process.Start(fileName);
    }
}


Result


Generated "Hello world" PDF


Similar sample demonstrating Fixed layout API

The code


/// <summary>
/// This sample shows how to draw a simple rect on PDF page.
/// </summary>
class Program
{
    private static void Main(string[] args)
    {
        string fileName = "rectangle.pdf";

        // open and load the file
        using (FileStream fs = new FileStream(fileName, FileMode.Create))
        {
            // this object represents a fixed PDF document
            FixedDocument document = new FixedDocument();
            Page page = new Page(new PageBoundary(Boundaries.A4));

            // create colorspace resource
            string rgbID = "CS_RGB";
            document.ResourceManager.RegisterResource(new RgbColorSpace(rgbID));

            // set fill color
            page.Content.SetNonStrokingColorSpace(rgbID);
            page.Content.SetNonStrokingColor(0.33, 0.66, 0.33);
               
            // define the rectangle
            FixedLayout.Content.Path path = new FixedLayout.Content.Path();
               
            path.AppendRectangle(200, 300, 200, 200);
            page.Content.FillAndStrokePath(path);

            // add page to the document and save
            document.Pages.Add(page);
                            
            document.Save(fs);
        }

        // preview document
        Process.Start(fileName);
    }       
}



Result


Generated PDF

We’ll continue to cover our API by providing more samples in upcoming posts, stay tuned!  Lots of samples are available already in our download package. Should you have any questions just let us know and we’ll be happy to help you. 

2014-11-19

PDF bookmarks

Intro

Some PDF documents can contain the TOC (table of contents) to simplify navigation within the PDF file and to allow structured content representation. It's the thing you usually see then you click on Bookmarks tab in Acrobat Reader. So this table of contents is usually being created by using bookmark objects (this is the PDF name for such objects as defined in specification). This object supports navigation as well as link (see our older posts: working with build-in navigation and how to work with links in PDF documents) being a bit different.

While the samples listed above provide code and theory for highlighting search results or link targets on PDF page, current sample is designed to show the bookmark basics for the most common task – enumerate bookmarks list and show doc's table of contents.

The code

C# code sample below demonstrates how it could be done using our API.

/// <summary>
/// Demonstrates bookmarks enumeration in PDF file.
/// </summary>
class Program
{
    static void Main(string[] args)
    {
       // open and load the file
       using (FileStream fs = new FileStream(@"..\..\..\Documents\development guide.pdf",                FileMode.Open))
       {
           // this object represents a PDF document
           using(Document document = new Document(fs))
           {
               EnumerateBookmarksAndPrint(document.Bookmarks);
           }
       }

       Console.ReadLine();
     }

     /// <summary>
     /// Enumerates the bookmarks and prints their title.
     /// </summary>
     /// <param name="bookmark">The bookmark.</param>
     private static void EnumerateBookmarksAndPrint(Bookmark bookmark)
     {
         if(bookmark!=null)
         {
             Console.WriteLine(bookmark.Title);

             for(int i=0;i<bookmark.Children.Count;i++)
             {
                 EnumerateBookmarksAndPrint(bookmark.Children[i]);
             }
         }
     }
}

Output

1. Introduction
2. Getting started
2.1 Development environment
2.2 Deployment & installation
2.3 Licensing process
2.3.1 Using custom assembly attribute
2.3.2 Applying license manually
3. Product description
3.1 PDF versions supported
3.2. Features and limitations
3.3. Output formats
3.4 Processing highlights
4. Code samples
4.1. Convert PDF document to Bitmap
4.2. Convert PDF to TIFF
4.3. Viewing information about PDF document
4.4. Extracting font information from PDF files
4.5 Advanced conversion using rendering settings



The sample can be found in our download package and is located in Samples\BookmarksUsage folder.
It's also possible to highlight bookmark's destinaton and save desired PDF page to image using the API provided by Apitron PDF Rasterizer for .NET.


2014-08-28

Yet another way to create a mutable bitmap (Xamarin Android)

Intro


Current API provided by Android Bitmap doesn’t provide a constructor to create a mutable bitmap object, however you can make it mutable by copying the existing one with a mutable flag set.
e.g.

Bitmap bitmap = new Bitmap(100, 100, Bitmap.Config.Argb8888);
Bitmap mutableBitmap = bm.Copy(Bitmap.Config.Argb8888, true);

Another way is to use a BitmapFactory and create bitmap object from stream or byte array with a mutable flag set.So for byte array it goes like this:

BitmapFactory.Options options = new BitmapFactory.Options();
options.InMutable = true;
options.InPreferredConfig = Bitmap.Config.Argb8888;
           
Bitmap result = BitmapFactory.DecodeByteArray(imageData, 0, imageData.Length, options);

But imageData is required to contain an encoded image not the raw pixel data. One of the solutions here that doesn’t require bitmap copying or reading from disk is to provide BitmapFactory with some data it’s able to recognize as an image and therefore decode.

The code


/// <summary>
/// A bitmap helper class by Apitron.
/// </summary>
static class BitmapHelper
{
    /// <summary>
    /// Creates mutable bitmap with ARGB32 pixel format.
    /// </summary>
    /// <param name="width">The width of the bitmap.</param>
    /// <param name="height">The height of the bitmap.</param>   
    /// <returns>Created bitmap.</returns>
    public static Bitmap CreateMutableBitmapARGB32(int width, int height)
    {
        // pixel data
        uint pixelDataSize = (uint) (width*height*4);

        byte[] imageData = new byte[pixelDataSize+54];

        // BITMAPFILEHEADER
        // "BM" +2
        imageData[0] = 0x42;
        imageData[1] = 0x4D;

        // bitmapsize +4; pixeldata size + bitmap file header(14 bytes) + bitmapinfo header(40 bytes)
        Array.Copy(BitConverter.GetBytes(pixelDataSize+54), 0, imageData, 2, 4);

        // reserved +4
        imageData[6] = 0;
        imageData[7] = 0;
        imageData[8] = 0;
        imageData[9] = 0;

        // pixel offset +4
        imageData[10] = 54;
        imageData[11] = 0;
        imageData[12] = 0;
        imageData[13] = 0;

           
        // BITMAPINFOHEADER
        // header size offset +4
        imageData[14] = 40;
        imageData[15] = 0;
        imageData[16] = 0;
        imageData[17] = 0;

        // bitmapWidth +4
        Array.Copy(BitConverter.GetBytes(width), 0, imageData, 18, 4);

        // bitmapHeight +4
        Array.Copy(BitConverter.GetBytes(height), 0, imageData, 22, 4);

        // planes +2
        imageData[26] = 1;
        imageData[27] = 0;

        // bitcount +2
        imageData[28] = 32;
        imageData[29] = 0;

        // compression +4, BI_RGB
        imageData[30] = 0;
        imageData[31] = 0;
        imageData[32] = 0;
        imageData[33] = 0;

        // pixel data size +4
        Array.Copy(BitConverter.GetBytes(pixelDataSize), 0, imageData, 34, 4);

        // dpiX  +4
        Array.Copy(BitConverter.GetBytes(2835), 0, imageData, 38, 4);

        // dpiY +4
        Array.Copy(BitConverter.GetBytes(2835), 0, imageData, 42, 4);

        // clrUsed +4
        imageData[46] = 0;
        imageData[47] = 0;
        imageData[48] = 0;
        imageData[49] = 0;

        // clr important +4
        imageData[50] = 0;
        imageData[51] = 0;
        imageData[52] = 0;
        imageData[53] = 0;

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.InMutable = true;
        options.InPreferredConfig = Bitmap.Config.Argb8888;
           
        Bitmap result = BitmapFactory.DecodeByteArray(imageData, 0, imageData.Length, options);
        result.HasAlpha = true;

        return result;
    }
}


So it just creates a byte array sized to fit the requested bitmap data and adds BITMAPFILEHEADER and BITMAPINFOHEADER to make it look like an image in BMP format for BitmapFactory. Hope it will help someone looking for a mutable bitmap.