From 968eb4bea2662813fe2a6928e4ee626f659b6e80 Mon Sep 17 00:00:00 2001 From: Mark Dawson Date: Fri, 2 Jul 2021 08:06:44 -0500 Subject: [PATCH] Remove FlashAnnotCreate sample programs Adobe Inc. no longer supports the Flash software product, so we are removing the Java, .NET, and .NET Core sample programs from Adobe PDF Library. --- .../FlashAnnotCreate/FlashAnnotCreate.cs | 205 ---------------- .../Properties/AssemblyInfo.cs | 33 --- .../FlashAnnotCreate/FlashAnnotCreate.cs | 209 ----------------- .../PDFL/Samples/FlashAnnotCreate.java | 221 ------------------ 4 files changed, 668 deletions(-) delete mode 100644 DotNET/Sample_Source/Annotations/FlashAnnotCreate/FlashAnnotCreate.cs delete mode 100644 DotNET/Sample_Source/Annotations/FlashAnnotCreate/Properties/AssemblyInfo.cs delete mode 100644 DotNETCore/Sample_Source/Annotations/FlashAnnotCreate/FlashAnnotCreate.cs delete mode 100644 Java/Sample_Source/Annotations/FlashAnnotCreate/src/com/datalogics/PDFL/Samples/FlashAnnotCreate.java diff --git a/DotNET/Sample_Source/Annotations/FlashAnnotCreate/FlashAnnotCreate.cs b/DotNET/Sample_Source/Annotations/FlashAnnotCreate/FlashAnnotCreate.cs deleted file mode 100644 index 0c55c651..00000000 --- a/DotNET/Sample_Source/Annotations/FlashAnnotCreate/FlashAnnotCreate.cs +++ /dev/null @@ -1,205 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Datalogics.PDFL; - -/* - * - * The sample program shows how to add an annotation to a PDF file that features a flash video embedded under an image. - * - * For more detail see the description of the FlashAnnotCreate sample program on our Developer’s site, - * http://dev.datalogics.com/adobe-pdf-library/sample-program-descriptions/net-sample-programs/working-with-annotations#flashannotcreate - * - * Copyright (c) 2007-2017, Datalogics, Inc. All rights reserved. - * - * For complete copyright information, refer to: - * http://dev.datalogics.com/adobe-pdf-library/license-for-downloaded-pdf-samples/ - * - */ -namespace FlashAnnotCreate -{ - class FlashAnnotCreate - { - - static void Main(string[] args) - { - Console.WriteLine("FlashAnnotCreate Sample:"); - - using (Library lib = new Library()) - { - Console.WriteLine("Initialized the library."); - - // Names of the flash-format file to embed. - String sInput1 = Library.ResourceDirectory + "Sample_Input/JobReady-info.swf"; - // Name of the PDF file to use for the annotation appearance - the - // first page of the PDF is imported - String sInput2 = Library.ResourceDirectory + "Sample_Input/cottage.pdf"; - String sOutput = "../FlashAnnotCreate-out.pdf"; - - if (args.Length > 0) - sInput1 = args[0]; - - if (args.Length > 1) - sInput2 = args[1]; - - if (args.Length > 2) - sOutput = args[2]; - - Console.WriteLine("Using flash file " + sInput1 + " and generating appearance from " + sInput2 + ", saving output file : " + sOutput); - - // Create a document and a 5" x 4" page for the Flash annotation - using (Document doc = new Document()) - { - Rect mediaBox = new Rect(0, 0, 5 * 72, 4 * 72); - using (Page page = doc.CreatePage(Document.BeforeFirstPage, mediaBox)) - { - // Set the annotation to be 3" x 2", with its lower-left corner 1" over and 1" up - // from the bottom-left corner of the page. - // - // The size of the annotation should match the design size of your flash file. - // If the two are drastically disparate, oddities with object placement in the - // flash file may result. - Rect annotRect = new Rect(1 * 72, 3 * 72, 4 * 72, 1 * 72); - - // Create the annotation and acquire the COS-layer representation. - // Most of the specific functionality for annotations is set via - // direct manipulation of the COS-layer representation of the annotation */ - Annotation newAnnot = new Annotation(page, "Screen", annotRect); - PDFDict cosAnnot = newAnnot.PDFDict; - - // Set the annotation title and flags - newAnnot.Flags = AnnotationFlags.Print | AnnotationFlags.ReadOnly; - newAnnot.Title = "Flash annotation sample"; - - // There are several layers of objects to be created and nested in order to make - // an annotation that plays Flash file content. The 2 major tasks are creating - // the appearance for the annotation, and creating the annotation's action: - // the appearance is what's shown before the Flash file is clicked on & invoked, - // whereas the action states what to do in order to play the Flash file. */ - - // The annotation action has many subdictionaries that are required. - // This example starts by creating the topmost item: - // set the action type to Rendition for SWF (Flash) files - Datalogics.PDFL.Action action = new Datalogics.PDFL.Action(doc, "Rendition"); - PDFDict actionDict = action.PDFDict; - // Make a back-link to the annotation - actionDict.Put("AN", cosAnnot); - - // Specify what to do: in this case, the OP value of 0 means - // if no rendition is associated with the annotation specified - // by AN, play the rendition specified by R, associating it - // with the annotation. If a rendition is already associated - // with the annotation, it is stopped, and the new rendition - // is associated with the annotation. - actionDict.Put("OP", new PDFInteger(0, doc, false)); - - // Make a rendition object to use for playing: - PDFDict rendObj = new PDFDict(doc, true); - // Rendition object is of the "media rendition" type - rendObj.Put("S", new PDFName("MR", doc, false)); - - // Add a name for the rendition (optional) - rendObj.Put("N", new PDFString("Rendition for Flash embedding sample", doc, false, false)); - - // Make the media clip dictionary: - PDFDict mediaClipObj = new PDFDict(doc, true); - - // Required: this is a media clip data object: - mediaClipObj.Put("S", new PDFName("MCD", doc, false)); - - // Specify what sort of media clip this is (MIME type): - mediaClipObj.Put("CT", new PDFString("application/x-shockwave-flash", doc, false, false)); - - // Add a permissions dictionary (for making temp files for playback) - PDFDict permObj = new PDFDict(doc, false); - // Indicate a temp file may be made to play the rendition: - permObj.Put("TF", new PDFString("TEMPACCESS", doc, false, false)); - // Add the permissions dictionary to the rendition - mediaClipObj.Put("P", permObj); - - using (System.IO.FileStream fileStream = new System.IO.FileStream(sInput1, System.IO.FileMode.Open)) - { - using (PDFStream fileStmObj = new PDFStream(fileStream, doc, new PDFDict(doc, false), new PDFArray(doc, false))) - { - // Make a new file reference - PDFDict fileRefObj = new PDFDict(doc, true); - // Which needs an embedded file - PDFDict efObj = new PDFDict(doc, false); - // Add the filestream above to the embedded file dict - efObj.Put("F", fileStmObj); - // Add the embedded file to the file reference - fileRefObj.Put("EF", efObj); - // Set the type of this object - fileRefObj.Put("Type", new PDFName("Filespec", doc, false)); - // And add the actual file name this was based upon - fileRefObj.Put("F", new PDFString(sInput1, doc, false, false)); - - // Place the file specification in the media clip dictionary: - mediaClipObj.Put("D", fileRefObj); - - // Associate the media clip dictionary with the rendition: - rendObj.Put("C", mediaClipObj); - - // Associate the rendition with the action: - actionDict.Put("R", rendObj); - - // Associate the action with the annotation: - cosAnnot.Put("A", actionDict); - - try - { - // The other major part is creating the appearance for the annotation. - // This example will import a PDF page and use it's first page as the appearance. - using (Document importPDDoc = new Document(sInput2)) - { - Page importPDPage = importPDDoc.GetPage(0); - Content tempContent = new Content(); - - // The page is added to the PDE Content in order to acquire the PDEForm - // created in the process. This PDEForm will become the basis of the - // annotation appearance. - // - // NOTE: the actual appearance of the page in the annotation will be scaled to fit - // within the boundaries of the annotation - so, if the page being used is of drastically - // different x/y proportions from the annotation, it will appear distorted. */ - tempContent.AddPage(Content.BeforeFirst, doc, importPDPage, null, null, 0, null); - - if (tempContent.NumElements == 1 && tempContent.GetElement(0) is Form) - { - Form annotAPForm = tempContent.GetElement(0) as Form; - // Place the form XObject as the "normal" appearance in an appearance dictionary - PDFDict apDict = new PDFDict(doc, false); - apDict.Put("N", annotAPForm.Stream); - // And place the appearance dictionary in the annotation - cosAnnot.Put("AP", apDict); - } - else - Console.WriteLine("Unexpected page import result. Annotation will have no appearance."); - } - } - catch (ApplicationException ex) - { - if (ex.Message.StartsWith("PDF")) - { - Console.WriteLine("Exception %x (%s) while importing annotation appearance:"); - Console.WriteLine(ex.Message); - Console.WriteLine("* Annotation will not have a visible appearance but is still in PDF file"); - } - else - throw; - } - - // Create a backlink to the page this annotation appears on - // in the annotation. This is required for Screen annotations - // with rendition actions. - cosAnnot.Put("P", page.PDFDict); - - doc.Save(SaveFlags.Full, sOutput); - } - } - } - } - } - } - } -} diff --git a/DotNET/Sample_Source/Annotations/FlashAnnotCreate/Properties/AssemblyInfo.cs b/DotNET/Sample_Source/Annotations/FlashAnnotCreate/Properties/AssemblyInfo.cs deleted file mode 100644 index c457a34c..00000000 --- a/DotNET/Sample_Source/Annotations/FlashAnnotCreate/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("FlashAnnotCreate")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Datalogics, Incorporated")] -[assembly: AssemblyProduct("FlashAnnotCreate")] -[assembly: AssemblyCopyright("Copyright © Datalogics, Incorporated 2008-2010")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("2132dad5-a96a-4898-863d-927dcb2a68a0")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DotNETCore/Sample_Source/Annotations/FlashAnnotCreate/FlashAnnotCreate.cs b/DotNETCore/Sample_Source/Annotations/FlashAnnotCreate/FlashAnnotCreate.cs deleted file mode 100644 index e317bbba..00000000 --- a/DotNETCore/Sample_Source/Annotations/FlashAnnotCreate/FlashAnnotCreate.cs +++ /dev/null @@ -1,209 +0,0 @@ -using System; -using Datalogics.PDFL; - -/* - * - * The sample program shows how to add an annotation to a PDF file that features a flash video embedded under an image. - * - * For more detail see the description of the FlashAnnotCreate sample program on our Developer’s site, - * http://dev.datalogics.com/adobe-pdf-library/sample-program-descriptions/net-core-sample-programs/working-with-annotations#flashannotcreate - * - * Copyright (c) 2007-2020, Datalogics, Inc. All rights reserved. - * - * For complete copyright information, refer to: - * http://dev.datalogics.com/adobe-pdf-library/license-for-downloaded-pdf-samples/ - * - */ -namespace FlashAnnotCreate -{ - class FlashAnnotCreate - { - static void Main(string[] args) - { - Console.WriteLine("FlashAnnotCreate Sample:"); - - // ReSharper disable once UnusedVariable - using (Library lib = new Library()) - { - Console.WriteLine("Initialized the library."); - - // Names of the flash-format file to embed. - String sInput1 = Library.ResourceDirectory + "Sample_Input/JobReady-info.swf"; - // Name of the PDF file to use for the annotation appearance - the - // first page of the PDF is imported - String sInput2 = Library.ResourceDirectory + "Sample_Input/cottage.pdf"; - String sOutput = "FlashAnnotCreate-out.pdf"; - - if (args.Length > 0) - sInput1 = args[0]; - - if (args.Length > 1) - sInput2 = args[1]; - - if (args.Length > 2) - sOutput = args[2]; - - Console.WriteLine("Using flash file " + sInput1 + " and generating appearance from " + sInput2 + - ", saving output file : " + sOutput); - - // Create a document and a 5" x 4" page for the Flash annotation - using (Document doc = new Document()) - { - Rect mediaBox = new Rect(0, 0, 5 * 72, 4 * 72); - using (Page page = doc.CreatePage(Document.BeforeFirstPage, mediaBox)) - { - // Set the annotation to be 3" x 2", with its lower-left corner 1" over and 1" up - // from the bottom-left corner of the page. - // - // The size of the annotation should match the design size of your flash file. - // If the two are drastically disparate, oddities with object placement in the - // flash file may result. - Rect annotRect = new Rect(1 * 72, 3 * 72, 4 * 72, 1 * 72); - - // Create the annotation and acquire the COS-layer representation. - // Most of the specific functionality for annotations is set via - // direct manipulation of the COS-layer representation of the annotation */ - Annotation newAnnot = new Annotation(page, "Screen", annotRect); - PDFDict cosAnnot = newAnnot.PDFDict; - - // Set the annotation title and flags - newAnnot.Flags = AnnotationFlags.Print | AnnotationFlags.ReadOnly; - newAnnot.Title = "Flash annotation sample"; - - // There are several layers of objects to be created and nested in order to make - // an annotation that plays Flash file content. The 2 major tasks are creating - // the appearance for the annotation, and creating the annotation's action: - // the appearance is what's shown before the Flash file is clicked on & invoked, - // whereas the action states what to do in order to play the Flash file. */ - - // The annotation action has many subdictionaries that are required. - // This example starts by creating the topmost item: - // set the action type to Rendition for SWF (Flash) files - Datalogics.PDFL.Action action = new Datalogics.PDFL.Action(doc, "Rendition"); - PDFDict actionDict = action.PDFDict; - // Make a back-link to the annotation - actionDict.Put("AN", cosAnnot); - - // Specify what to do: in this case, the OP value of 0 means - // if no rendition is associated with the annotation specified - // by AN, play the rendition specified by R, associating it - // with the annotation. If a rendition is already associated - // with the annotation, it is stopped, and the new rendition - // is associated with the annotation. - actionDict.Put("OP", new PDFInteger(0, doc, false)); - - // Make a rendition object to use for playing: - PDFDict rendObj = new PDFDict(doc, true); - // Rendition object is of the "media rendition" type - rendObj.Put("S", new PDFName("MR", doc, false)); - - // Add a name for the rendition (optional) - rendObj.Put("N", new PDFString("Rendition for Flash embedding sample", doc, false, false)); - - // Make the media clip dictionary: - PDFDict mediaClipObj = new PDFDict(doc, true); - - // Required: this is a media clip data object: - mediaClipObj.Put("S", new PDFName("MCD", doc, false)); - - // Specify what sort of media clip this is (MIME type): - mediaClipObj.Put("CT", new PDFString("application/x-shockwave-flash", doc, false, false)); - - // Add a permissions dictionary (for making temp files for playback) - PDFDict permObj = new PDFDict(doc, false); - // Indicate a temp file may be made to play the rendition: - permObj.Put("TF", new PDFString("TEMPACCESS", doc, false, false)); - // Add the permissions dictionary to the rendition - mediaClipObj.Put("P", permObj); - - using (System.IO.FileStream fileStream = - new System.IO.FileStream(sInput1, System.IO.FileMode.Open)) - { - using (PDFStream fileStmObj = new PDFStream(fileStream, doc, new PDFDict(doc, false), - new PDFArray(doc, false))) - { - // Make a new file reference - PDFDict fileRefObj = new PDFDict(doc, true); - // Which needs an embedded file - PDFDict efObj = new PDFDict(doc, false); - // Add the filestream above to the embedded file dict - efObj.Put("F", fileStmObj); - // Add the embedded file to the file reference - fileRefObj.Put("EF", efObj); - // Set the type of this object - fileRefObj.Put("Type", new PDFName("Filespec", doc, false)); - // And add the actual file name this was based upon - fileRefObj.Put("F", new PDFString(sInput1, doc, false, false)); - - // Place the file specification in the media clip dictionary: - mediaClipObj.Put("D", fileRefObj); - - // Associate the media clip dictionary with the rendition: - rendObj.Put("C", mediaClipObj); - - // Associate the rendition with the action: - actionDict.Put("R", rendObj); - - // Associate the action with the annotation: - cosAnnot.Put("A", actionDict); - - try - { - // The other major part is creating the appearance for the annotation. - // This example will import a PDF page and use it's first page as the appearance. - using (Document importPDDoc = new Document(sInput2)) - { - Page importPDPage = importPDDoc.GetPage(0); - Content tempContent = new Content(); - - // The page is added to the PDE Content in order to acquire the PDEForm - // created in the process. This PDEForm will become the basis of the - // annotation appearance. - // - // NOTE: the actual appearance of the page in the annotation will be scaled to fit - // within the boundaries of the annotation - so, if the page being used is of drastically - // different x/y proportions from the annotation, it will appear distorted. */ - tempContent.AddPage(Content.BeforeFirst, doc, importPDPage, null, null, 0, - null); - - if (tempContent.NumElements == 1 && tempContent.GetElement(0) is Form) - { - Form annotAPForm = tempContent.GetElement(0) as Form; - // Place the form XObject as the "normal" appearance in an appearance dictionary - PDFDict apDict = new PDFDict(doc, false); - apDict.Put("N", annotAPForm.Stream); - // And place the appearance dictionary in the annotation - cosAnnot.Put("AP", apDict); - } - else - Console.WriteLine( - "Unexpected page import result. Annotation will have no appearance."); - } - } - catch (ApplicationException ex) - { - if (ex.Message.StartsWith("PDF")) - { - Console.WriteLine("Exception %x (%s) while importing annotation appearance:"); - Console.WriteLine(ex.Message); - Console.WriteLine( - "* Annotation will not have a visible appearance but is still in PDF file"); - } - else - throw; - } - - // Create a backlink to the page this annotation appears on - // in the annotation. This is required for Screen annotations - // with rendition actions. - cosAnnot.Put("P", page.PDFDict); - - doc.Save(SaveFlags.Full, sOutput); - } - } - } - } - } - } - } -} diff --git a/Java/Sample_Source/Annotations/FlashAnnotCreate/src/com/datalogics/PDFL/Samples/FlashAnnotCreate.java b/Java/Sample_Source/Annotations/FlashAnnotCreate/src/com/datalogics/PDFL/Samples/FlashAnnotCreate.java deleted file mode 100644 index c1688e75..00000000 --- a/Java/Sample_Source/Annotations/FlashAnnotCreate/src/com/datalogics/PDFL/Samples/FlashAnnotCreate.java +++ /dev/null @@ -1,221 +0,0 @@ -package com.datalogics.PDFL.Samples; - -import com.datalogics.PDFL.Action; -import com.datalogics.PDFL.AddPageFlags; -import com.datalogics.PDFL.Annotation; -import com.datalogics.PDFL.AnnotationFlags; -import com.datalogics.PDFL.Content; -import com.datalogics.PDFL.Document; -import com.datalogics.PDFL.Form; -import com.datalogics.PDFL.Library; -import com.datalogics.PDFL.PDFArray; -import com.datalogics.PDFL.PDFDict; -import com.datalogics.PDFL.PDFInteger; -import com.datalogics.PDFL.PDFName; -import com.datalogics.PDFL.PDFStream; -import com.datalogics.PDFL.PDFString; -import com.datalogics.PDFL.Page; -import com.datalogics.PDFL.Rect; -import com.datalogics.PDFL.SaveFlags; -import java.io.FileInputStream; -import java.util.EnumSet; - -/* - * - * The sample program shows how to add an annotation to a PDF file that features a flash video embedded under an image. - * - * For more detail see the description of the FlashAnnotCreate sample program on our Developer's site, - * http://dev.datalogics.com/adobe-pdf-library/sample-program-descriptions/java-sample-programs/working-with-annotations-in-pdf-files#flashannotcreate - * - * Copyright (c) 2007-2017, Datalogics, Inc. All rights reserved. - * - * For complete copyright information, refer to: - * http://dev.datalogics.com/adobe-pdf-library/license-for-downloaded-pdf-samples/ - * - */ -public class FlashAnnotCreate { - - public static void main(String[] args) throws java.io.IOException{ - // Names of the flash-format file to embed & output file to create - String flashFileName = "../../Resources/Sample_Input/JobReady-info.swf"; - String outputFileName = "FlashAnnotCreate-out.pdf"; - - // Name of the PDF file to use for the annotation appearance - the - // first page of the PDF is imported - String appearancePDFName = "../../Resources/Sample_Input/cottage.pdf"; - Library lib = new Library(); - - try { - if (args.length > 0) - flashFileName = args[0]; - if (args.length > 1) - appearancePDFName = args[1]; - if (args.length > 2) - outputFileName = args[2]; - System.out.println("Flash file: " + flashFileName + " Output: " + outputFileName + - " appearance PDF: " + appearancePDFName ); - - // Create a document and a 5" x 4" page for the Flash annotation - Document doc = new Document(); - Rect mediaBox = new Rect(0, 0, 5 * 72, 4 * 72); - Page page = doc.createPage(Document.BEFORE_FIRST_PAGE, mediaBox); - - // Set the annotation to be 3" x 2", with its lower-left corner 1" over and 1" up - // from the bottom-left corner of the page. - // - // The size of the annotation should match the design size of your flash file. - // If the two are drastically disparate, oddities with object placement in the - // flash file may result. - Rect annotRect = new Rect(1 * 72, 3 * 72, 4 * 72, 1 * 72); - - // Create the annotation and acquire the COS-layer representation. - // Most of the specific functionality for annotations is set via - // direct manipulation of the COS-layer representation of the annotation - Annotation newAnnot = new Annotation(page, "Screen", annotRect); - PDFDict cosAnnot = newAnnot.getPDFDict(); - - // Set the annotation title and flags - newAnnot.setTitle("Flash annotation sample"); - newAnnot.setFlags(EnumSet.of(AnnotationFlags.PRINT, AnnotationFlags.READ_ONLY)); - - // There are several layers of objects to be created and nested in order to make - // an annotation that plays Flash file content. The 2 major tasks are creating - // the appearance for the annotation, and creating the annotation's action: - // the appearance is what's shown before the Flash file is clicked on & invoked, - // whereas the action states what to do in order to play the Flash file. - - // The annotation action has many subdictionaries that are required. - // This example starts by creating the topmost item: - // set the action type to Rendition for SWF (Flash) files - Action action = new Action(doc, "Rendition"); - PDFDict actionDict = action.getPDFDict(); - - // Make a back-link to the annotation - actionDict.put("AN", cosAnnot); - - // Specify what to do: in this case, the OP value of 0 means - // if no rendition is associated with the annotation specified - // by AN, play the rendition specified by R, associating it - // with the annotation. If a rendition is already associated - // with the annotation, it is stopped, and the new rendition - // is associated with the annotation. - actionDict.put("OP",new PDFInteger(0, doc, false)); - - // Make a rendition object to use for playing: - PDFDict rendObj = new PDFDict(doc, true); - - // Rendition object is of the "media rendition" type - rendObj.put("S", new PDFName("MR", doc, false)); - - // Add a name for the rendition (optional) - rendObj.put("N",new PDFString("Rendition for Flash embedding sample", doc, false, false)); - - // Make the media clip dictionary: - PDFDict mediaClipObj = new PDFDict(doc, true); - - // Required: this is a media clip data object: - mediaClipObj.put("S",new PDFName("MCD", doc, false)); - - // Specify what sort of media clip this is (MIME type): - mediaClipObj.put("CT", new PDFString("application/x-shockwave-flash", doc, false, false)); - - // Add a permissions dictionary (for making temp files for playback) - PDFDict permObj = new PDFDict(doc, false); - - // Indicate a temp file may be made to play the rendition: - permObj.put("TF", new PDFString("TEMPACCESS", doc, false, false)); - - // Add the permissions dictionary to the rendition - mediaClipObj.put("P", permObj); - - PDFStream fileStmObj = new PDFStream(new FileInputStream(flashFileName), doc, new PDFDict(doc, false), new PDFArray(doc, false)); - - // Make a new file reference - PDFDict fileRefObj = new PDFDict(doc, true); - - // Which needs an embedded file - PDFDict efObj = new PDFDict(doc, false); - - // Add the filestream above to the embedded file dict - efObj.put("F", fileStmObj); - - // Add the embedded file to the file reference - fileRefObj.put("EF",efObj); - - // Set the type of this object - fileRefObj.put("Type", new PDFName("Filespec", doc, false)); - - // And add the actual file name this was based upon - fileRefObj.put("F", new PDFString(flashFileName, doc, false, false)); - - // Place the file specification in the media clip dictionary: - mediaClipObj.put("D", fileRefObj); - - // Associate the media clip dictionary with the rendition: - rendObj.put("C", mediaClipObj); - - // Associate the rendition with the action: - actionDict.put("R", rendObj); - - // Associate the action with the annotation: - cosAnnot.put("A",actionDict); - - try { - // The other major part is creating the appearance for the annotation. - // This example will import a PDF page and use it's first page as the appearance. - Document importPDDoc = new Document(appearancePDFName); - - Page importPDPage = importPDDoc.getPage(0); - Content tempContent = new Content(); - - // The page is added to the PDE Content in order to acquire the PDEForm - // created in the process. This PDEForm will become the basis of the - // annotation appearance. - // - // NOTE: the actual appearance of the page in the annotation will be scaled to fit - // within the boundaries of the annotation - so, if the page being used is of drastically - // different x/y proportions from the annotation, it will appear distorted. - tempContent.addPage(Content.BEFORE_FIRST, doc, importPDPage, null, null, EnumSet.noneOf(AddPageFlags.class), null); - - if (tempContent.getNumElements() == 1 && tempContent.getElement(0) instanceof Form) - { - Form annotAPForm = (Form)tempContent.getElement(0); - - // Place the form XObject as the "normal" appearance in an appearance dictionary - PDFDict apDict = new PDFDict(doc, false); - apDict.put("N", annotAPForm.getStream()); - - // And place the appearance dictionary in the annotation - cosAnnot.put("AP", apDict); - } - else - System.out.println("Unexpected page import result. Annotation will have no appearance."); - - importPDDoc.delete(); - } - catch (RuntimeException ex) { - if (ex.getMessage().startsWith("PDF")) - { - System.out.println("Exception while importing annotation appearance:"); - System.out.println(ex.getMessage()); - System.out.println("* Annotation will not have a visible appearance but is still in PDF file"); - } - else - throw ex; - } - - // Create a backlink to the page this annotation appears on - // in the annotation. This is required for Screen annotations - // with rendition actions. - cosAnnot.put("P", page.getPDFDict()); - - page.delete(); - - doc.save(EnumSet.of(SaveFlags.FULL), outputFileName); - } - finally { - lib.delete(); - } - } - -}