// ---------------------------------------------------------------------------
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document()) {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_7);
                writer.AddDeveloperExtension(
                    PdfDeveloperExtension.ADOBE_1_7_EXTENSIONLEVEL3
                    );
                // step 3
                document.Open();
                // step 4
                // we prepare a RichMediaAnnotation
                RichMediaAnnotation richMedia = new RichMediaAnnotation(
                    writer, new Rectangle(36, 400, 559, 806)
                    );
                // we embed the swf file
                PdfFileSpecification fs = PdfFileSpecification.FileEmbedded(
                    writer, RESOURCE, "FestivalCalendar1.swf", null
                    );
                // we declare the swf file as an asset
                PdfIndirectReference asset = richMedia.AddAsset(
                    "FestivalCalendar1.swf", fs
                    );
                // we create a configuration
                RichMediaConfiguration configuration = new RichMediaConfiguration(
                    PdfName.FLASH
                    );
                RichMediaInstance instance  = new RichMediaInstance(PdfName.FLASH);
                RichMediaParams   flashVars = new RichMediaParams();
                String            vars      = "&day=2011-10-13";
                flashVars.FlashVars = vars;
                instance.Params     = flashVars;
                instance.Asset      = asset;
                configuration.AddInstance(instance);
                // we add the configuration to the annotation
                PdfIndirectReference configurationRef = richMedia.AddConfiguration(
                    configuration
                    );
                // activation of the rich media
                RichMediaActivation activation = new RichMediaActivation();
                activation.Configuration = configurationRef;
                richMedia.Activation     = activation;
                // we add the annotation
                PdfAnnotation richMediaAnnotation = richMedia.CreateAnnotation();
                richMediaAnnotation.Flags = PdfAnnotation.FLAGS_PRINT;
                writer.AddAnnotation(richMediaAnnotation);
            }
        }
 /**
  * Creates the actual annotation and adds different elements to the
  * PdfWriter while doing so.
  * @return  a PdfAnnotation
  */
 virtual public PdfAnnotation CreateAnnotation()
 {
     if (richMediaContent != null)
     {
         if (assetsmap.Count > 0)
         {
             PdfDictionary assets = PdfNameTree.WriteTree(assetsmap, writer);
             richMediaContent.Put(PdfName.ASSETS, writer.AddToBody(assets).IndirectReference);
         }
         if (configurations.Size > 0)
         {
             richMediaContent.Put(PdfName.CONFIGURATION, writer.AddToBody(configurations).IndirectReference);
         }
         if (views.Size > 0)
         {
             richMediaContent.Put(PdfName.VIEWS, writer.AddToBody(views).IndirectReference);
         }
         richMediaContentReference = writer.AddToBody(richMediaContent).IndirectReference;
     }
     writer.AddDeveloperExtension(PdfDeveloperExtension.ADOBE_1_7_EXTENSIONLEVEL3);
     annot.Put(PdfName.RICHMEDIACONTENT, richMediaContentReference);
     annot.Put(PdfName.RICHMEDIASETTINGS, writer.AddToBody(richMediaSettings).IndirectReference);
     return(annot);
 }
