We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to extract all the embeded audios in this pdf

Hi, Support:
How to extract all the embedded audios in this pdf?
The sample pdf has 38 audios, why the pdf.dll only extract 16 out of it.
Please fix this issue.
01 The Secret Word(1).pdf (5.3 MB)

@ducaisoft

Can you please share the sample code which you are using to extract the embedded audio files

My Code:
'Pdf.dll v21.3
Dim MyPdf As New Aspose.Pdf.Document(sFile)
Dim Count as integer
DIm IsScreenMedia as boolean
For Each annotation As Global.Aspose.Pdf.Annotations.Annotation In MyPdf.Pages.Annotations
If (annotation.AnnotationType = Aspose.Pdf.Annotations.AnnotationType.RichMedia Or annotation.AnnotationType = Aspose.Pdf.Annotations.AnnotationType.Sound) Then
Count = Count + 1
End If
Next
if Count =0 then
For Each annotation As Aspose.Pdf.Annotations.ScreenAnnotation In MyPdf.Pages.Annotations
Count = Count + 1
Next
IsScreenMedia = Count
end if

If IsScreenMedia Then
For Each annotation As Aspose.Pdf.Annotations.ScreenAnnotation In MyPdf.Pages.Annotations
Dim ann As ScreenAnnotation = annotation
Dim renditionAction As RenditionAction = ann.Action
Dim mediaRendition As MediaRendition = renditionAction.Rendition
Dim mediaclip As MediaClipData = mediaRendition.MediaClip
Dim fs = New FileStream(OutF, FileMode.CreateNew)
mediaclip.Data.Contents.CopyTo(fs)
fs.Flush()
fs.Close()
next
else

endif

@ducaisoft

I have used the code below which extracts 47 audio files so I suggest you to upgrade to latest version then share your feedback.

Document document = new Document("01 The Secret Word(1).pdf");
foreach (Page page in document.Pages)
    foreach (Annotation annotation in page.Annotations)
    {
        if (annotation is ScreenAnnotation)
        {
            var ann = annotation as ScreenAnnotation;
            RenditionAction renditionaction = ann.Action as RenditionAction;
            MediaRendition mediaRendition = renditionaction.Rendition as MediaRendition;
            MediaClipData mediaclip = mediaRendition.MediaClip as MediaClipData;
            FileStream fs = new FileStream(dataDir + mediaclip.Data.Name, FileMode.CreateNew);
            mediaclip.Data.Contents.CopyTo(fs);
            fs.Close();
        }
    }

Thanks.
Would you please email the latest pdf.dll based on Net 4.6.1 or higher to 15104946@qq.com? for it is very hard to download it from my end.

@ducaisoft

Email does not support big attachment so you can try downloading it from Downloads or NuGet.

Thanks for your suggestion.
I have downloaded the Apose.pdf.dll(v21.9,Net 4). then it was used in VB.net and Net4 and VS 2017. To be regret, the latest aspose.pdf.dll still extract on 6 audios out of the source.
Why? Please investigate this issue.

I have resolved this issue:
Rewrite the code like this:
For Each annotation As Aspose.Pdf.Annotations.ScreenAnnotation In MyPdf.Pages.Annotations
Count = Count + 1
Next

as the new ones like below:
For Each annotation As Aspose.Pdf.Annotations.Annotation In MyPdf.Pages.Annotations
if annotation.annotationType=annotation.Screen then Count = Count + 1
Next

Here the value Count will be the correct one,i.e., 47!

Another question is that: Why the old codes cannot get all the audios?

@ducaisoft

It’s good to hear that things are fine on your end. An investigation ticket with ID PDFNET-50760 has been created in our issue tracking system to further investigate the issue on our end. This thread has been linked with the issue so that you may be notified once the issue will be fixed.