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-31

How to set fallback fonts for PDF rendering and creation

Introduction


PDF specification allows authors and software writers to create completely self-contained documents which include all necessary information for their rendering. It provides font data embedding – an important mechanism that can be used to get the documents consistently presented on many platforms and devices. While it looks good and natural from the first sight, it makes documents bigger because you have to embed the font’s data used in document.

One of the alternatives to embedding is using standard Adobe 14 fonts (Times-Roman, Helvetica, Courier, Symbol, Times-Bold, Helvetica-Bold, Courier-Bold, ZapfDingbats, Times-Italic, Helvetica-Oblique, Courier-Oblique, Times-BoldItalic, Helvetica-BoldOblique, Courier-BoldOblique) which a conforming reader should understand and display correctly.

Other alternative (and most widely used) is to use external fonts, which are usually provided along with the operating system. These fonts can be referred to by their names, and PDF reader tries to find them inside the well-known system folders when it loads the document.

To examine the fonts used inside the particular PDF document, go to the File-> Properties…-> Fonts (tab) in Adobe PDF Reader. See the sample below:

Pic. 1 Examining fonts used in PDF document

Pic. 1 Examining fonts used in PDF document

You may notice that AdobePiStd is marked as embedded subset, while Arial-based fonts are being loaded externally from default system folder ( C:\Windows\Fonts if you’re running the reader on Windows). Furthermore, you may also note that these Arial-based fonts are getting replaced by the fonts shown as Actual fonts. Thus Arial becomes substituted by ArialMT and so on.

External fonts and font substitution may work well under some conditions, but what if you were to create a PDF reading or processing app using Apitron PDF Rasterizer or Apitron PDF Kit .NET components for a platform where system fonts are completely inaccessible e.g. Silverlight? Or you would like to provide a custom font fallback mechanism for cases where you have a very limited system fonts set, e.g. an Android phone app. 

To help you with this, we have introduced new API for specifying font fallbacks. See the code section below for a real-world example.

Code sample


The following piece of code demonstrates how to set up font fallback in any of our products.

// let's set Arial as fallback for all not found fonts
using (Stream fontStream = File.Open("Arial.ttf", FileMode.Open))        
{
    // register the fallback font, it can be either TTF or TTC stream,
    // font name and other attributes will be inferred automatically
    EngineSettings.RegisterUserFont(fontStream);
    // map the font to all not found fonts using *, 
    // it's possible to map particular fonts using their names
    EngineSettings.UserFontMappings.Add(new KeyValuePair<string, string[]>("Arial"
        new[] {"*"}));
}

So, in order to font fallback to work you have to register the fonts and map them using EngineSettings class static methods.

Conclusion


Apitron PDF Kit and Apitron PDF Rasterizer products provide a great base for any PDF processing application. Understanding their settings doesn’t require much time, but can help you to find the solution for the trickiest cases. Contact us if you need any help or have questions and we’ll be happy to help.

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

2015-08-22

How to use background images for content elements in PDF

Introduction



Every content element defined in FlowLayout API subset provided by Apitron PDF Kit .NET component can have background set using solid color or an image. Background property can be used for solid backgrounds or pattern based colors and BackgroundImage for image backgrounds. You can also use BackgroundPosition and BackgroundRepeat properties to fine tune the background tiling if needed.

Code sample


Below is the console app sample that demonstrates how to use background for Section content element:

class Program
{
    static void Main(string[] args)
    {
        // create resource manager and add image resource
        ResourceManager resourceManager = new ResourceManager();           
        resourceManager.RegisterResource(new Apitron.PDF.Kit.FixedLayout.Resources.
XObjects.Image("background","../../images/image.jpg"));

        // create document and define styles
        FlowDocument pdfDocument = new FlowDocument();
          
        // define style for section with id = imageBackground
        pdfDocument.StyleManager.RegisterStyle("section#imageBackground", new Style()
            {
                BackgroundImage = new BackgroundImage("background"),
                Width = Length.FromPercentage(100),
                Height = Length.FromPercentage(100),
            });

        // define style for textblocks with class "title"
        pdfDocument.StyleManager.RegisterStyle("textblock.title", new Style()
            {
                Color = RgbColors.White,
                Font = new Font("Arial",40),
                Margin = new Thickness(70,395,0,0),
            });

        // add section containing text block
        pdfDocument.Add(new Section(new TextBlock("Background image sample"
          {Class = "title"})
            {
                Id = "imageBackground"
            });
            
        // save document
        using (Stream stream = File.Create("out.pdf"))
        {
            pdfDocument.Write(stream,resourceManager);
        }

        Process.Start("out.pdf");
    }
}

This code defines two styles: one for textblock and one for its container section (of course we could simply assign all properties directly to the elements not defining the styles at all). The section gets sized to page size and also gets an image background set. The textblock becomes positioned inside this section as a child content element.


Resulting PDF document looks as follows:


Pic. 1 Background image usage sample

Pic. 1 Background image usage sample

Conclusion


You can create impressive PDF documents using simple constructs demonstrated in this example. Content elements with image background are an easy to use and expressive way to enhance the look and feel of the new or existing documents. Download Apitron PDF Kit and try it yourself.

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

2015-08-15

How to create PDF documents using MONO and Apitron PDF Kit

Introduction


To demonstrate the cross-platform nature of Apitron PDF Kit library we decided to create a small sample showing how one can programmatically create a PDF document using MONO and our pdf .NET component. You’ll be able to run it on any MONO powered system, and we did it on OS X and Windows.


Prerequisites


1) Make sure MONO is installed on all machines where you’re going to run the app. We used v.4.0.3 available from mono project website.

