PDF Toolkit

Samples

Insert and Extract PDF Attachments

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

    
using Aquaforest.PDF;
using System.Collections.Generic;
    
namespace PDFAttachments
{
    internal class PDFAttachments
    {
        private static void Main(string[] args)
        {
            //Assign Licence Key
            PDFToolkit.LicenseKey = string.Empty;
            string inputFile = @"..\documents\source\image_pdf.pdf";
            string outputFolder = @"..\documents\output\extract\\";
            string outputFile = @"..\documents\output\attachment.pdf";
            PDFAttachmentItem item = new PDFAttachmentItem(@"..\documents\source\cookbook.pdf");
            PDFAttachmentItem item1 = new PDFAttachmentItem(@"..\documents\source\csv_input.csv");
            PDFAttachmentItem item2 = new PDFAttachmentItem(@"..\documents\source\stampFile.png");
            PDFAttachmentItem item3 = new PDFAttachmentItem(@"..\documents\source\xmp.xml");
    
            AddPDFAttchment(item, inputFile, outputFile);
            List allItems = new List { item, item1, item2, item3 };
    
            AddPDFAttchment(allItems, inputFile, outputFile);
            GetPDFAttchment(outputFolder, outputFile);
        }
    
        public static void AddPDFAttchment(List attachments, string inputFile, string ouptut)
        {
            PDFDocument pdfDoc = new PDFDocument(inputFile);
            pdfDoc.EmbedPDFAttachments(attachments);
            pdfDoc.Save(ouptut);
        }
    
        public static void AddPDFAttchment(PDFAttachmentItem attachments, string inputFile, string ouptut)
        {
            PDFDocument pdfDoc = new PDFDocument(inputFile);
            pdfDoc.EmbedPDFAttachment(attachments);
            pdfDoc.Save(ouptut);
        }
    
        public static void GetPDFAttchment(string outputFolder, string inputfile)
        {
            PDFDocument pdfDoc = new PDFDocument(inputfile);
            pdfDoc.ExtractAttachment(outputFolder);
        }
    }
}