How do I extract movies, multimedia, and custom annotations from PDF?

2,638 views
Skip to first unread message

Support

unread,
Nov 17, 2009, 3:16:26 PM11/17/09
to PDFTron PDFNet SDK
Q: We have tested the samples with annotations (http://www.pdftron.com/
pdfnet/samplecode.html#Annotation). It works well with the supplied
test files.

Then we tried to open our PDF file with an embedded video (see
attached). It opens and displays that the file has one annotation and
its type is “Screen”, but we weren‘t able to EXTRACT the video and
SAVE its content to hard drive. Could you confirm that it is possible
to do with your solution and provide some code example?

---------------
A: We didn’t receive your sample file yet, however I wanted to
confirm that you can use PDFNet SDK to extract any type of content
from PDF (including videos from Screen annotations).

In case of Screen annotations the actual multimedia data (i.e. movie)
is stored in ‘Rendition Action’ which is associated with the
annotation. Assuming that you are developing using C# you could use do
the following lines to extract the movie:

// This snippet builds on Annotation sample project:
// http://www.pdftron.com/pdfnet/samplecode.html#Annotation

for (int i = 0; i < num_annots; i++) {
Annot annot = page.GetAnnot(i);
if (annot.GetType() == Annot.Type.e_Screen) {
pdftron.PDF.Annots.Screen screen = new pdftron.PDF.Annots.Screen
(annot);
Action action = screen.GetAction();
if (action.GetType() == Action.Type.e_Rendition) {
Obj rend = action.GetSDFObj().FindObj("R");
if (rend != null) {
// Obtain a 'media clip' dictionary
Obj mc = rend.FindObj("C");
if (mc != null)
{
FileSpec fs = new FileSpec(rend.FindObj("D"));
fs.Export(@"c:\mymovie.avi");
}
}
}
}
}

The structure of rendition actions is documented in section 12.6.4.13
'Rendition Actions' of PDF Reference Manual.

Support

unread,
Nov 17, 2009, 3:22:36 PM11/17/09
to PDFTron PDFNet SDK
Q: I assume that some of PDFs I have created myself with Acrobat Pro 9
has video stored in a way other than this code expects.
However we have to be able to process all kind of embedded videos.

------------
A: Some of the PDF you send contain Adobe proprietary annotation type
called 'RichMedia'. This annotation type is described in
http://www.adobe.com/devnet/acrobat/pdfs/adobe_supplement_iso32000.pdf:

"The rich media annotation means that Flash applications, video,
audio, and other multimedia can be attached
to a PDF document. The rich media annotation incorporates the existing
3D annotation structure to
support multiple multimedia file assets, including Flash video and
compatible variations on the H.264
format."

You can identify and process 'RichMedia' and other custom annotations
as follows:

PageIterator itr = doc.GetPageIterator();
for (; itr.HasNext(); itr.Next())
{
Console.WriteLine("Page {0:d}: ", itr.GetPageNumber());

Page page = itr.Current();
int num_annots = page.GetNumAnnots();
for (int i = 0; i < num_annots; ++i)
{
Annot annot = page.GetAnnot(i);
if (annot.IsValid() == false) continue;

if (annot.GetType() == Annot.Type.e_Unknown)
{
Obj ad = annot.GetSDFObj();
if ("RichMedia" == ad.Get("Subtype").Value().GetName())
{
Rect bbox = annot.GetRect();
Console.WriteLine(" Position: {0:f}, {1:f}, {2:f}, {3:f}",
bbox.x1, bbox.y1, bbox.x2, bbox.y2);

Obj mc = ad.FindObj("RichMediaContent");
if (mc != null)
{
// NameTree is in pdftron.SDF namespace
NameTree assets = new NameTree(mc.FindObj("Assets"));
if (!assets.IsValid()) continue;
NameTreeIterator j = assets.GetIterator();
for (; j.HasNext(); j.Next())
{
string assent_name = j.Key().GetAsPDFText();
FileSpec file_spec = new FileSpec(j.Value());
Filter stm = file_spec.GetFileData();
if (stm != null)
{
FilterReader reader = new FilterReader(stm);
StdFile f = new StdFile(output_path + assent_name,
StdFile.OpenMode.e_write_mode);
FilterWriter writer = new FilterWriter(f);
writer.WriteFilter(reader);
writer.Flush();
f.Close();
}
}
}
}
}
}
}

All of the details are described in the reference manual.

Support

unread,
Oct 7, 2014, 11:55:41 PM10/7/14
to pdfne...@googlegroups.com

For more info on how to use RichMediaAnnotations on mobile (e.g. Android, iOS, ..)
Reply all
Reply to author
Forward
0 new messages