根據Bruno Lowagie的建議,我使用RichMediaAnnotation編寫了以下代碼。但該視頻並未顯示在生成的PDF中。任何想法我在這裏失蹤?
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("richMedia.pdf"));
document.open();
writer.setPdfVersion(PdfWriter.PDF_VERSION_1_7);
writer.addDeveloperExtension(PdfDeveloperExtension.ADOBE_1_7_EXTENSIONLEVEL3);
RichMediaAnnotation richMedia = new RichMediaAnnotation(writer, new Rectangle(10,10,150,75));
PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(writer, RESOURCE, "VideoPlayer.swf", null);
PdfIndirectReference asset = richMedia.addAsset("VideoPlayer.swf", fs);
RichMediaConfiguration configuration = new RichMediaConfiguration(PdfName.VIDEO);
RichMediaInstance instance = new RichMediaInstance(PdfName.VIDEO);
RichMediaParams vars = new RichMediaParams();
vars.setBinding(PdfName.BACKGROUND);
instance.setAsset(asset);
configuration.addInstance(instance);
PdfIndirectReference configRef = richMedia.addConfiguration(configuration);
RichMediaActivation activation = new RichMediaActivation();
activation.setCondition(PdfName.XA);
RichMediaPresentation presentation = new RichMediaPresentation();
presentation.setPassContextClick(PdfBoolean.PDFFALSE);
presentation.setTransparent(PdfBoolean.PDFFALSE);
presentation.setStyle(PdfName.WINDOWED);
RichMediaWindow window = new RichMediaWindow();
window.setHeight(240, 800, 64);
window.setWidth(320, 800, 64);
presentation.setWindow(window);
presentation.setNavigationPane(PdfBoolean.PDFFALSE);
presentation.setToolbar(PdfBoolean.PDFFALSE);
activation.setPresentation(presentation);
activation.setConfiguration(configRef);
richMedia.setActivation(activation);
PdfAnnotation richMediaAnnotation = richMedia.createAnnotation();
writer.addAnnotation(richMediaAnnotation);
document.close();
這是一個古老的例子,基於ISO-32000-1。用於該實施例中的技術將在ISO-32000-2被棄用(由於爲出版物中2016)。如果您希望您的應用程序具有未來性,則最好使用RichMedia註釋而不是Screen註釋。需要注意的是,當我打開後,在Adobe Reader *的PDF *我表明我接受的安全風險在影片播放。 *在*我這樣做,* *前我點擊的註解,該文件確實顯示了一個空白頁。順便說一句:它可以創建一個利用iText一個富媒體註釋,但我沒有這樣的例子呢。 – 2014-12-07 12:49:41
感謝Bruno Lowagie。我通過使用PDFXplorer查看內部結構並按照您的建議使用RichMedia註釋來逆向設計PDF文檔。但視頻並沒有顯示出來。我有點卡在這一點上。我無法在網絡上找到任何使用RichMedia Annotation嵌入視頻的示例。 – 2014-12-11 08:31:42