예제 #1
0
 public static iText.Kernel.Pdf.PdfEncryptedPayload ExtractFrom(PdfFileSpec fileSpec)
 {
     if (fileSpec != null && fileSpec.GetPdfObject().IsDictionary())
     {
         return(iText.Kernel.Pdf.PdfEncryptedPayload.Wrap(((PdfDictionary)fileSpec.GetPdfObject()).GetAsDictionary(
                                                              PdfName.EP)));
     }
     return(null);
 }
예제 #2
0
        /// <summary>
        /// <p>
        /// Adds file associated with PDF XObject and identifies the relationship between them.
        /// </summary>
        /// <remarks>
        /// <p>
        /// Adds file associated with PDF XObject and identifies the relationship between them.
        /// </p>
        /// <p>
        /// Associated files may be used in Pdf/A-3 and Pdf 2.0 documents.
        /// The method adds file to array value of the AF key in the XObject dictionary.
        /// </p>
        /// <p>
        /// For associated files their associated file specification dictionaries shall include the AFRelationship key
        /// </p>
        /// </remarks>
        /// <param name="fs">file specification dictionary of associated file</param>
        public virtual void AddAssociatedFile(PdfFileSpec fs)
        {
            if (null == ((PdfDictionary)fs.GetPdfObject()).Get(PdfName.AFRelationship))
            {
                ILog logger = LogManager.GetLogger(typeof(iText.Kernel.Pdf.Xobject.PdfXObject));
                logger.Error(iText.IO.LogMessageConstant.ASSOCIATED_FILE_SPEC_SHALL_INCLUDE_AFRELATIONSHIP);
            }
            PdfArray afArray = GetPdfObject().GetAsArray(PdfName.AF);

            if (afArray == null)
            {
                afArray = new PdfArray();
                GetPdfObject().Put(PdfName.AF, afArray);
            }
            afArray.Add(fs.GetPdfObject());
        }
예제 #3
0
 /// <summary>Creates a GoToE action, or embedded file action (section 12.6.4.4 of ISO 32000-1).</summary>
 /// <param name="fileSpec">The root document of the target relative to the root document of the source</param>
 /// <param name="destination">the destination in the target to jump to</param>
 /// <param name="newWindow">
 /// if true, the destination document should be opened in a new window;
 /// if false, the destination document should replace the current document in the same window
 /// </param>
 /// <param name="targetDictionary">
 /// A target dictionary specifying path information to the target document.
 /// Each target dictionary specifies one element in the full path to the target and
 /// may have nested target dictionaries specifying additional elements
 /// </param>
 /// <returns>created action</returns>
 public static iText.Kernel.Pdf.Action.PdfAction CreateGoToE(PdfFileSpec fileSpec, PdfDestination destination
                                                             , bool newWindow, PdfTarget targetDictionary)
 {
     iText.Kernel.Pdf.Action.PdfAction action = new iText.Kernel.Pdf.Action.PdfAction().Put(PdfName.S, PdfName.
                                                                                            GoToE).Put(PdfName.NewWindow, PdfBoolean.ValueOf(newWindow));
     if (fileSpec != null)
     {
         action.Put(PdfName.F, fileSpec.GetPdfObject());
     }
     if (destination != null)
     {
         ValidateRemoteDestination(destination);
         action.Put(PdfName.D, destination.GetPdfObject());
     }
     else
     {
         LogManager.GetLogger(typeof(iText.Kernel.Pdf.Action.PdfAction)).Warn(iText.IO.LogMessageConstant.EMBEDDED_GO_TO_DESTINATION_NOT_SPECIFIED
                                                                              );
     }
     if (targetDictionary != null)
     {
         action.Put(PdfName.T, targetDictionary.GetPdfObject());
     }
     return(action);
 }
