Hi, Support:
I have some issues need your help.
Please see the attachment pdf file.
There are one or more audios objects embedded into the pdf file indicated by a speaker token.
Now,:
1.how to get the (x,y) position and (wxh) of each speaker on the given pdf page?
2.how to extract each embedded audio object and save as mpa file in each pdf file?
Thanks for your help!
How to locate the xy position of the horn.pdf (945.4 KB)
@ducaisoft
Please use following code snippet in order to extract position (Rectangle), height/width of the embedded audio file and save the file as .mpa:
Document pdfDocument = new Document(dataDir + "How to locate the xy position of the horn.pdf");
foreach (var page in pdfDocument.Pages)
{
foreach (Annotation annotation in page.Annotations)
{
if (annotation is RichMediaAnnotation)
{
var ann = annotation as RichMediaAnnotation;
FileStream fs = new FileStream(dataDir + "extractedaudio.mpa", FileMode.CreateNew);
ann.Content.CopyTo(fs);
fs.Close();
var rect = ann.Rect;
var height = ann.Height;
var width = ann.Width;
}
}
}
Dim Index as integer=0
Dim sfile As string = “C:\Temp\Demo.pdf”
Dim MyPdf as New Aspose.Pdf.Document(sFile)
Dim Pgs As Integer = MyPdf.Pages.Count
for p as integer =1 to Pgs
Dim PdfW As Integer = MyPdf.Pages§.Rect.Width
Dim PdfH As Integer = MyPdf.Pages§.Rect.Height
For Each annotation As Aspose.Pdf.Annotations.Annotation In MyPdf.Pages§.Annotations
If (annotation.AnnotationType = Aspose.Pdf.Annotations.AnnotationType.RichMedia) Then
Index =Index +1
Dim ann As RichMediaAnnotation = annotation
Dim ann As RichMediaAnnotation = annotation
Dim height = ann.Height
Dim width = ann.Width
Dm x = ann.Rect.LLX
Dim y = ann.Rect.LLY
x = x / PdfW * 100
y = (PdfH - y) / PdfH * 100
Dim outputFileName =“C:\Temp” & Index & “.mpa”
Dim fs As FileStream = New FileStream(outputFileName, FileMode.CreateNew)
Dim resourceWriter As BinaryWriter = New BinaryWriter(fs)
Dim Buffer() As Byte
ann.Content.Read(Buffer, 0, ann.Content.Length) 'Here, the value of Buffer is nothing
ann.Content.copyto(fs) 'Here, the system report the Member of CopyTo method is not defined
resourceWriter.Write(Buffer) 'The result is a 0 byte file.
fs.Write(Buffer, 0, ann.Content.Length) 'The result is a 0 byte file.
resourceWriter.Flush()
resourceWriter.Close()
resourceWriter = Nothing
fs.Close()
fs.Dispose()
fs.Flush()
fs.Close()
fs.Dispose()
fs = Nothing
end if
next
next
================
What’s wrong? How to fix it?
@ducaisoft
Please use the following modified code snippet:
Dim Index As Integer = 0
Dim sfile As String = “demo.pdf”
Dim MyPdf As New Aspose.Pdf.Document(sfile)
Dim Pgs As Integer = MyPdf.Pages.Count
For p As Integer = 1 To Pgs
Dim PdfW As Integer = MyPdf.Pages(p).Rect.Width
Dim PdfH As Integer = MyPdf.Pages(p).Rect.Height
For Each annotation As Aspose.Pdf.Annotations.Annotation In MyPdf.Pages(p).Annotations
If (annotation.AnnotationType = Aspose.Pdf.Annotations.AnnotationType.RichMedia) Then
Index = Index + 1
Dim ann As RichMediaAnnotation = annotation
Dim height = ann.Height
Dim width = ann.Width
Dim x = ann.Rect.LLX
Dim y = ann.Rect.LLY
x = x / PdfW * 100
y = (PdfH - y) / PdfH * 100
Dim outputFileName = “Temp” & Index & “.mpa”
Dim fs As FileStream = New FileStream(outputFileName, FileMode.Create)
'Dim resourceWriter As BinaryWriter = New BinaryWriter(fs)
'Dim Buffer() As Byte
'ann.Content.Read(Buffer, 0, ann.Content.Length) 'Here, the value of Buffer is nothing
ann.Content.CopyTo(fs) 'Here, the system report the Member of CopyTo method is not defined
'resourceWriter.Write(Buffer) 'The result is a 0 byte file.
'fs.Write(Buffer, 0, ann.Content.Length) 'The result is a 0 byte file.
'resourceWriter.Flush()
'resourceWriter.Close()
'resourceWriter = Nothing
fs.Close()
fs.Dispose()
End If
Next
Next
Thank you very much.
I have found the method to solve this problem, that’s to say, the method CopyYo must be based on at leas Net4.0.
@ducaisoft
It is nice to hear that your issue has been resolved. Please keep using our API and feel free to let us know in case you need further assistance.