21 Temmuz 2011 Perşembe

Itextsharp swf view methods

Itextsharp dll i kullanarak oluşturduğumuz pdf te istenilen swf dosyaları oynatmak için yazmış olduğum method örneği

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text.pdf;
using iTextSharp.text;
using iTextSharp.text.xml;
using System.IO;
using System.Xml;
using iTextSharp.text.pdf.codec;
using iTextSharp.text.pdf.parser;
using iTextSharp.text.pdf.richmedia;

public void PdfFlash(string file)
        {
            string day = DateTime.Now.ToString("dd/MM/yyyy");

            Document document = new Document();
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(file, FileMode.Create));
            writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_7);
            writer.AddDeveloperExtension(PdfDeveloperExtension.ADOBE_1_7_EXTENSIONLEVEL3);

            document.Open();

            RichMediaAnnotation richMedia = new RichMediaAnnotation(writer, new Rectangle(36, 400, 559, 806));
            PdfFileSpecification fs = PdfFileSpecification.FileEmbedded(writer, @"C:\1.swf", "1.swf", null);
            PdfIndirectReference asset = richMedia.AddAsset("1.swf", fs);
            RichMediaConfiguration configuration = new RichMediaConfiguration(PdfName.FLASH);
            RichMediaInstance instance = new RichMediaInstance(PdfName.FLASH);
            RichMediaParams flashVars = new RichMediaParams();
            String vars = day;
            flashVars.FlashVars = vars;
            instance.Params = flashVars;
            instance.Asset = asset;
            configuration.AddInstance(instance);
            PdfIndirectReference configurationRef = richMedia.AddConfiguration(configuration);
            RichMediaActivation activation = new RichMediaActivation();
            activation.Configuration = configurationRef;
            richMedia.Activation = activation;
            PdfAnnotation richMediaAnnotation = richMedia.CreateAnnotation();
            richMediaAnnotation.Flags = PdfAnnotation.FLAGS_PRINT;
            writer.AddAnnotation(richMediaAnnotation);
            document.Close();
        }

Hiç yorum yok:

Yorum Gönder