Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,
How can we generate a pdf file with Video and Image slider.
Posted

1 solution

Hello there, have you ever used itextsharp? Its a beautiful library, it was a java library ported to c#.

http://sourceforge.net/projects/itextsharp/[^]

The sample code i've got below is for embedding a swf file into a pdf. With this sameple you should be able to try whatever other formats you may have and see if they will work by importing them into a pdf.

Please let me know if you have any questions.

Usings

C#
using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.richmedia;


Code

C#
static void Main(string[] args)
        {
            CreatePdfWithMedia(@"C:\temp\test.pdf");
        }

        public static void CreatePdfWithMedia(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 media = new RichMediaAnnotation(writer, new Rectangle(36, 400, 559, 806));
            PdfFileSpecification fs = PdfFileSpecification.FileEmbedded(writer, @"C:\temp\test.swf", "1.swf", null);
            PdfIndirectReference asset = media.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 = media.AddConfiguration(configuration);
            RichMediaActivation activation = new RichMediaActivation();
            activation.Configuration = configurationRef;
            media.Activation = activation;
            //--------------------
            PdfAnnotation richMediaAnnotation = media.CreateAnnotation();
            richMediaAnnotation.Flags = PdfAnnotation.FLAGS_PRINT;
            writer.AddAnnotation(richMediaAnnotation);
            //--------------------
            document.Close();
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900