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

Notification

Icon
Error

New Topic Post Reply
Options
Go to last post Go to first unread
dc.greatus  
#1 Posted : Tuesday, June 6, 2017 9:25:13 PM(UTC)
Quote
dc.greatus

Rank: Newbie

Groups: Registered
Joined: 6/6/2017(UTC)
Posts: 1
Hungary

Was thanked: 1 time(s) in 1 post(s)
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 54 time(s).

Thanks Paul!

Edited by moderator Thursday, June 8, 2017 7:48:13 PM(UTC)  | Reason: Not specified

thanks 1 user thanked dc.greatus for this useful post.
Paul Rayman on 6/8/2017(UTC)
Quick Reply Show Quick Reply
Users browsing this topic
Guest
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.