예제 #4
0
 /// <summary>Creates a Launch action (section 12.6.4.5 of ISO 32000-1).</summary>
 /// <param name="fileSpec">the application that shall be launched or the document that shall beopened or printed
 ///     </param>
 /// <returns>created action</returns>
 public static iText.Kernel.Pdf.Action.PdfAction CreateLaunch(PdfFileSpec fileSpec)
 {
     iText.Kernel.Pdf.Action.PdfAction action = new iText.Kernel.Pdf.Action.PdfAction().Put(PdfName.S, PdfName.
                                                                                            Launch);
     if (fileSpec != null)
     {
         action.Put(PdfName.F, fileSpec.GetPdfObject());
     }
     return(action);
 }
예제 #5
0
 /// <summary>Creates a Thread action (section 12.6.4.6 of ISO 32000-1).</summary>
 /// <remarks>
 /// Creates a Thread action (section 12.6.4.6 of ISO 32000-1).
 /// A thread action jumps to a specified bead on an article thread (see 12.4.3, "Articles"),
 /// in either the current document or a different one. Table 205 shows the action dictionary
 /// entries specific to this type of action.
 /// </remarks>
 /// <param name="fileSpec">the file containing the thread. If this entry is absent, the thread is in the current file
 ///     </param>
 /// <param name="destinationThread">the destination thread</param>
 /// <param name="bead">the bead in the destination thread</param>
 /// <returns>created action</returns>
 public static iText.Kernel.Pdf.Action.PdfAction CreateThread(PdfFileSpec fileSpec, PdfObject destinationThread
                                                              , PdfObject bead)
 {
     iText.Kernel.Pdf.Action.PdfAction action = new iText.Kernel.Pdf.Action.PdfAction().Put(PdfName.S, PdfName.
                                                                                            Launch).Put(PdfName.D, destinationThread).Put(PdfName.B, bead);
     if (fileSpec != null)
     {
         action.Put(PdfName.F, fileSpec.GetPdfObject());
     }
     return(action);
 }
예제 #6
0
        /// <summary>
        /// <p>
        /// Adds file associated with structure tree root and identifies the relationship between them.
        /// </summary>
        /// <remarks>
        /// <p>
        /// Adds file associated with structure tree root and identifies the relationship between them.
        /// </p>
        /// <p>
        /// Associated files may be used in Pdf/A-3 and Pdf 2.0 documents.
        /// The method adds file to array value of the AF key in the structure tree root dictionary.
        /// If description is provided, it also will add file description to catalog Names tree.
        /// </p>
        /// <p>
        /// For associated files their associated file specification dictionaries shall include the AFRelationship key
        /// </p>
        /// </remarks>
        /// <param name="description">the file description</param>
        /// <param name="fs">file specification dictionary of associated file</param>
        public virtual void AddAssociatedFile(String description, PdfFileSpec fs)
        {
            if (null == ((PdfDictionary)fs.GetPdfObject()).Get(PdfName.AFRelationship))
            {
                ILog logger = LogManager.GetLogger(typeof(iText.Kernel.Pdf.Tagging.PdfStructTreeRoot));
                logger.Error(iText.IO.LogMessageConstant.ASSOCIATED_FILE_SPEC_SHALL_INCLUDE_AFRELATIONSHIP);
            }
            if (null != description)
            {
                GetDocument().GetCatalog().GetNameTree(PdfName.EmbeddedFiles).AddEntry(description, fs.GetPdfObject());
            }
            PdfArray afArray = GetPdfObject().GetAsArray(PdfName.AF);

            if (afArray == null)
            {
                afArray = new PdfArray();
                GetPdfObject().Put(PdfName.AF, afArray);
            }
            afArray.Add(fs.GetPdfObject());
        }
