logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Post a reply
From:
Message:

Maximum number of characters in each post is: 32767
Bold Italic Underline   Highlight Quote Choose Language for Syntax Highlighting Insert Image Insert an existing Attachment or upload a new File... Create Link   Unordered List Ordered List   Left Justify Center Justify Right Justify   Outdent Indent   More BBCode Tags
Font Color Font Size
Security Image:
Enter The Letters From The Security Image:
  Preview Post Cancel

Last 10 Posts (In reverse order)
dc.greatus Posted: Tuesday, June 6, 2017 9:25:13 PM(UTC)
 
As some do know, pdf does support so caled "rich media".

There are some limitations, but pdf is good for holding h264 video in mp4 format.
I created a pdf ("mp4.pdf", using acrobat pro) and inserted one mp4 video in it.
Tried to use pdfium, but could not figure out how to access the mp4 itself.

Asked for some support
and Paul Rayman kindly showed me a solution for this. Here it goes.


Code:
 
           PdfCommon.Initialize();
           var doc = PdfDocument.Load(@"d:\0\9\mp4.pdf");
           var page = doc.Pages[0];
           var dict = page.Dictionary;
           var annots = ((dict["Annots"] as PdfTypeIndirect).Direct) as PdfTypeArray;
           var annotation = ((annots[0] as PdfTypeIndirect).Direct) as PdfTypeDictionary;
           if ((annotation["Subtype"] as PdfTypeName).Value == "RichMedia")
           {
               //this is your media dictionary
               var mediaSettings = annotation["RichMediaSettings"] as PdfTypeDictionary;
               var mediaContent = (annotation["RichMediaContent"] as PdfTypeIndirect).Direct as PdfTypeDictionary;
               var names = ((mediaContent["Assets"] as PdfTypeIndirect).Direct as PdfTypeDictionary)["Names"] as PdfTypeArray;
               for(int i = 0; i< names.Count; i+=2)
               {
                   string filename = (names[i] as PdfTypeString).UnicodeString;
                   var fileDict = (names[i + 1] as PdfTypeIndirect).Direct as PdfTypeDictionary;
                   var stream = ((fileDict["EF"] as PdfTypeDictionary)["F"] as PdfTypeIndirect).Direct as PdfTypeStream;
                   var data = new byte[stream.Length];
                   stream.Read(0, data.Length, data);
                   System.IO.File.WriteAllBytes(string.Format(@"d:\0\9\Files\{0}", filename), data);
               }
           }



Quote:

As a result a three files will be created inside the "d:\0\9\Files\" folder:
VideoPlayer.swf
SkinOverAllNoFullNoCaption.swf
sample.mp4


sample document: mp4.pdf (848kb) downloaded 56 time(s).

Thanks Paul!