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.

2016-01-26

Apitron PDF Kit and Apitron PDF Rasterizer - engine settings explained

Introduction


Apitron PDF Kit for .NET and Apitron PDF Rasterizer for .NET both share a common approach for fine tuning their internal engines PDF processing engines. One may use EngineSettings class for that and control the memory usage, as well as font substitution and fallback. In addition the Apitron PDF Rasterizer has a RenderingSettings class that controls the rendering.  In this article we’ll explain how to use EngineSettings and what each setting means.

The code


Example below shows how to use global engine settings for both Apitron PDF Kit and Apitron PDF Rasterizer, and also rendering settings. The piece of code related to rasterizer demonstrates the usage of per document engine settings as well.

static void Main(string[] args)
{           
    /* GLOBAL SETTINGS usage, same for Apitron PDF Kit  and Apitron PDF Rasterizer */

    // controls whether we have to unload resources whenever possible based on 
    // size limit setting, if the resource takes more than allowed it will be unloaded.
    EngineSettings.GlobalSettings.MemoryAllocationMode = 
        MemoryAllocationMode.ResourcesLowMemory;
    // sets the resource size limit
    EngineSettings.GlobalSettings.ResourceSizeLimit = 1048676;

    // system font paths used to find external fonts [readonly].
    ICollection<string> systemFontPaths = EngineSettings.SystemFontPaths;

    // a collection used to specifiy additional font search paths
    ICollection<string> userFontPaths = EngineSettings.UserFontPaths;
    // example:
    userFontPaths.Add(@"c:\\myfonts");

    // set font fallbacks
    // map Arial and Calibri to Helvetica if they are not embedded in document
    // and not found in system and user font folders
    EngineSettings.UserFontMappings.Add(new KeyValuePair<string, string[]>("Helvetica",
        new string[]{"Arial","Calibri"}));
    // map all not found fonts to TimesNewRoman using special name "*"
    EngineSettings.UserFontMappings.Add(new KeyValuePair<string, string[]>("TimesNewRoman",
        new string[]{"*"}));

    // registers additional font in library's font cache if don't have a user font folder
    // or can't create one. Font name and parameters will be read from font file.
    using (Stream fontStream = File.Open("c:\\fonts\\Consolas.ttf", FileMode.Open))
    {
        EngineSettings.RegisterUserFont(fontStream);
    }

    // unregister all fonts registered via RegisterUserFonts()
    EngineSettings.UnregisterUserFonts();

    // create document
    using (Stream outputDocument = File.Create("document.pdf"))
    {
        FixedDocument document = new FixedDocument();
        document.Pages.Add(new Page());
        document.Save(outputDocument);
    }           

    /* Apitron PDF Rasterizer only usage*/
    using (Stream inputDocument = File.Open("document.pdf", FileMode.Open))
    {
        // create engine settings instance and set memory usage limit
        Apitron.PDF.Rasterizer.Configuration.EngineSettings settings =
           new Apitron.PDF.Rasterizer.Configuration.EngineSettings();
        settings.MemoryAllocationMode =
           Apitron.PDF.Rasterizer.Configuration.MemoryAllocationMode.ResourcesLowMemory;
        settings.ResourceSizeLimit = 2000000; 

        // open PDF document using specific engine settings,
        // these settings will be applied to this document only
        using (Document doc = new Document(inputDocument, settings))
        {
            // create rendering settings instance
            RenderingSettings renderingSettings = new RenderingSettings();
            // turn off annotations drawing for example
            renderingSettings.DrawAnotations = false;

            // render page
            Bitmap bitmap = doc.Pages[0].Render(new Resolution(96, 96), renderingSettings);
            bitmap.Save("page0.png");
        }
    }
}

Using engine settings you can: control memory usage; define font substitution and fallback behavior, register own fonts. Using rendering settings you can: control which parts of content should be drawn or not, control rendering speed and quality as well as scale mode used.
The complete code sample can be found in our github repo.


Conclusion 


Apitron PDF products are highly customizable and can be set up to work under many different conditions. If you have any questions or need help, just drop us an email and we’ll be happy to consult you.

No comments:

Post a Comment