How To embed a flash in pdf through pdftron

677 views
Skip to first unread message

Priya007

unread,
Jul 21, 2010, 4:27:35 AM7/21/10
to PDFTron PDFNet SDK
Hi,

I want to embed .swf files or audio/vedio files in pdf. Can anyone
tell me how can I do this. Is their any sample for this?

Support

unread,
Dec 10, 2014, 8:08:15 PM12/10/14
to

You would need to create a custom annotation type with "RichMedia"
Subtype. Please note that RichMedia annotation is a proprietary
Adobe's extension (see http://www.adobe.com/devnet/acrobat/pdfs/adobe_supplement_iso32000.pdf)
and is not part of ISO32000.  The code would look along the following
lines:

// Assuming C# (JAVA,C/C++,VB is similar)
// This is a drop-in replacement for Annotation sample project

using pdftron; 
using pdftron.Common; 
using pdftron.Filters; 
using pdftron.SDF; 
using pdftron.PDF; 

namespace AnnotationTestCS
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
        private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();

        static void EmbedFlash(PDFDoc doc) 
        {
            string input_path = "../../../../TestFiles/";

            pdftron.PDF.Annot a = Annot.Create(doc, Annot.Type.e_RichMedia, new Rect(12, 632, 604, 771)); 
            Obj dict = a.GetSDFObj(); 

            Obj  mc = dict.PutDict("RichMediaContent"); 

            // Embed the flash file. 
            string flash_file = "header.swf";
            FileSpec fs = FileSpec.Create(doc, input_path + flash_file, true); 

            fs.GetSDFObj().PutString("F", flash_file);  // Not sure if this is right for non-ascii file paths. Hopefuly in this case UF should be taken as authority. 
            fs.GetSDFObj().PutText("UF", flash_file); 


            // Create/find the asset NameTree. 
            NameTree assets = pdftron.SDF.NameTree.Create(doc, "Assets"); 
            assets.Put(System.Text.Encoding.UTF8.GetBytes("header.swf"), fs.GetSDFObj()); 

            mc.Put("Assets", assets.GetSDFObj()); 

            Obj config = doc.CreateIndirectDict(); 
            config.PutName("Subtype", "Flash"); 

            Obj instance = doc.CreateIndirectDict(); 
            instance.Put("Asset", fs.GetSDFObj()); 
            instance.PutDict("Params").PutName("Binding", "Background"); 

            Obj instances = doc.CreateIndirectArray(); 
            instances.PushBack(instance); 
            config.Put("Instances", instances); 

            Obj configs = doc.CreateIndirectArray(); 
            configs.PushBack(config); 

            mc.Put("Configurations", configs); 

            // Optional: Fill-in RichMediaSettings dictionary 
            // Obj  ms = dict.PutDict("RichMediaSettings"); 

            //... 
            // add annotation to the page. 
            Page page = doc.GetPage(1); 
            page.AnnotPushBack(a); 
        }

        static void Main(string[] args)
        {
            PDFNet.Initialize();
            try
            {
                using (PDFDoc doc = new PDFDoc("../../../../TestFiles/numbered.pdf"))
                {
                    doc.InitSecurityHandler();
                    EmbedFlash(doc);
                    doc.Save("../../../../TestFiles/Output/our.pdf", SDFDoc.SaveOptions.e_linearized);
                }
            }
            catch (PDFNetException e)
            {
                System.Console.WriteLine(e.Message);
            }
        } 

}
}

The above sample code referenced following Flash file:
http://www.pdftron.com/assets/flash/header.swf   (which you can save under PDFNet\Samples\TestFiles\).

For example of how to extract flash movies and other RichMedia from
PDF please see:
  http://groups.google.com/group/pdfnet-sdk/browse_thread/thread/d3ef6d8d15691bd5/ba33d2cb885cdfbb




AnnotationTest.cs
header.swf

Priya007

unread,
Jul 28, 2010, 3:27:35 AM7/28/10
to PDFTron PDFNet SDK
Hi,

Thanks a lot for this solution. It's really working fine.
Your answer has solved one of my biggest issue.
Thanks again :)