2) This sample was created using Xamarin Studio (former MonoDevelop), so please download and install it as well.

3) Get the latest version of the Apitron PDF Kit for .NET component, you can download it here.


Creating the project


Open Xamarin Studio and select File -> New…- >Solution… -> .NET -> Console Project, as shown on the image below:

Pic. 1 Creating new Mono.NET console project

Pic. 1 Creating new Mono.NET console project

After clicking “Next”, configure you project’s location and finish the creation.


Adding references


Add the reference to the Apitron.PDF.Kit.dll from the downloaded zip package, so your project references would look like on the image below:

Pic. 2 Main program code file

Pic. 2 Main program code file

Writing the code


The code used in this sample is provided below; it creates a simple PDF file with a few text blocks.  It shows how to use styles and markup parsing for creating several TextBlocks at once. The automatic link creation for TextBlocks is demonstrated as well.

using System;
using Apitron.PDF.Kit;
using Apitron.PDF.Kit.FlowLayout.Content;
using System.IO;
using Apitron.PDF.Kit.Styles;
using Apitron.PDF.Kit.Styles.Text;
using System.Diagnostics;
using Apitron.PDF.Kit.FixedLayout.Resources;
using Apitron.PDF.Kit.FixedLayout.Resources.Fonts;
using Font = Apitron.PDF.Kit.Styles.Text.Font;
using Apitron.PDF.Kit.Styles.Appearance;
using Apitron.PDF.Kit.FlowLayout;

namespace CreatePDFFileSample
{
    class MainClass
    {
        public static void Main (string[] args)
        {            
            // create flow layout PDF document and resource manager
            ResourceManager resourceManager = new ResourceManager ();
            FlowDocument pdfDocument = new FlowDocument () 
              {
                Margin = new Thickness(10),
                Align = Align.Justify
              };

            // register styles
            pdfDocument.StyleManager.RegisterStyle ("textblock",new Style()
                {
                    Font = new Font(StandardFonts.Helvetica, 20),
                    Color = RgbColors.Black,
                });

            pdfDocument.StyleManager.RegisterStyle ("textblock.a"new Style()
                {
                    Color = RgbColors.Blue    
                });

            // add simple text blok element
            pdfDocument.Add(
                new TextBlock ("This PDF file was created using Apitron PDF Kit for .NET component. " +
                "It's a cross-platform library that can be used to manipulate PDF in Windows, " +
                "Mac, iOS, Android and Mono apps."));

            // add text containing the block acting as an interactive link
            pdfDocument.AddItems(
                ContentElement.FromMarkup("Visit our <a href='www.apitron.com'>website</a> " +
                "if you want to learn more about our PDF components."));

            string outputFileName = "document.pdf";

            // save the PDF file
            using (Stream outputStream = File.Create (outputFileName)) 
            {                            
                pdfDocument.Write (outputStream, resourceManager);
            }

            // open file with default system viewer
            Process.Start (outputFileName);
        }
    }
}

Results


If you run the sample created above, you’ll get the results shown on the images below:

Pic. 3 Resulting PDF document ( Windows )

Pic. 3 Resulting PDF document ( Windows )

You can see that the text is justified (because we set the document’s property Align), and it also contains a web link (pointed by the small hand cursor). If you click on this link, you’ll be navigated to the URL shown by the tooltip. The link in this document is represented by the Link Annotation object.

Running the app on OS X produces the same results. Just copy it to your OS X machine and execute the following command in terminal:

mono test/CreatePDFFileSample.exe

It assumes you have created a directory named “test” in your home folder and put files there. An image below shows the resulting PDF document:

Pic. 4 Resulting PDF document ( OS X )
Pic. 4 Resulting PDF document ( OS X )

Conclusion


Creation of the cross platform PDF processing application might be easier than you think with the right tools in hands. We’ve have shown how you could create a simple MONO based pdf processing app in this article. But the Apitron PDF Kit .NET component is not limited to such simple cases; it can be used to perform complex PDF processing tasks including: content manipulation and extraction, document merging, adding digital signatures, creation of PDF forms and much more, and provides a uniform API for all supported platforms.

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

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].