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-09-26

How to sign the already signed PDF document

Introduction


Digital signatures provide a reliable way to sign documents and verify the identity of the signing person(s). They are used nowadays in many areas of our everyday workflow, and, when it comes to PDF, we luckily have the support for them built-in into the standard.

We have already covered the PDF signing and validating topic in one of our earlier posts (you can read it here), but it was related to signing the document with one or several signatures at once.


In this article we’ll cover another interesting scenario where signing will be performed for previously signed document.  “What is the difference?” - you may ask. Sequential signing requires different handling and implementation because as the document changes, previous signatures may become invalid. But the Apitron PDF Kit for .NET component can handle any signing task and we’ll demonstrate it in code section.

Code sample


The code below adds two digital signatures to PDF document sequentially. This way you can add as many signatures as you want.

class Program
{
    private static void Sign(string pathToDocument, string pathToCertificate,
       string password, string pathToSignatureImage, Boundary signatureViewLocation)
    {           
        // open existing document andd sign once
        using(Stream inputStream= new FileStream(pathToDocument, FileMode.Open,
            FileAccess.ReadWrite))
        {
            using (FixedDocument doc = new FixedDocument(inputStream))
            {
                string imageResourceId = Guid.NewGuid().ToString("N");
                string signatureFieldId = Guid.NewGuid().ToString("N");

                // register signature image resource
                doc.ResourceManager.RegisterResource(new Image(imageResourceId,
                    pathToSignatureImage));

                // create first signature field and initialize it using a stored certificate
                SignatureField signatureField = new SignatureField(signatureFieldId);
                using (Stream signatureDataStream = File.OpenRead(pathToCertificate))
                {
                    signatureField.Signature = Signature.Create(
                       new Pkcs12Store(signatureDataStream,password));
                }

                // add signature fields to the document
                doc.AcroForm.Fields.Add(signatureField);

                // create first signature view using the image resource
                SignatureFieldView signatureView =
new SignatureFieldView(signatureField, signatureViewLocation);
                signatureView.ViewSettings.Graphic = Graphic.Image;
                signatureView.ViewSettings.GraphicResourceID = imageResourceId;
                signatureView.ViewSettings.Description = Description.None;

                // add views to page annotations collection
                doc.Pages[0].Annotations.Add(signatureView);

                // save as incremental update
                doc.Save();
            }
        }
    }

    static void Main(string[] args)
    {
        string fileName = "signedTwice.pdf";
        CreatePDFDocument(fileName);

        // save once and save
        Sign(fileName, "../../data/certs/JohnDoe.pfx", "password",
 "../../data/images/signatureImage.png"new Boundary(10,750,110,800));

        // add second signature to the already signed doc and save
        Sign(fileName,
            "../../data/certs/JaneDoe.pfx", "password",
             "../../data/images/signatureImageJane.png"
             new Boundary(120, 750, 220, 800));                      
    }

    private static void CreatePDFDocument(string fileName)
    {
        using (Stream stream = File.Create(fileName))
        {
            FlowDocument doc = new FlowDocument(){Margin = new Thickness(10)};
            doc.Add(new TextBlock("Signed using Apitron PDF Kit for .NET"));
            doc.Write(stream,new ResourceManager());
        }
    }               
}


The resulting file looks as follows:

Pic. 1 Signed PDF document

Pic. 1 Signed PDF document

Conclusion


Apitron PDF Kit handles multiple signing scenarios and can be used to create digitally signed documents in corporate, government and end user environments. You can download it from our website and try for yourself. Whenever you have a question you can read our free book, browse online API documentation and articles (see documentation page). Contact us if you need any help and we’ll be happy to assist you.

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

2015-09-19

How to avoid the out of memory exception when rendering or reading PDF files

Introduction


Rendering or reading PDF files can be tricky sometimes because of abnormal PDF resource size and device memory limitation constraint overlapping with each other. The most common problem is having a huge image inside the PDF file that requires a significant amount of memory to be allocated for proper processing.

This problem can arise on mobile devices (e.g. in Xamarin apps), but can also be observed on PCs if you have not enough memory to hold the resources stored in PDF file and there are really big. To solve this problem we introduced the PDF engine setting controlling the resource loading strategy. See the code sample in next section to learn how it works.

Code sample


// open the document and render first page
using (Stream fileStream = File.Open("document.pdf",FileMode.Open))
{
    // You can turn on the low memory mode globally:
    // EngineSettings.GlobalSettings.MemoryAllocationMode = 
    // MemoryAllocationMode.ResourcesLowMemory;
    //  or apply this setting only to the specific file as shown below.
    // This mode can be useful in situations where you have PDF files containing huge
    // image resources or embedded fonts, and running out of memory because of this.
    EngineSettings engineSettings = new EngineSettings()
    {
        // set the resource size limit to 2MB, 
        // everything bigger than that will be saved to disk
        ResourceSizeLimit = 2097152,
        MemoryAllocationMode = MemoryAllocationMode.ResourcesLowMemory
    };

    using (Document doc = new Document(fileStream, engineSettings))
    {
        // render page and save the result
        Bitmap bitmap = doc.Pages[0].Render(new Resolution(72, 72), 
           new RenderingSettings());
        bitmap.Save("page0.png");
    }
}

