Example #1
0
        /**
         * Creates a file specification for an external file.
         * @param writer the <CODE>PdfWriter</CODE>
         * @param filePath the file path
         * @return the file specification
         */
        public static PdfFileSpecification FileExtern(PdfWriter writer, String filePath)
        {
            PdfFileSpecification fs = new PdfFileSpecification();

            fs.writer = writer;
            fs.Put(PdfName.F, new PdfString(filePath));
            return(fs);
        }
Example #2
0
        /**
         * Creates a file specification of type URL.
         * @param writer the <CODE>PdfWriter</CODE>
         * @param url the URL
         * @return the file specification
         */
        public static PdfFileSpecification Url(PdfWriter writer, String url)
        {
            PdfFileSpecification fs = new PdfFileSpecification();

            fs.writer = writer;
            fs.Put(PdfName.FS, PdfName.URL);
            fs.Put(PdfName.F, new PdfString(url));
            return(fs);
        }
Example #3
0
        /**Creates a Rendition action
         * @param file
         * @param fs
         * @param mimeType
         * @param ref
         * @return a Media Clip action
         * @throws IOException
         */
        public static PdfAction Rendition(String file, PdfFileSpecification fs, String mimeType, PdfIndirectReference refi)
        {
            PdfAction js = new PdfAction();

            js.Put(PdfName.S, PdfName.RENDITION);
            js.Put(PdfName.R, new PdfRendition(file, fs, mimeType));
            js.Put(new PdfName("OP"), new PdfNumber(0));
            js.Put(new PdfName("AN"), refi);
            return(js);
        }
Example #4
0
        internal PdfMediaClipData(String file, PdfFileSpecification fs, String mimeType)
        {
            Put(PdfName.TYPE, new PdfName("MediaClip"));
            Put(PdfName.S, new PdfName("MCD"));
            Put(PdfName.N, new PdfString("Media clip for " + file));
            Put(new PdfName("CT"), new PdfString(mimeType));
            PdfDictionary dic = new PdfDictionary();

            dic.Put(new PdfName("TF"), new PdfString("TEMPACCESS"));
            Put(new PdfName("P"), dic);
            Put(PdfName.D, fs.Reference);
        }
Example #5
0
 public PdfRendition(String file, PdfFileSpecification fs, String mimeType)
 {
     Put(PdfName.S, new PdfName("MR"));
     Put(PdfName.N, new PdfString("Rendition for " + file));
     Put(PdfName.C, new PdfMediaClipData(file, fs, mimeType));
 }
Example #6
0
        /**
         * Creates a file specification with the file embedded. The file may
         * come from the file system or from a byte array.
         * @param writer the <CODE>PdfWriter</CODE>
         * @param filePath the file path
         * @param fileDisplay the file information that is presented to the user
         * @param fileStore the byte array with the file. If it is not <CODE>null</CODE>
         * it takes precedence over <CODE>filePath</CODE>
         * @param mimeType the optional mimeType
         * @param fileParameter the optional extra file parameters such as the creation or modification date
         * @param compressionLevel the level of compression
         * @throws IOException on error
         * @return the file specification
         * @since   2.1.3
         */
        public static PdfFileSpecification FileEmbedded(PdfWriter writer, String filePath, String fileDisplay, byte[] fileStore, String mimeType, PdfDictionary fileParameter, int compressionLevel)
        {
            PdfFileSpecification fs = new PdfFileSpecification();

            fs.writer = writer;
            fs.Put(PdfName.F, new PdfString(fileDisplay));
            PdfEFStream          stream;
            Stream               inp = null;
            PdfIndirectReference refi;
            PdfIndirectReference refFileLength;

            try {
                refFileLength = writer.PdfIndirectReference;
                if (fileStore == null)
                {
                    if (File.Exists(filePath))
                    {
                        inp = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                    }
                    else
                    {
                        if (filePath.StartsWith("file:/") || filePath.StartsWith("http://") || filePath.StartsWith("https://"))
                        {
                            WebRequest w = WebRequest.Create(filePath);
                            inp = w.GetResponse().GetResponseStream();
                        }
                        else
                        {
                            inp = BaseFont.GetResourceStream(filePath);
                            if (inp == null)
                            {
                                throw new IOException(filePath + " not found as file or resource.");
                            }
                        }
                    }
                    stream = new PdfEFStream(inp, writer);
                }
                else
                {
                    stream = new PdfEFStream(fileStore);
                }
                stream.Put(PdfName.TYPE, PdfName.EMBEDDEDFILE);
                stream.FlateCompress(compressionLevel);
                stream.Put(PdfName.PARAMS, refFileLength);
                if (mimeType != null)
                {
                    stream.Put(PdfName.SUBTYPE, new PdfName(mimeType));
                }
                refi = writer.AddToBody(stream).IndirectReference;
                if (fileStore == null)
                {
                    stream.WriteLength();
                }
                PdfDictionary param = new PdfDictionary();
                if (fileParameter != null)
                {
                    param.Merge(fileParameter);
                }
                param.Put(PdfName.SIZE, new PdfNumber(stream.RawLength));
                writer.AddToBody(param, refFileLength);
            }
            finally {
                if (inp != null)
                {
                    try{ inp.Close(); }catch {}
                }
            }
            PdfDictionary f = new PdfDictionary();

            f.Put(PdfName.F, refi);
            fs.Put(PdfName.EF, f);
            return(fs);
        }
