Esempio n. 1
0
        public byte[] FillInFields(Dictionary <string, string> formFields)
        {
            if (string.IsNullOrEmpty(this._location.Trim()))
            {
                return(null);
            }
            byte[]       fileBytes;
            MemoryStream memStream = new MemoryStream();

            PdfReader  reader  = new PdfReader(this._location);
            PdfStamper stamper = new PdfStamper(reader, memStream);

            var        layers = stamper.GetPdfLayers();
            AcroFields fields = stamper.AcroFields;

            fields.GenerateAppearances = true;

            foreach (var name in formFields.Keys)
            {
                var type = fields.GetFieldType(name);

                if (type == AcroFields.FIELD_TYPE_CHECKBOX)
                {
                    //fields.SetField(name, formFields[name].ToLower() == "true" ? "Yes" : "Off");
                }
                else
                {
                    fields.SetField(name, formFields[name]);
                }
            }
            stamper.Close();
            fileBytes = memStream.ToArray();

            return(fileBytes);
        }
        public static void Main(string[] args)
        {
            PdfReader  reader = new PdfReader("test.pdf");
            PdfStamper stamp  = new PdfStamper(reader, new FileStream("test2.pdf", FileMode.Create));
            Dictionary <string, PdfLayer> layers = stamp.GetPdfLayers();

            foreach (KeyValuePair <string, PdfLayer> entry in layers)
            {
                PdfLayer layer = (PdfLayer)entry.Value;
                layer.On = false;
            }

            stamp.Close();
        }
 static void Main(string[] args)
 {
     var src = @"c:\layer-example.pdf";
     var dest = @"c:\layer-example-out.pdf";
     var reader = new PdfReader(src);
     PdfStamper pdf = new PdfStamper(reader, new FileStream(dest, FileMode.Create));
     var layers = pdf.GetPdfLayers();
     foreach (var layer in layers)
     {
         var title = layer.Key;
         Console.WriteLine($"title: {title ?? "null"}");
         layer.Value.On = false;
     }
     pdf.Close();
     reader.Close();
 }