Conclusion



You can render resource demanding and complex PDF documents using Apitron PDF Rasterizer .NET component, download it from our website and enjoy the top quality PDF rendering results and its easy to use API. Contact us if you need any help or have questions, we guarantee the response within the same business day.

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

2015-09-12

How to check whether the document uses PDF/A standard

Introduction


PDF/A is a special topic not much can be found about, so we have covered the creation of PDF/A documents our recent blog post. Sometimes you may need to check whether the PDF document already uses PDF/A standard, and we’ll show how you can get this done using Apitron PDF Kit for .NET component.

Code sample (C#)


static void Main(string[] args)
{
    using (Stream fileStream = File.Open("../../Data/document.pdf",FileMode.Open))
    {
        using (FixedDocument doc = new FixedDocument(fileStream))
        {
            // PdfStandard property can be used to check whether the document
            // uses PDFA standard. It will return PDfStandard.Default if the 
            // doc doesn't use PDFA or PdfStandard.PDFA if it does.
            Console.WriteLine(string.Format("Document uses '{0}'  standard",
 Enum.GetName(typeof(PdfStandard),doc.PdfStandard)));
        }
    }

    Console.ReadLine();
}


The output is shown below:

Pic. 1 Checking document standard (PDF/A document)

Pic. 1 Checking document standard (PDF/A document)

Conclusion


You can download the Apitron PDF Kit for .NET component from our website and try it out. In addition, you can also find more samples inside the component’s package. Should you have any questions, just send us an email and we’ll be happy to help.

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

2015-09-05

Working with transparent images in PDF

Introduction


Transparency in PDF can be specified using various methods and depends on desired effect, all possible techniques are discussed in details in our free book Apitron PDF Kit in Action in sections:

3.3.1.8 Drawing transparent objects in PDF
3.3.4 Transparency Group XObjects
3.3.5 Images
3.3.6 Softmasks

In this post we’ll cover the typical task of using a transparent image in PDF document. One may think that such a simple thing should work of the box and shouldn’t require any tricky manipulations. That’s true for Apitron PDF Kit, and you’ll see how easy it can be done, but underlying PDF specifics might be an interesting read by itself.

PDF standard doesn’t have a concept of a transparent image as a whole. Instead, a transparent image gets defined as a combination of raster image data samples (pixels) plus an additional object defining the transparency level for each of them.

These objects may define whether the image will be masked using color key mask, explicit (stencil) mask defined by another monochrome image, or a softmask.

The latter allows for smooth masking, gradually changing the transparency level of the image samples, while other methods can only define fully transparent or opaque pixels. And the softmask is the only way to correctly reproduce the transparent PNG for example. Using Apitron PDF Kit API you can manage image transparency yourself or let the library handle it for you. Let’ see the code sample in next section.

Code sample (C#)


Let’s use the PNG demo image from Wikipedia in our sample, see the code below:

using (FileStream outputStream = new FileStream("image.pdf", FileMode.Create, FileAccess.Write))
{
    // create new PDF document
    FixedDocument document = new FixedDocument();
    document.Pages.Add(new Page());              

    // create image XObject and set it to use embedded transparency data
    Image maskedImage = new Image("maskedImage", "../../images/cubes.png", true);
    document.ResourceManager.RegisterResource(maskedImage);
               
    // create page content object
    ClippedContent pageContent = document.Pages[0].Content;

    // define stripe parameters
    double stripeWidth = 20.0;
    double doubleStripeWidth = stripeWidth*2;
    // create stripe rect
    Path path = new Path();
    path.AppendRectangle(0, 0, stripeWidth, maskedImage.Height);

    // set initial translation
    pageContent.Translate(20, 300);
    // save state in order to restore it later for image
    pageContent.SaveGraphicsState();                               

    // draw gray stripes with a step of 20 points
    for (int i = 0; i < (maskedImage.Width / doubleStripeWidth); ++i)
    {                   
        pageContent.SetDeviceNonStrokingColor(new double[] {0.3});
        pageContent.FillPath(path);
        pageContent.Translate(doubleStripeWidth, 0);
    }
               
    pageContent.RestoreGraphicsState();

    // add image
    pageContent.AppendImage(maskedImage.ID,0,0,maskedImage.Width,maskedImage.Height);

    document.Save(outputStream);
}       

This code adds a set of gray stripes to create a background for transparent image and draws it over. Note that when we create the maskedImage object we set useTransparency flag to true. It indicates that library should automatically handle transparency by creating the corresponding softmask for this image if necessary.

The resulting image is shown below:

Pic. 1 Transparent image in PDF document

Pic. 1 Transparent image in PDF document

Conclusion


Working with transparent images doesn’t need additional coding when you’re using Apitron PDF Kit for .NET component. Read our free book to get the complete understanding on how the transparency works in PDF. It’s an invaluable resource for those interested in PDF internals and advanced processing. Contact us if you have questions or need help, we are always ready to help.

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