Exemple #3
0
// ---------------------------------------------------------------------------
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document()) {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_7);
                writer.AddDeveloperExtension(
                    PdfDeveloperExtension.ADOBE_1_7_EXTENSIONLEVEL3
                    );
                // step 3
                document.Open();
                // step 4
                writer.AddJavaScript(File.ReadAllText(JS));

                // we prepare a RichMediaAnnotation
                RichMediaAnnotation richMedia = new RichMediaAnnotation(
                    writer, new Rectangle(36, 560, 561, 760)
                    );
                // we embed the swf file
                PdfFileSpecification fs = PdfFileSpecification.FileEmbedded(
                    writer, RESOURCE, "FestivalCalendar2.swf", null
                    );
                // we declare the swf file as an asset
                PdfIndirectReference asset = richMedia.AddAsset(
                    "FestivalCalendar2.swf", fs
                    );
                // we create a configuration
                RichMediaConfiguration configuration = new RichMediaConfiguration(
                    PdfName.FLASH
                    );
                RichMediaInstance instance = new RichMediaInstance(PdfName.FLASH);
                instance.Asset = asset;
                configuration.AddInstance(instance);
                // we add the configuration to the annotation
                PdfIndirectReference configurationRef = richMedia.AddConfiguration(
                    configuration
                    );
                // activation of the rich media
                RichMediaActivation activation = new RichMediaActivation();
                activation.Configuration = configurationRef;
                richMedia.Activation     = activation;
                // we add the annotation
                PdfAnnotation richMediaAnnotation = richMedia.CreateAnnotation();
                richMediaAnnotation.Flags = PdfAnnotation.FLAGS_PRINT;
                writer.AddAnnotation(richMediaAnnotation);

                String[] days = new String[] {
                    "2011-10-12", "2011-10-13", "2011-10-14", "2011-10-15",
                    "2011-10-16", "2011-10-17", "2011-10-18", "2011-10-19"
                };
                for (int i = 0; i < days.Length; i++)
                {
                    Rectangle       rect   = new Rectangle(36 + (65 * i), 765, 100 + (65 * i), 780);
                    PushbuttonField button = new PushbuttonField(writer, rect, "button" + i);
                    button.BackgroundColor          = new GrayColor(0.75f);
                    button.BorderStyle              = PdfBorderDictionary.STYLE_BEVELED;
                    button.TextColor                = GrayColor.GRAYBLACK;
                    button.FontSize                 = 12;
                    button.Text                     = days[i];
                    button.Layout                   = PushbuttonField.LAYOUT_ICON_LEFT_LABEL_RIGHT;
                    button.ScaleIcon                = PushbuttonField.SCALE_ICON_ALWAYS;
                    button.ProportionalIcon         = true;
                    button.IconHorizontalAdjustment = 0;
                    PdfFormField     field   = button.Field;
                    RichMediaCommand command = new RichMediaCommand(
                        new PdfString("getDateInfo")
                        );
                    command.Arguments = new PdfString(days[i]);
                    RichMediaExecuteAction action = new RichMediaExecuteAction(
                        richMediaAnnotation.IndirectReference, command
                        );
                    field.Action = action;
                    writer.AddAnnotation(field);
                }
                TextField text = new TextField(
                    writer, new Rectangle(36, 785, 559, 806), "date"
                    );
                text.Options = TextField.READ_ONLY;
                writer.AddAnnotation(text.GetTextField());
            }
        }
        void outputDss()
        {
            PdfWriter writer = pdfStamper.Writer;
            PdfReader reader = pdfStamper.Reader;

            PdfDictionary dss   = new PdfDictionary();
            PdfDictionary vrim  = new PdfDictionary();
            PdfArray      ocsps = new PdfArray();
            PdfArray      crls  = new PdfArray();
            PdfArray      certs = new PdfArray();

            writer.AddDeveloperExtension(PdfDeveloperExtension.ESIC_1_7_EXTENSIONLEVEL5);
            writer.AddDeveloperExtension(new PdfDeveloperExtension(PdfName.ADBE, new PdfName("1.7"), 8));

            PdfDictionary catalog = reader.Catalog;

            pdfStamper.MarkUsed(catalog);
            foreach (PdfName vkey in validated.Keys)
            {
                PdfArray      ocsp = new PdfArray();
                PdfArray      crl  = new PdfArray();
                PdfArray      cert = new PdfArray();
                PdfDictionary vri  = new PdfDictionary();
                foreach (byte[] b in validated[vkey].crls)
                {
                    PdfStream ps = new PdfStream(b);
                    ps.FlateCompress();
                    PdfIndirectReference iref = writer.AddToBody(ps, false).IndirectReference;
                    crl.Add(iref);
                    crls.Add(iref);
                }
                foreach (byte[] b in validated[vkey].ocsps)
                {
                    PdfStream ps = new PdfStream(buildOCSPResponse(b));
                    ps.FlateCompress();
                    PdfIndirectReference iref = writer.AddToBody(ps, false).IndirectReference;
                    ocsp.Add(iref);
                    ocsps.Add(iref);
                }
                foreach (byte[] b in validated[vkey].certs)
                {
                    PdfStream ps = new PdfStream(b);
                    ps.FlateCompress();
                    PdfIndirectReference iref = writer.AddToBody(ps, false).IndirectReference;
                    cert.Add(iref);
                    certs.Add(iref);
                }
                if (ocsp.Length > 0)
                {
                    vri.Put(PdfName.OCSP, writer.AddToBody(ocsp, false).IndirectReference);
                }
                if (crl.Length > 0)
                {
                    vri.Put(PdfName.CRL, writer.AddToBody(crl, false).IndirectReference);
                }
                if (cert.Length > 0)
                {
                    vri.Put(PdfName.CERT, writer.AddToBody(cert, false).IndirectReference);
                }
                vri.Put(PdfName.TU, new PdfDate());
                vrim.Put(vkey, writer.AddToBody(vri, false).IndirectReference);
            }
            dss.Put(PdfName.VRI, writer.AddToBody(vrim, false).IndirectReference);
            if (ocsps.Length > 0)
            {
                dss.Put(PdfName.OCSPS, writer.AddToBody(ocsps, false).IndirectReference);
            }
            if (crls.Length > 0)
            {
                dss.Put(PdfName.CRLS, writer.AddToBody(crls, false).IndirectReference);
            }
            if (certs.Length > 0)
            {
                dss.Put(PdfName.CERTS, writer.AddToBody(certs, false).IndirectReference);
            }
            catalog.Put(PdfName.DSS, writer.AddToBody(dss, false).IndirectReference);
        }