PDF Toolkit

Samples

Convert Office Files To PDF

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


using Aquaforest.Office.PDF;
using Aquaforest.PDF;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
    
    
namespace OfficeToPDFConversion
{
    class OfficeConversion
    {
    
        static void Main(string[] args)
        {
            //Assign Licence Key
            PDFToolkit.LicenseKey = string.Empty;
            string wordInput = @"..\documents\source\Skills.docx";
            string excelInput = @"..\documents\source\excel.xlsx";
            string powerPointInput = @"..\documents\source\split.pptx";
            string pubInput = @"..\documents\source\publisher.pub";
            string wordOutput = @"..\documents\output\word.pdf";
            string excelOutput = @"..\documents\output\excel.pdf";
            string powerPointOutput = @"..\documents\output\powerpoint.pdf";
            string pubOutput = @"..\documents\output\pub.pdf";
            DocumentSettings docSettings = new DocumentSettings {BookmarkOption=AquaforestPDFBookmarks.BOOKMARKS_FROM_HEADINGS,PDFA1a= true};
            ConvertWordToPDF(wordInput,wordOutput,docSettings);
            ConvertExcelToPDF(excelInput, excelOutput, docSettings);
            ConvertPowerPointToPDF(powerPointInput, powerPointOutput, docSettings);
            ConvertPublisherToPDF(pubInput, pubOutput, docSettings);
        }
        public static void ConvertWordToPDF(string input,string output,DocumentSettings settings)
        {
            try
            {
                WordToPDF wordToPDF = new WordToPDF(Path.GetFullPath(input));
                wordToPDF.ConvertToPDF(settings, Path.GetFullPath(output));
            }
            catch(Exception)
            {
    
            }
    
        }
        public static void ConvertExcelToPDF(string input, string output, DocumentSettings settings)
        {
            try
            {
                ExcelToPDF wordToPDF = new ExcelToPDF(Path.GetFullPath(input));
                wordToPDF.ConvertToPDF(settings, Path.GetFullPath(output));
            }
            catch (Exception)
            {
    
            }
        }
        public static void ConvertPowerPointToPDF(string input, string output, DocumentSettings settings)
        {
            try
            {
                PowerPointToPDF wordToPDF = new PowerPointToPDF(Path.GetFullPath(input));
                settings.OptimizeFor = 0;
                wordToPDF.DocStructureTags =true;
                wordToPDF.FrameSlides = true;            
                wordToPDF.ConvertToPDF(settings, Path.GetFullPath(output));
            }
            catch (Exception)
            {
    
            }
        }
        public static void ConvertPublisherToPDF(string input, string output, DocumentSettings settings)
        {
            try
            {
                PublisherToPDF wordToPDF = new PublisherToPDF(Path.GetFullPath(input));
                wordToPDF.ConvertToPDF(settings, Path.GetFullPath(output));
            }
            catch (Exception)
            {
    
            }
        }
    
    }
}