26 Temmuz 2011 Salı

Itextsharp File Attachment Event

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text.pdf;
using iTextSharp.text;
using iTextSharp.text.xml;
using iTextSharp.text.pdf.events;
using System.IO;

public class FileAttachmentEvent : PdfPCellEventForwarder
    {
        protected PdfWriter writer;
        protected PdfFileSpecification fs;
        protected String description;

        public FileAttachmentEvent(PdfWriter Writer, PdfFileSpecification Fs, String Description)
        {
            this.writer = Writer;
            this.fs = Fs;
            this.description = Description;
        }

        public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases)
        {
            try
            {
                PdfAnnotation annonation = PdfAnnotation.CreateFileAttachment(writer, new Rectangle(position.GetLeft(20f), position.GetTop(15f),
                    position.GetLeft(5f), position.GetTop(5f)), description, fs);
                annonation.Name = description;
                writer.AddAnnotation(annonation);
            }
            catch (IOException)
            {
                throw;
            }
        }
    }

Hiç yorum yok:

Yorum Gönder