التعليقات التوضيحية للوسائط في PDF
Contents
[
Hide
]
عادةً ما تغطي التعليقات التوضيحية للوسائط في PDF المحتوى المتعدد الوسائط المدمج أو المرتبط مثل مقاطع الصوت، ومناطق تشغيل الشاشة، وحاويات الوسائط الغنية، والنماذج ثلاثية الأبعاد.
إضافة تعليقا بوسائط غنية
استخدم هذا المثال عندما يجب أن تستضيف صفحة PDF محتوى فيديو مدمج مع مشغل مخصص، صورة ملصق، ومظهر.
- أنشئ مستند PDF جديدًا باستخدام Document وأضف صفحة.
- أنشئ كائنًا من الفئة RichMediaAnnotation، اضبط أصول المشغل، الملصق، وتدفق المحتوى.
- أضف التعليق التوضيحي إلى الصفحة واحفظ مستند الإخراج.
public static void richMediaAnnotationsAdd(Path mediaDir, Path outputFile) throws Exception {
String pathToAdobeApp = "C:\\Program Files (x86)\\Adobe\\Acrobat 2017\\Acrobat\\Multimedia Skins";
try (Document document = new Document()) {
Page page = document.getPages().add();
String videoName = "file_example_MP4_480_1_5MG.mp4";
String posterName = "file_example_MP4_480_1_5MG_poster.jpg";
String skinName = "SkinOverAllNoFullNoCaption.swf";
RichMediaAnnotation richMediaAnnotation = new RichMediaAnnotation(
page,
new Rectangle(100, 500, 300, 600, true));
String playerPath = pathToAdobeApp + "\\Players\\Videoplayer.swf";
richMediaAnnotation.setCustomPlayer(new FileInputStream(playerPath));
richMediaAnnotation.setCustomFlashVariables("source=" + videoName + "&skin=" + skinName);
String skinPath = pathToAdobeApp + "\\" + skinName;
richMediaAnnotation.addCustomData(skinName, new FileInputStream(skinPath));
Path posterPath = mediaDir.resolve(posterName);
richMediaAnnotation.setPoster(new FileInputStream(posterPath.toString()));
Path videoPath = mediaDir.resolve(videoName);
try (FileInputStream videoStream = new FileInputStream(videoPath.toString())) {
richMediaAnnotation.setContent(videoName, videoStream);
}
richMediaAnnotation.setType(RichMediaAnnotation.ContentType.Video);
richMediaAnnotation.setActivateOn(RichMediaAnnotation.ActivationEvent.Click);
richMediaAnnotation.update();
page.getAnnotations().add(richMediaAnnotation);
document.save(outputFile.toString());
}
}
حذف تعليقات الوسائط الغنية
يقوم هذا المثال بإزالة التعليقات التوضيحية للوسائط المتعددة الغنية الموجودة من صفحة.
- افتح ملف PDF المصدر Document.
- اجمع التعليقات التوضيحية من النوع AnnotationType.
RichMedia. - احذف التعليقات التوضيحية المجمعة واحفظ المستند المحدَّث.
public static void richMediaAnnotationsDelete(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
Page page = document.getPages().get_Item(1);
List<Annotation> toDelete = new ArrayList<>();
for (Annotation annotation : page.getAnnotations()) {
if (annotation.getAnnotationType() == AnnotationType.RichMedia) {
toDelete.add(annotation);
}
}
for (Annotation annotation : toDelete) {
page.getAnnotations().delete(annotation);
}
document.save(outputFile.toString());
}
}
احصل على التعليقات المتعددة الوسائط
استخدم هذا المثال لتفقد التعليقات التوضيحية للصور المتحركة والصوت والوسائط الغنية الموجودة بالفعل على الصفحة.
- افتح ملف PDF المصدر Document.
- حدّد مجموعة أنواع التعليقات التوضيحية المتعددة الوسائط التي تريد اكتشافها.
- مرّ على ملاحظات الصفحة واطبع النوع والمستطيل لكل مطابقة.
public static void multimediaAnnotationsGet(Path inputFile) {
try (Document document = new Document(inputFile.toString())) {
Set<AnnotationType> targetTypes = Set.of(
AnnotationType.Screen,
AnnotationType.Sound,
AnnotationType.RichMedia);
for (Annotation annotation : document.getPages().get_Item(1).getAnnotations()) {
if (targetTypes.contains(annotation.getAnnotationType())) {
System.out.println(annotation.getAnnotationType() + " [" + annotation.getRect() + "]");
}
}
}
}
إضافة تعليق ثلاثي الأبعاد
يضيف هذا المثال عرضًا تفاعليًا للنموذج ثلاثي الأبعاد مع وجهات نظر محددة مسبقًا وخيارات التصيير.
- أنشئ مستند PDF جديدًا باستخدام Document.
- حمّل النموذج إلى PDF3DContent واضبط PDF3DArtwork.
- أنشئ كائنًا من الفئة PDF3DAnnotation، أضفه إلى صفحة، واحفظ المستند.
public static void annotation3dAdd(Path modelFile, Path outputFile) {
try (Document document = new Document()) {
PDF3DContent pdf3dContent = new PDF3DContent(modelFile.toString());
PDF3DArtwork pdf3dArtwork = new PDF3DArtwork(document, pdf3dContent);
pdf3dArtwork.setLightingScheme(new PDF3DLightingScheme(LightingSchemeType.CAD));
pdf3dArtwork.setRenderMode(new PDF3DRenderMode(RenderModeType.Solid));
Matrix3D topMatrix = new Matrix3D(
1, 0, 0,
0, -1, 0,
0, 0, -1,
0.10271, 0.08184, 0.273836);
Matrix3D frontMatrix = new Matrix3D(
0, -1, 0,
0, 0, 1,
-1, 0, 0,
0.332652, 0.08184, 0.085273);
pdf3dArtwork.getViewArray().add(new PDF3DView(document, topMatrix, 0.188563, "Top"));
pdf3dArtwork.getViewArray().add(new PDF3DView(document, frontMatrix, 0.188563, "Left"));
Page page = document.getPages().add();
PDF3DAnnotation pdf3dAnnotation = new PDF3DAnnotation(
page,
new Rectangle(100, 500, 300, 700, true),
pdf3dArtwork);
pdf3dAnnotation.setBorder(new com.aspose.pdf.Border(pdf3dAnnotation));
pdf3dAnnotation.setDefaultViewIndex(1);
pdf3dAnnotation.setFlags(AnnotationFlags.NoZoom);
pdf3dAnnotation.setName(modelFile.getFileName().toString());
page.getAnnotations().add(pdf3dAnnotation);
document.save(outputFile.toString());
}
}
إضافة تعليق على الشاشة
استخدم هذا المثال عندما يجب على الصفحة الإشارة إلى ملف وسائط عبر منطقة تشغيل الشاشة.
- أنشئ مستند PDF جديدًا باستخدام Document وأضف صفحة.
- أنشئ كائنًا من الفئة ScreenAnnotation لملف الوسائط والمستطيل الهدف.
- أضف التعليق التوضيحي إلى الصفحة واحفظ المستند.
public static void screenAnnotationWithMediaAdd(Path mediaFile, Path outputFile) {
try (Document document = new Document()) {
Page page = document.getPages().add();
ScreenAnnotation screenAnnotation = new ScreenAnnotation(
page,
new Rectangle(170, 190, 470, 380, true),
mediaFile.toString());
page.getAnnotations().add(screenAnnotation);
document.save(outputFile.toString());
}
}
إضافة تعليق صوتي
يوضح هذا المثال وضع ملاحظة صوتية على الصفحة وربطها بملف WAV.
- افتح ملف PDF المصدر Document.
- أنشئ كائنًا من الفئة SoundAnnotation لملف الصوت الهدف واضبط البيانات الوصفية الخاصة به.
- أضف التعليق التوضيحي إلى الصفحة واحفظ مستند الإخراج.
public static void soundAnnotationAdd(Path inputFile, Path outputFile) {
try (Document document = new Document(inputFile.toString())) {
Page page = document.getPages().get_Item(1);
Path mediaFile = inputFile.getParent().resolve("file_example_WAV_1MG.wav");
SoundAnnotation soundAnnotation = new SoundAnnotation(
page,
new Rectangle(20, 700, 60, 740, true),
mediaFile.toString());
soundAnnotation.setColor(Color.getBlue());
soundAnnotation.setTitle("John Smith");
soundAnnotation.setSubject("Sound Annotation demo");
soundAnnotation.setPopup(new PopupAnnotation(
page,
new Rectangle(20, 700, 60, 740, true)));
page.getAnnotations().add(soundAnnotation);
document.save(outputFile.toString());
}
}