But I still have an issue of embedding Vedio/audio files in my PDF
through PDFTron.

Is it possible to embed Vedio/Audio file in my PDF through PDFTron.

It will be really greatful if you can provide me any solution for
this.


Thanks in advance.

On Jul 28, 4:12 am, Support <supp...@pdftron.com> wrote:
> You would need to create a custom annotation type with "RichMedia"
> Subtype. Please note that RichMedia annotation is a proprietary
> Adobe's extension (seehttp://www.adobe.com/devnet/acrobat/pdfs/adobe_supplement_iso32000.pdf)
> and is not part of ISO32000.  The code would look along the following
> lines:
>
> // Assuming C# (JAVA,C/C++,VB is similar)
>
> using pdftron;
> using pdftron.Common;
> using pdftron.Filters;
> using pdftron.SDF;
> using pdftron.PDF;
>
> static void EmbedFlash(PDFDoc doc)
> {
>         pdftron.PDF.Annot a = Annot.Create(doc, Annot.Type.e_RichMedia, new
> Rect(12, 632, 604, 771));
>         Obj dict = a.GetSDFObj();
>
>         Obj  mc = dict.PutDict("RichMediaContent");
>
>         // Embed the flash file.
>         string flash_file = "header.swf";
>         FileSpec fs = FileSpec.Create(doc, @"D:\" + flash_file, true);
>             using (PDFDoc doc = new PDFDoc("my.pdf")) {
>                 doc.InitSecurityHandler();
>                 EmbedFlash(doc);
>                 doc.Save(output_path + "annotation_test2.pdf",
> SDFDoc.SaveOptions.e_linearized);
>             }
>         }
>         catch (PDFNetException e) {
>                 System.Console.WriteLine(e.Message);
>         }
>
> }
>
> The above sample code referenced following Flash file:http://www.pdftron.com/assets/flash/header.swf
>
> For example of how to extract flash movies and other RichMedia from
> PDF please see:
>  http://groups.google.com/group/pdfnet-sdk/browse_thread/thread/d3ef6d...

Support

unread,
May 26, 2015, 3:11:35 AM5/26/15
to pdfne...@googlegroups.com

For more info related to RichMedia annotations (specifically extraction & playback) see:

Working with PDF RichMedia annotations



On Tuesday, July 27, 2010 at 4:12:04 PM UTC-7, Support wrote:

You would need to create a custom annotation type with "RichMedia"
Subtype. Please note that RichMedia annotation is a proprietary
and is not part of ISO32000.  The code would look along the following
lines:

// Assuming C# (JAVA,C/C++,VB is similar)
// This is a drop-in replacement for Annotation sample project

using pdftron; 
using pdftron.Common; 
using pdftron.Filters; 
using pdftron.SDF; 
using pdftron.PDF; 

namespace AnnotationTestCS
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
        private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();

        static void EmbedFlash(PDFDoc doc) 
        {
            string input_path = "../../../../TestFiles/";

            pdftron.PDF.Annot a = Annot.Create(doc, Annot.Type.e_RichMedia, new Rect(12, 632, 604, 771)); 
            Obj dict = a.GetSDFObj(); 

            Obj  mc = dict.PutDict("RichMediaContent"); 

            // Embed the flash file. 
            string flash_file = "header.swf";
            FileSpec fs = FileSpec.Create(doc, input_path + flash_file, true); 
                using (PDFDoc doc = new PDFDoc("../../../../TestFiles/numbered.pdf"))
                {
                    doc.InitSecurityHandler();
                    EmbedFlash(doc);
                    doc.Save("../../../../TestFiles/Output/our.pdf", SDFDoc.SaveOptions.e_linearized);
                }
            }
            catch (PDFNetException e)
            {
                System.Console.WriteLine(e.Message);
            }
        } 

}
}

The above sample code referenced following Flash file:
http://www.pdftron.com/assets/flash/header.swf   (which you can save under PDFNet\Samples\TestFiles\).

For example of how to extract flash movies and other RichMedia from
PDF please see:
Reply all
Reply to author
Forward
0 new messages