PDF Toolkit

Samples

Get and Set PDF Viewer Preferences

This Code sample requires the PDF Toolkit and is found in: C:\Aquaforest\PDF Toolkit\samples\SetAndGetPDFOpensettings


using Aquaforest.PDF;
using System;

namespace SetAndGetPDFOpensettings
{
    internal class Opensettings
    {
        //Assign Licence Key
        private static void Main(string[] args)
        {
            //Assign Licence Key
            PDFToolkit.LicenseKey = string.Empty;
            string inputFile = @"..\documents\source\releasenotes.pdf";
            string outputFile = @"..\documents\output\setoptions.pdf";
            SetOpenOptions(inputFile, outputFile);
            ReadOpenOptions(outputFile);
        }

        public static void SetOpenOptions(string input, string output)
        {
            try
            {
                PDFDocument doc = new PDFDocument(input);
                //Create the opensettings object
                PDFDocumentOpenSetting opensetting = new PDFDocumentOpenSetting(doc);
                opensetting.PDFPageMode = PageModeOptions.FULL_SCREEN;
                opensetting.NonFullScreenPageMode = NonFullScreenModeOptions.UseThumbs;
                opensetting.HideWindowUI = true;
                opensetting.CenterWindow = true;
                opensetting.PDFPageLayout = PageLayoutOptions.ONE_COLUMN;
                opensetting.HideToolbar = true;
                opensetting.HideMenubar = true;
                opensetting.SaveOpenSettings(output);
                doc.Close();
            }
            catch (Exception)
            {
            }
        }

        public static void ReadOpenOptions(string input)
        {
            PDFDocument doc = new PDFDocument(input);
            PDFDocumentOpenSetting opensetting = new PDFDocumentOpenSetting(doc);
            Console.WriteLine("PageLayout = {0}, PageMode = {1}, HideWindowUI = {2} .", opensetting.PDFPageLayout, opensetting.PDFPageMode, opensetting.HideWindowUI);
            doc.Close();
        }
    }
}