예제 #7
0
        /// <summary>
        /// Constructs a new
        /// <see cref="PdfMediaClipData"/>
        /// wrapper around a newly created dictionary.
        /// </summary>
        /// <param name="file">the name of the file to create a media clip for</param>
        /// <param name="fs">a file specification that specifies the actual media data</param>
        /// <param name="mimeType">an ASCII string identifying the type of data</param>
        public PdfMediaClipData(String file, PdfFileSpec fs, String mimeType)
            : this(new PdfDictionary())
        {
            PdfDictionary dic = new PdfDictionary();

            MarkObjectAsIndirect(dic);
            dic.Put(PdfName.TF, TEMPACCESS);
            GetPdfObject().Put(PdfName.Type, PdfName.MediaClip);
            GetPdfObject().Put(PdfName.S, PdfName.MCD);
            GetPdfObject().Put(PdfName.N, new PdfString(MessageFormatUtil.Format("Media clip for {0}", file)));
            GetPdfObject().Put(PdfName.CT, new PdfString(mimeType));
            GetPdfObject().Put(PdfName.P, dic);
            GetPdfObject().Put(PdfName.D, fs.GetPdfObject());
        }
예제 #8
0
        /// <summary>
        /// Adds a single
        /// <see cref="iText.Kernel.Pdf.Filespec.PdfFileSpec"/>
        /// object, which specifies XML file conforming to PLS.
        /// For more info see
        /// <see cref="GetPronunciationLexiconsList()"/>
        /// .
        /// <p>This value has meaning only for the PDF documents of version <b>2.0 and higher</b>.</p>
        /// </summary>
        /// <param name="pronunciationLexiconFileSpec">
        /// a
        /// <see cref="iText.Kernel.Pdf.Filespec.PdfFileSpec"/>
        /// object, which specifies XML file conforming to PLS.
        /// </param>
        public virtual void AddPronunciationLexicon(PdfFileSpec pronunciationLexiconFileSpec)
        {
            PdfArray pronunciationLexicons = GetPdfObject().GetAsArray(PdfName.PronunciationLexicon);

            if (pronunciationLexicons == null)
            {
                pronunciationLexicons = new PdfArray();
                VersionConforming.ValidatePdfVersionForDictEntry(GetDocument(), PdfVersion.PDF_2_0, PdfName.PronunciationLexicon
                                                                 , PdfName.StructTreeRoot);
                GetPdfObject().Put(PdfName.PronunciationLexicon, pronunciationLexicons);
            }
            pronunciationLexicons.Add(pronunciationLexiconFileSpec.GetPdfObject());
            SetModified();
        }
        public virtual void CreatePdf(String dest)
        {
            PdfADocument pdf = new PdfADocument(new PdfWriter(dest), PdfAConformanceLevel.PDF_A_3A, new PdfOutputIntent
                                                    ("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", new FileStream(INTENT, FileMode.Open, FileAccess.Read
                                                                                                                               )));
            Document document = new Document(pdf, PageSize.A4.Rotate());

            document.SetMargins(20, 20, 20, 20);
            //Setting some required parameters
            pdf.SetTagged();
            pdf.GetCatalog().SetLang(new PdfString("en-US"));
            pdf.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true));
            PdfDocumentInfo info = pdf.GetDocumentInfo();

            info.SetTitle("iText7 PDF/A-3 example");
            //Add attachment
            PdfDictionary parameters = new PdfDictionary();

            parameters.Put(PdfName.ModDate, new PdfDate().GetPdfObject());
            PdfFileSpec fileSpec = PdfFileSpec.CreateEmbeddedFileSpec(pdf, File.ReadAllBytes(System.IO.Path.Combine(DATA
                                                                                                                    )), "united_states.csv", "united_states.csv", new PdfName("text/csv"), parameters, PdfName.Data);

            fileSpec.Put(new PdfName("AFRelationship"), new PdfName("Data"));
            pdf.AddFileAttachment("united_states.csv", fileSpec);
            PdfArray array = new PdfArray();

            array.Add(fileSpec.GetPdfObject().GetIndirectReference());
            pdf.GetCatalog().Put(new PdfName("AF"), array);
            //Embed fonts
            PdfFont font = PdfFontFactory.CreateFont(FONT, true);
            PdfFont bold = PdfFontFactory.CreateFont(BOLD_FONT, true);
            // Create content
            Table table = new Table(UnitValue.CreatePercentArray(new float[] { 4, 1, 3, 4, 3, 3, 3, 3, 1 }))
                          .UseAllAvailableWidth();

            using (StreamReader sr = File.OpenText(DATA))
            {
                String line = sr.ReadLine();
                Process(table, line, bold, true);
                while ((line = sr.ReadLine()) != null)
                {
                    Process(table, line, font, false);
                }
            }

            document.Add(table);
            //Close document
            document.Close();
        }
