Exemple #1
0
// ===========================================================================
        public void Write(Stream stream)
        {
            using (ZipFile zip = new ZipFile()) {
                Subscribe s       = new Subscribe();
                byte[]    pdf     = s.CreatePdf();
                string    PdfName = Utility.ResultFileName(s.ToString() + ".pdf");
                zip.AddEntry(PdfName, pdf);

                FdfWriter fdf = new FdfWriter();

/*
 * we're hard-coding the FDF data, not receiving it from an
 * HTML page like the book example
 */
                fdf.SetFieldAsString("personal.name", "HARD-CODED name");
                fdf.SetFieldAsString("personal.loginname", "HARD-CODED loginname");
                fdf.SetFieldAsString("personal.password", "HARD-CODED password");
                fdf.SetFieldAsString("personal.reason", "HARD-CODED reason");
                fdf.File = PdfName;
                using (MemoryStream ms = new MemoryStream()) {
                    fdf.WriteTo(ms);
                    zip.AddEntry("subscribe.fdf", ms.ToArray());
                }
                zip.Save(stream);
            }
        }
Exemple #2
0
        public virtual void FdfTest()
        {
            String acroform_pdf  = TEST_RESOURCES_PATH + "acroform.pdf";
            String barcode_jpg   = TEST_RESOURCES_PATH + "barcode.jpg";
            String signature_pdf = TEST_RESOURCES_PATH + "signature.pdf";
            String outFdf        = OUT_FOLDER + "acroform_fields.fdf";

            FileStream fos       = new FileStream(outFdf, FileMode.Create);
            FdfWriter  fdfWriter = new FdfWriter(fos);

            fdfWriter.File = Path.GetFullPath(acroform_pdf);

            fdfWriter.SetFieldAsString("FirstName", "Alexander");
            fdfWriter.SetFieldAsString("LastName", "Chingarev");

            //Add signature from external PDF.
            PdfReader signatureReader = new PdfReader(signature_pdf);

            fdfWriter.SetFieldAsTemplate("Signature", fdfWriter.GetImportedPage(signatureReader, 1));

            //Add barcode image
            Image img = Image.GetInstance(barcode_jpg);

            fdfWriter.SetFieldAsImage("Barcode", img);

            fdfWriter.Write();

            //Close signature PDF reader.
            signatureReader.Close();


            FdfReader fdfReader = new FdfReader(outFdf);
            Dictionary <String, PdfDictionary> fields = fdfReader.Fields;
            PdfDictionary barcode = fields["Barcode"];
            PdfStream     n       = barcode.GetAsDict(PdfName.AP).GetAsStream(PdfName.N);

            Assert.NotNull(n);
            byte[] b = FdfReader.GetStreamBytes((PRStream)n);
            Assert.AreEqual(51, b.Length);
            PdfStream img0 = n.GetAsDict(PdfName.RESOURCES).GetAsDict(PdfName.XOBJECT).GetAsStream(new PdfName("img0"));

            Assert.NotNull(img0);
            PdfDictionary signature = fields["Signature"];

            n = signature.GetAsDict(PdfName.AP).GetAsStream(PdfName.N);
            Assert.NotNull(n);
            b = FdfReader.GetStreamBytes((PRStream)n);
            Assert.AreEqual(24410, b.Length);
            fdfReader.Close();
        }