Esempio n. 1
0
// ---------------------------------------------------------------------------

        /**
         * Shows the stream passed to the server with POST
         */
        protected void DoPost(byte[] pdf, Stream stream)
        {
            using (Stream s = WebContext.Request.InputStream) {
                // Create a reader that interprets the Request's input stream
                FdfReader fdf = new FdfReader(s);
                // We get a resource from our web app
                PdfReader reader = new PdfReader(pdf);
                // Now we create the PDF
                using (PdfStamper stamper = new PdfStamper(reader, stream)) {
                    // We alter the fields of the existing PDF
                    AcroFields fields = stamper.AcroFields;
                    fields.SetFields(fdf);
                    stamper.FormFlattening = true;
                    // Gets the image from the FDF file
                    try {
                        Image img = Image.GetInstance(fdf.GetAttachedFile("image"));
                        img.ScaleToFit(100, 100);
                        img.SetAbsolutePosition(90, 590);
                        stamper.GetOverContent(1).AddImage(img);
                    }
                    catch {
                        ColumnText.ShowTextAligned(
                            stamper.GetOverContent(1),
                            Element.ALIGN_LEFT,
                            new Phrase("No image posted!"),
                            90, 660, 0
                            );
                    }
                }
            }
        }
        /// <summary>
        /// Parses the HMRC vat returns PDF.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="info">The information.</param>
        /// <returns></returns>
        public Optional <VatReturnsPerBusiness> ParseHmrcVatReturnsPdf(string fileName, InfoAccumulator info)
        {
            PdfReader reader;

            try {
                reader = new FdfReader(fileName);
            } catch (Exception ex) {
                info.AddException(ex);
                return(null);
            }

            VatReturnsPerBusiness vatReturnsPerBusiness = new VatReturnsPerBusiness();

            HmrcBusiness    hmrcBusiness    = new HmrcBusiness();
            VatReturnRecord vatReturnRecord = new VatReturnRecord();

            vatReturnsPerBusiness.VatReturnRecord = vatReturnRecord;
            vatReturnsPerBusiness.Business        = hmrcBusiness;
            vatReturnsPerBusiness.Entries         = ParseVatReturnDetails(reader, info).Value;
            FillPeriodData(reader, vatReturnRecord, info);
            FillBusinessData(reader, vatReturnRecord, hmrcBusiness, info);

            if (!info.HasErrors)
            {
                return(vatReturnsPerBusiness);
            }

            return(null);
        }
Esempio n. 3
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();
        }