예제 #10
0
 public static iText.Kernel.Pdf.Action.PdfAction CreateLaunch(PdfFileSpec fileSpec, PdfWin win, bool newWindow
                                                              )
 {
     iText.Kernel.Pdf.Action.PdfAction action = new iText.Kernel.Pdf.Action.PdfAction().Put(PdfName.S, PdfName.
                                                                                            Launch).Put(PdfName.NewWindow, new PdfBoolean(newWindow));
     if (fileSpec != null)
     {
         action.Put(PdfName.F, fileSpec.GetPdfObject());
     }
     if (win != null)
     {
         action.Put(PdfName.Win, win.GetPdfObject());
     }
     return(action);
 }
예제 #11
0
 public virtual void FileSpecCheckTest02()
 {
     NUnit.Framework.Assert.That(() => {
         PdfWriter writer             = new PdfWriter(new MemoryStream());
         Stream @is                   = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
         PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
                                                            , @is);
         PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);
         PdfStream stream         = new PdfStream();
         pdfDocument.GetCatalog().Put(new PdfName("testStream"), stream);
         PdfFileSpec spec = PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, sourceFolder + "sample.wav", "sample.wav"
                                                               , "sample", null, null);
         stream.Put(PdfName.F, spec.GetPdfObject());
         pdfDocument.AddNewPage();
         pdfDocument.Close();
     }
                                 , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.STREAM_OBJECT_DICTIONARY_SHALL_NOT_CONTAIN_THE_F_FFILTER_OR_FDECODEPARAMS_KEYS))
     ;
 }
예제 #12
0
 /// <summary>Creates a GoToE action, or embedded file action (section 12.6.4.4 of ISO 32000-1).</summary>
 /// <param name="fileSpec">The root document of the target relative to the root document of the source</param>
 /// <param name="destination">the destination in the target to jump to</param>
 /// <param name="newWindow">
 /// if true, the destination document should be opened in a new window;
 /// if false, the destination document should replace the current document in the same window
 /// </param>
 /// <param name="targetDictionary">
 /// A target dictionary specifying path information to the target document.
 /// Each target dictionary specifies one element in the full path to the target and
 /// may have nested target dictionaries specifying additional elements
 /// </param>
 /// <returns>created action</returns>
 public static iText.Kernel.Pdf.Action.PdfAction CreateGoToE(PdfFileSpec fileSpec, PdfDestination destination
                                                             , bool newWindow, PdfTarget targetDictionary)
 {
     iText.Kernel.Pdf.Action.PdfAction action = new iText.Kernel.Pdf.Action.PdfAction().Put(PdfName.S, PdfName.
                                                                                            GoToE).Put(PdfName.NewWindow, PdfBoolean.ValueOf(newWindow));
     if (fileSpec != null)
     {
         action.Put(PdfName.F, fileSpec.GetPdfObject());
     }
     if (destination != null)
     {
         action.Put(PdfName.D, destination.GetPdfObject());
     }
     if (targetDictionary != null)
     {
         action.Put(PdfName.T, targetDictionary.GetPdfObject());
     }
     return(action);
 }