Example #7
0
 /** Adds a file attachment at the document level. Existing attachments will be kept.
  * @param description the file description
  * @param fs the file specification
  */
 public void AddFileAttachment(String description, PdfFileSpecification fs)
 {
     stamper.AddFileAttachment(description, fs);
 }
Example #8
0
 /** Adds a file attachment at the document level. Existing attachments will be kept.
  * @param description the file description
  * @param fileStore an array with the file. If it's <CODE>null</CODE>
  * the file will be read from the disk
  * @param file the path to the file. It will only be used if
  * <CODE>fileStore</CODE> is not <CODE>null</CODE>
  * @param fileDisplay the actual file name stored in the pdf
  * @throws IOException on error
  */
 public void AddFileAttachment(String description, byte[] fileStore, String file, String fileDisplay)
 {
     AddFileAttachment(description, PdfFileSpecification.FileEmbedded(stamper, file, fileDisplay, fileStore));
 }
Example #9
0
        /** Creates a file attachment annotation
         * @param writer
         * @param rect
         * @param contents
         * @param fs
         * @return the annotation
         * @throws IOException
         */
        public static PdfAnnotation CreateFileAttachment(PdfWriter writer, Rectangle rect, String contents, PdfFileSpecification fs)
        {
            PdfAnnotation annot = new PdfAnnotation(writer, rect);

            annot.Put(PdfName.SUBTYPE, PdfName.FILEATTACHMENT);
            if (contents != null)
            {
                annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
            }
            annot.Put(PdfName.FS, fs.Reference);
            return(annot);
        }
Example #10
0
 /** Creates a file attachment annotation.
  * @param writer the <CODE>PdfWriter</CODE>
  * @param rect the dimensions in the page of the annotation
  * @param contents the file description
  * @param fileStore an array with the file. If it's <CODE>null</CODE>
  * the file will be read from the disk
  * @param file the path to the file. It will only be used if
  * <CODE>fileStore</CODE> is not <CODE>null</CODE>
  * @param fileDisplay the actual file name stored in the pdf
  * @throws IOException on error
  * @return the annotation
  */
 public static PdfAnnotation CreateFileAttachment(PdfWriter writer, Rectangle rect, String contents, byte[] fileStore, String file, String fileDisplay)
 {
     return(CreateFileAttachment(writer, rect, contents, PdfFileSpecification.FileEmbedded(writer, file, fileDisplay, fileStore)));
 }
Example #11
0
        /**
         * Creates a screen PdfAnnotation
         * @param writer
         * @param rect
         * @param clipTitle
         * @param fs
         * @param mimeType
         * @param playOnDisplay
         * @return a screen PdfAnnotation
         * @throws IOException
         */
        public static PdfAnnotation CreateScreen(PdfWriter writer, Rectangle rect, String clipTitle, PdfFileSpecification fs,
                                                 String mimeType, bool playOnDisplay)
        {
            PdfAnnotation ann = new PdfAnnotation(writer, rect);

            ann.Put(PdfName.SUBTYPE, PdfName.SCREEN);
            ann.Put(PdfName.F, new PdfNumber(FLAGS_PRINT));
            ann.Put(PdfName.TYPE, PdfName.ANNOT);
            ann.SetPage();
            PdfIndirectReference refi      = ann.IndirectReference;
            PdfAction            action    = PdfAction.Rendition(clipTitle, fs, mimeType, refi);
            PdfIndirectReference actionRef = writer.AddToBody(action).IndirectReference;

            // for play on display add trigger event
            if (playOnDisplay)
            {
                PdfDictionary aa = new PdfDictionary();
                aa.Put(new PdfName("PV"), actionRef);
                ann.Put(PdfName.AA, aa);
            }
            ann.Put(PdfName.A, actionRef);
            return(ann);
        }