Пример #1
0
        private static void addFields(iTextSharp.text.pdf.PdfReader reader, FileStream fs, SqlDataReader dr)
        {
            using (var pdfStamper = new PdfStamper(reader, fs))
            {
                int i = 0;
                int fieldIndex = 0;
                int page = 1;
                int top;
                int bottom;
                while (dr.Read())
                {
                    if (i > 22 && page == 1)
                    {
                        page = 2;
                        i = 1;
                    }
                    i++;
                    fieldIndex++;
                    int lineSp = (i - 1) * 20;
                    if (page == 1)
                    {
                        top = 450 - lineSp;
                        bottom = 470 - lineSp;

                    }
                    else
                    {
                        top = 600 - lineSp;
                        bottom = 620 - lineSp;
                    }
                    iTextSharp.text.BaseColor currBackgrd;
                    if (i % 2 == 0)
                        currBackgrd = iTextSharp.text.BaseColor.WHITE;
                    else
                        currBackgrd = iTextSharp.text.BaseColor.LIGHT_GRAY;

                    TextField field = new TextField(pdfStamper.Writer, new iTextSharp.text.Rectangle(20, top, 90, bottom), "Day" + fieldIndex.ToString());
                    field.FontSize = MYSIZE;
                    field.Rotation = 90;
                    field.BackgroundColor = currBackgrd;
                    pdfStamper.AddAnnotation(field.GetTextField(), page);

                    field = new TextField(pdfStamper.Writer, new iTextSharp.text.Rectangle(92, top, 145, bottom), "Time" + fieldIndex.ToString());
                    field.FontSize = MYSIZE;
                    field.Rotation = 90;
                    field.BackgroundColor = currBackgrd;
                    pdfStamper.AddAnnotation(field.GetTextField(), page);

                    field = new TextField(pdfStamper.Writer, new iTextSharp.text.Rectangle(147, top, 197, bottom), "Type" + fieldIndex.ToString());
                    field.FontSize = MYSIZE;
                    field.Rotation = 90;
                    field.BackgroundColor = currBackgrd;
                    pdfStamper.AddAnnotation(field.GetTextField(), page);

                    field = new TextField(pdfStamper.Writer, new iTextSharp.text.Rectangle(199, top, 309, bottom), "Topic" + fieldIndex.ToString());
                    field.FontSize = MYSIZE;
                    field.Rotation = 90;
                    field.BackgroundColor = currBackgrd;
                    pdfStamper.AddAnnotation(field.GetTextField(), page);

                    field = new TextField(pdfStamper.Writer, new iTextSharp.text.Rectangle(311, top, 461, bottom), "aaGroup" + fieldIndex.ToString());
                    field.FontSize = MYSIZE;
                    field.Rotation = 90;
                    field.BackgroundColor = currBackgrd;
                    pdfStamper.AddAnnotation(field.GetTextField(), page);

                    field = new TextField(pdfStamper.Writer, new iTextSharp.text.Rectangle(463, top, 690, bottom), "Location" + fieldIndex.ToString());
                    field.FontSize = MYSIZE;
                    field.Rotation = 90;
                    field.BackgroundColor = currBackgrd;
                    pdfStamper.AddAnnotation(field.GetTextField(), page);

                    field = new TextField(pdfStamper.Writer, new iTextSharp.text.Rectangle(692, top, 782, bottom), "City" + fieldIndex.ToString());
                    field.FontSize = MYSIZE;
                    field.Rotation = 90;
                    field.BackgroundColor = currBackgrd;
                    pdfStamper.AddAnnotation(field.GetTextField(), page);

                }
                pdfStamper.FormFlattening = true;
                pdfStamper.Close();
                reader.Close();
            }
            fs.Close();
        }
Пример #2
0
 private static void fillFormFields(iTextSharp.text.pdf.PdfReader reader, FileStream fs, SqlDataReader dr)
 {
     using (var pdfStamper = new PdfStamper(reader, fs))
     {
         int i = 0;
         while (dr.Read())
         {
             i++;
             pdfStamper.AcroFields.SetField("Day" + i.ToString(), FormatField(dr["Day"].ToString(), "Day"));
             pdfStamper.AcroFields.SetField("Time" + i.ToString(), FormatField(dr["Time"].ToString(), "Time"));
             pdfStamper.AcroFields.SetField("Type" + i.ToString(), FormatField(dr["Type"].ToString(), "Type"));
             pdfStamper.AcroFields.SetField("Topic" + i.ToString(), FormatField(dr["Topic"].ToString(), "Topic"));
             pdfStamper.AcroFields.SetField("Group" + i.ToString(), FormatField(dr["aaGroup"].ToString(), "aaGroup"));
             pdfStamper.AcroFields.SetField("Location" + i.ToString(), FormatField(dr["Location"].ToString(), "Location"));
             pdfStamper.AcroFields.SetField("City" + i.ToString(), FormatField(dr["City"].ToString(), "City"));
         }
         pdfStamper.FormFlattening = true;
         pdfStamper.Close();
         reader.Close();
     }
 }