예제 #13
0
 public virtual void FileSpecCheckTest03()
 {
     NUnit.Framework.Assert.That(() => {
         PdfWriter writer             = new PdfWriter(new MemoryStream());
         Stream @is                   = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
         PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
                                                            , @is);
         PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);
         PdfStream stream         = new PdfStream();
         pdfDocument.GetCatalog().Put(new PdfName("testStream"), stream);
         PdfFileSpec spec = PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, sourceFolder + "sample.wav", "sample.wav"
                                                               , "sample", null, null, true);
         stream.Put(new PdfName("fileData"), spec.GetPdfObject());
         pdfDocument.AddNewPage();
         pdfDocument.Close();
     }
                                 , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.FileSpecificationDictionaryShallNotContainTheEFKey));
     ;
 }
예제 #14
0
 public virtual void FileSpecCheckTest01()
 {
     NUnit.Framework.Assert.That(() => {
         PdfWriter writer             = new PdfWriter(new MemoryStream());
         Stream @is                   = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
         PdfOutputIntent outputIntent = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1"
                                                            , @is);
         PdfADocument pdfDocument = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, outputIntent);
         PdfDictionary fileNames  = new PdfDictionary();
         pdfDocument.GetCatalog().Put(PdfName.Names, fileNames);
         PdfDictionary embeddedFiles = new PdfDictionary();
         fileNames.Put(PdfName.EmbeddedFiles, embeddedFiles);
         PdfArray names = new PdfArray();
         fileNames.Put(PdfName.Names, names);
         names.Add(new PdfString("some/file/path"));
         PdfFileSpec spec = PdfFileSpec.CreateEmbeddedFileSpec(pdfDocument, sourceFolder + "sample.wav", "sample.wav"
                                                               , "sample", null, null);
         names.Add(spec.GetPdfObject());
         pdfDocument.AddNewPage();
         pdfDocument.Close();
     }
                                 , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.A_NAME_DICTIONARY_SHALL_NOT_CONTAIN_THE_EMBEDDED_FILES_KEY))
     ;
 }
예제 #15
0
 /// <summary>Sets file specification identifying the schema file, which defines this namespace.</summary>
 /// <param name="fileSpec">
 /// a
 /// <see cref="iText.Kernel.Pdf.Filespec.PdfFileSpec"/>
 /// identifying the schema file.
 /// </param>
 /// <returns>
 /// this
 /// <see cref="PdfNamespace"/>
 /// instance.
 /// </returns>
 public virtual iText.Kernel.Pdf.Tagging.PdfNamespace SetSchema(PdfFileSpec fileSpec)
 {
     return(Put(PdfName.Schema, fileSpec.GetPdfObject()));
 }
예제 #16
0
 /// <summary>Creates a GoToR action, or remote action (section 12.6.4.3 of ISO 32000-1).</summary>
 /// <param name="fileSpec">the file in which the destination shall be located</param>
 /// <param name="destination">the destination in the remote document to jump to</param>
 /// <returns>created action</returns>
 public static iText.Kernel.Pdf.Action.PdfAction CreateGoToR(PdfFileSpec fileSpec, PdfDestination destination
                                                             )
 {
     ValidateRemoteDestination(destination);
     return(new iText.Kernel.Pdf.Action.PdfAction().Put(PdfName.S, PdfName.GoToR).Put(PdfName.F, fileSpec.GetPdfObject
                                                                                          ()).Put(PdfName.D, destination.GetPdfObject()));
 }
예제 #17
0
 public static iText.Kernel.Pdf.Action.PdfAction CreateGoToR(PdfFileSpec fileSpec, PdfDestination destination
                                                             , bool newWindow)
 {
     return(new iText.Kernel.Pdf.Action.PdfAction().Put(PdfName.S, PdfName.GoToR).Put(PdfName.F, fileSpec.GetPdfObject
                                                                                          ()).Put(PdfName.D, destination.GetPdfObject()).Put(PdfName.NewWindow, new PdfBoolean(newWindow)));
 }
 public PdfFileAttachmentAnnotation(Rectangle rect, PdfFileSpec file)
     : this(rect) {
     Put(PdfName.FS, file.GetPdfObject());
 }