|
|
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!
|
Important Information:
The Patagames Software Support Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close