A HeaderFooter-object is a Rectangle with text that can be put above and/or below every page.
Inheritance: Rectangle
コード例 #1
18
ファイル: ReportPdf.cs プロジェクト: jonbws/strengthreport
        public ReportPdf(Stream Output, Layout Layout, Template Template, Dictionary<string, string> ConfigParams)
            : base(Output, Layout, Template, ConfigParams)
        {
            Rectangle pageSize = new Rectangle(mm2pt(Template.PageSize.Width), mm2pt(Template.PageSize.Height));

            // Initialization
            m_Document = new Document(pageSize, mm2pt(Template.Margin.Left), mm2pt(Template.Margin.Right), mm2pt(Template.Margin.Top), mm2pt(Template.Margin.Bottom));
            m_Writer = PdfWriter.GetInstance(m_Document, Output);

            m_Document.AddCreationDate();
            m_Document.AddCreator("StrengthReport http://dev.progterv.info/strengthreport) and KeePass (http://keepass.info)");
            m_Document.AddKeywords("report");
            m_Document.AddTitle(Layout.Title+" (report)");

            // Header
            HeaderFooter header = new HeaderFooter(new Phrase(Layout.Title+", "+DateTime.Now.ToString(), m_Template.ReportFooter.getFont()), false);
            header.Alignment = Template.ReportFooter.getAlignment();
            m_Document.Header = header;

            // Footer
            HeaderFooter footer = new HeaderFooter(new Phrase(new Chunk("Page ", m_Template.ReportFooter.getFont())), new Phrase(new Chunk(".", m_Template.ReportFooter.getFont())));
            footer.Alignment = Template.ReportFooter.getAlignment();
            m_Document.Footer = footer;

            // TODO: Metadata
            // Open document
            m_Document.Open();

            // Report Heading
            {
                PdfPTable reportTitle = new PdfPTable(1);
                PdfPCell titleCell = new PdfPCell(new Phrase(Layout.Title, m_Template.ReportHeader.getFont()));
                titleCell.Border = 0;
                titleCell.FixedHeight = mm2pt(m_Template.ReportHeader.Height);
                titleCell.VerticalAlignment = Element.ALIGN_MIDDLE;
                titleCell.HorizontalAlignment = m_Template.ReportHeader.getAlignment();
                reportTitle.AddCell(titleCell);
                reportTitle.WidthPercentage = 100;
                m_Document.Add(reportTitle);
            }

            // Create main table
            m_Table = new PdfPTable(Layout.GetColumnWidths());
            m_Table.WidthPercentage = 100;
            m_Table.HeaderRows = 1;
            foreach (LayoutElement element in Layout) {
                PdfPCell cell = new PdfPCell(new Phrase(element.Title, m_Template.Header.getFont()));
                cell.BackgroundColor = m_Template.Header.Background.ToColor();
                cell.MinimumHeight = mm2pt(m_Template.Header.Height);
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                m_Table.AddCell(cell);
            }

            m_colorRow = new CMYKColor[] { m_Template.Row.BackgroundA.ToColor(), m_Template.Row.BackgroundB.ToColor() };
        }
コード例 #2
0
 /// <summary>
 /// Resets the header of this document.
 /// </summary>
 public virtual void ResetHeader()
 {
     header = null;
     foreach (IDocListener listener in _listeners)
     {
         listener.ResetHeader();
     }
 }
コード例 #3
0
 /// <summary>
 /// Resets the footer of this document.
 /// </summary>
 public virtual void ResetFooter()
 {
     this.footer = null;
     foreach (IDocListener listener in listeners)
     {
         listener.ResetFooter();
     }
 }
コード例 #4
0
ファイル: Document.cs プロジェクト: aakkssqq/CreatePDFCSharp
 /// <summary>
 /// Resets the footer of this document.
 /// </summary>
 public virtual void resetFooter()
 {
     this.footer = footer;
     foreach (IDocListener listener in listeners)
     {
         listener.resetFooter();
     }
 }
コード例 #5
0
ファイル: Document.cs プロジェクト: aakkssqq/CreatePDFCSharp
 /// <summary>
 /// Resets the header of this document.
 /// </summary>
 public virtual void resetHeader()
 {
     this.header = null;
     foreach (IDocListener listener in listeners)
     {
         listener.resetHeader();
     }
 }
コード例 #6
0
ファイル: B2FPDFDownLoad.cs プロジェクト: rivernli/SGP
 public void AddHeaderFooter()
 {
     string image_url = HttpContext.Current.Server.MapPath("~/tmp/logo.png");
     iTextSharp.text.Image png = iTextSharp.text.Image.getInstance(new Uri(image_url));
     png.scaleToFit(100, 100);
     png.Interpolation = true;
     HeaderFooter header = new HeaderFooter(new Phrase(new Chunk(png, 10, 0)), false);
     header.Border = iTextSharp.text.Rectangle.NO_BORDER;
     doc.Header = header;
 }
コード例 #7
0
ファイル: RtfWriter.cs プロジェクト: hjgode/iTextSharpCF
 private void ProcessHeaderFooter(HeaderFooter hf)
 {
     if (hf != null) {
         if (hf is RtfHeaderFooters) {
             RtfHeaderFooters rhf = (RtfHeaderFooters) hf;
             if (rhf.Get(RtfHeaderFooters.ALL_PAGES) != null) {
                 AddHeaderFooterFontColor(rhf.Get(RtfHeaderFooters.ALL_PAGES));
             }
             if (rhf.Get(RtfHeaderFooters.LEFT_PAGES) != null) {
                 AddHeaderFooterFontColor(rhf.Get(RtfHeaderFooters.LEFT_PAGES));
             }
             if (rhf.Get(RtfHeaderFooters.RIGHT_PAGES) != null) {
                 AddHeaderFooterFontColor(rhf.Get(RtfHeaderFooters.RIGHT_PAGES));
             }
             if (rhf.Get(RtfHeaderFooters.FIRST_PAGE) != null) {
                 AddHeaderFooterFontColor(rhf.Get(RtfHeaderFooters.FIRST_PAGE));
             }
         } else {
             AddHeaderFooterFontColor(hf);
         }
     }
 }
コード例 #8
0
 /**
 * Adds a HeaderFooter to this HeaderFooters object
 * @param type
 * @param hf
 */
 public void Set( int type, HeaderFooter hf )
 {
     switch (type) {
         case ALL_PAGES:
             allPages = hf;
             break;
         case LEFT_PAGES:
             leftPages = hf;
             break;
         case RIGHT_PAGES:
             rightPages = hf;
             break;
         case FIRST_PAGE:
             firstPage = hf;
             break;
         default:
             throw new ArgumentException( "unknown type " + type );
     }
 }
コード例 #9
0
ファイル: OfficeHelper.cs プロジェクト: mkbiltek2019/dlerp
        public static void Genera(string sourcePath, string title, List <InventoryReportModel> data)
        {
            sourcePath = HttpContext.Current.Server.MapPath(sourcePath);
            //定义一个Document,并设置页面大小为A4,竖向
            iTextSharp.text.Document doc = new Document(PageSize.A4);
            try
            {
                //写实例
                PdfWriter.GetInstance(doc, new FileStream(sourcePath, FileMode.Create));
                //打开document
                doc.Open();


                //载入字体
                BaseFont baseFont = BaseFont.CreateFont(
                    "C:\\WINDOWS\\FONTS\\SIMHEI.TTF", //黑体
                    BaseFont.IDENTITY_H,              //横向字体
                    BaseFont.NOT_EMBEDDED);
                iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, 9);

                #region 其他元素

                doc.Add(new Paragraph(title, font));


                //包含页码没有任何边框的页脚。
                iTextSharp.text.HeaderFooter footer = new iTextSharp.text.HeaderFooter(new Phrase("This is page: "), true);
                footer.Border = iTextSharp.text.Rectangle.NO_BORDER;
                doc.Footer    = footer;

                //构建了一个简单的表:

                int   rows   = data.Count;
                Table aTable = new Table(15, rows + 1);
                aTable.AutoFillEmptyCells = true;
                //行 从1开始,列 从0开始
                #region 表头
                // Chunk chunk1 = new Chunk("This text is underlined", FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.UNDEFINED));
                // Cell cell=new Cell(chunk1);
                //aTable.AddCell(cell,ne
                aTable.AddCell("序号", new System.Drawing.Point(1, 0));
                aTable.AddCell("耗材规格", new System.Drawing.Point(1, 1));
                aTable.AddCell("期初库存数", new System.Drawing.Point(1, 2));
                aTable.AddCell("期初库存数", new System.Drawing.Point(1, 3));
                aTable.AddCell("期初库存额", new System.Drawing.Point(1, 4));
                aTable.AddCell("入库数", new System.Drawing.Point(1, 5));
                aTable.AddCell("入库额", new System.Drawing.Point(1, 6));
                aTable.AddCell("出库数", new System.Drawing.Point(1, 7));
                aTable.AddCell("出库额", new System.Drawing.Point(1, 8));
                aTable.AddCell("期末库存数", new System.Drawing.Point(1, 9));
                aTable.AddCell("期末库存额", new System.Drawing.Point(1, 10));
                aTable.AddCell("期初结余量", new System.Drawing.Point(1, 11));
                aTable.AddCell("期初结余额", new System.Drawing.Point(1, 12));
                aTable.AddCell("期末结余量", new System.Drawing.Point(1, 13));
                aTable.AddCell("期末结余额", new System.Drawing.Point(1, 14));
                #endregion
                #region 内容
                for (int i = 0; i < rows; i++)
                {
                    var item = data[i];
                    aTable.AddCell((i + 1).ToString(), new System.Drawing.Point(i + 2, 0));
                    aTable.AddCell(item.material_specification_name + "(" + @item.material_specification_model + ")", new System.Drawing.Point(i + 2, 1));
                    aTable.AddCell(item.unit_html, new System.Drawing.Point(i + 2, 2));
                    aTable.AddCell(item.inventory_reports_beginning_amount.Value.ToString(), new System.Drawing.Point(i + 2, 3));
                    aTable.AddCell(item.inventory_reports_beginning_cost.Value.ToString("N"), new System.Drawing.Point(i + 2, 4));
                    aTable.AddCell(item.inventory_reports_in_amount.Value.ToString(), new System.Drawing.Point(i + 2, 5));
                    aTable.AddCell(item.inventory_reports_in_cost.Value.ToString("N"), new System.Drawing.Point(i + 2, 6));
                    aTable.AddCell(item.inventory_reports_out_amount.Value.ToString(), new System.Drawing.Point(i + 2, 7));
                    aTable.AddCell(item.inventory_reports_out_cost.Value.ToString("N"), new System.Drawing.Point(i + 2, 8));
                    aTable.AddCell(item.inventory_reports_ending_amount.Value.ToString(), new System.Drawing.Point(i + 2, 9));
                    aTable.AddCell(item.inventory_reports_ending_cost.Value.ToString("N"), new System.Drawing.Point(i + 2, 10));
                    aTable.AddCell(item.beginning_locale_amount.Value.ToString(), new System.Drawing.Point(i + 2, 11));
                    aTable.AddCell(item.beginning_locale_cost.Value.ToString("N"), new System.Drawing.Point(i + 2, 12));
                    aTable.AddCell(item.ending_locale_amount.Value.ToString(), new System.Drawing.Point(i + 2, 13));
                    aTable.AddCell(item.ending_locale_cost.Value.ToString("N"), new System.Drawing.Point(i + 2, 14));
                }
                #endregion
                doc.Add(aTable);



                #endregion
                //关闭document
                doc.Close();
                //打开PDF,看效果
                //Process.Start(sourcePath);
            }
            catch (DocumentException de)
            {
                Console.WriteLine(de.Message);
                Console.ReadKey();
            }
            catch (IOException io)
            {
                Console.WriteLine(io.Message);
                Console.ReadKey();
            }
        }
コード例 #10
0
ファイル: OfficeHelper.cs プロジェクト: mkbiltek2019/dlerp
        public static void Genera(string sourcePath, string content)
        {
            sourcePath = HttpContext.Current.Server.MapPath(sourcePath);
            //定义一个Document,并设置页面大小为A4,竖向
            iTextSharp.text.Document doc = new Document(PageSize.A4);
            try
            {
                //写实例
                PdfWriter.GetInstance(doc, new FileStream(sourcePath, FileMode.Create));
                //打开document
                doc.Open();


                //载入字体
                BaseFont baseFont = BaseFont.CreateFont(
                    "C:\\WINDOWS\\FONTS\\SIMHEI.TTF", //黑体
                    BaseFont.IDENTITY_H,              //横向字体
                    BaseFont.NOT_EMBEDDED);
                iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, 9);


                //写入一个段落, Paragraph
                doc.Add(new Paragraph("第一段:" + content, font));
                doc.Add(new Paragraph("这是第二段 !", font));


                #region 图片
                //以下代码用来添加图片,此时图片是做为背景加入到pdf文件当中的:

                Stream inputImageStream     = new FileStream(HttpContext.Current.Server.MapPath("~/images/logo.jpg"), FileMode.Open, FileAccess.Read, FileShare.Read);
                iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(inputImageStream);
                image.SetAbsolutePosition(0, 0);
                image.Alignment = iTextSharp.text.Image.UNDERLYING;    //这里可以设定图片是做为背景还是做为元素添加到文件中
                doc.Add(image);

                #endregion
                #region 其他元素
                doc.Add(new Paragraph("Hello World"));
                //另起一行。有几种办法建立一个段落,如:
                Paragraph p1 = new Paragraph(new Chunk("This is my first paragraph.\n", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
                Paragraph p2 = new Paragraph(new Phrase("This is my second paragraph.", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
                Paragraph p3 = new Paragraph("This is my third paragraph.", FontFactory.GetFont(FontFactory.HELVETICA, 12));
                //所有有些对象将被添加到段落中:
                p1.Add("you can add string here\n\t");
                p1.Add(new Chunk("you can add chunks \n")); p1.Add(new Phrase("or you can add phrases.\n"));
                doc.Add(p1); doc.Add(p2); doc.Add(p3);

                //创建了一个内容为“hello World”、红色、斜体、COURIER字体、尺寸20的一个块:
                Chunk chunk = new Chunk("创建了一个内容为“hello World”、红色、斜体、COURIER字体、尺寸20的一个块", FontFactory.GetFont(FontFactory.COURIER, 20, iTextSharp.text.Font.COURIER, new iTextSharp.text.Color(255, 0, 0)));
                doc.Add(chunk);
                //如果你希望一些块有下划线或删除线,你可以通过改变字体风格简单做到:
                Chunk chunk1 = new Chunk("This text is underlined", FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.UNDEFINED));
                Chunk chunk2 = new Chunk("This font is of type ITALIC | STRIKETHRU", FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.ITALIC | iTextSharp.text.Font.STRIKETHRU));
                //改变块的背景
                chunk2.SetBackground(new iTextSharp.text.Color(0xFF, 0xFF, 0x00));
                //上标/下标
                chunk1.SetTextRise(5);
                doc.Add(chunk1);
                doc.Add(chunk2);

                //外部链接示例:
                Anchor anchor = new Anchor("website", FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.UNDEFINED, new iTextSharp.text.Color(0, 0, 255)));
                anchor.Reference = "http://itextsharp.sourceforge.net";
                anchor.Name      = "website";
                //内部链接示例:
                Anchor anchor1 = new Anchor("This is an internal link\n\n");
                anchor1.Name = "link1";
                Anchor anchor2 = new Anchor("Click here to jump to the internal link\n\f");
                anchor2.Reference = "#link1";
                doc.Add(anchor); doc.Add(anchor1); doc.Add(anchor2);

                //排序列表示例:
                List list = new List(true, 20);
                list.Add(new ListItem("First line"));
                list.Add(new ListItem("The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?"));
                list.Add(new ListItem("Third line"));
                doc.Add(list);

                //文本注释:
                Annotation a = new Annotation("authors", "Maybe its because I wanted to be an author myself that I wrote iText.");
                doc.Add(a);

                //包含页码没有任何边框的页脚。
                iTextSharp.text.HeaderFooter footer = new iTextSharp.text.HeaderFooter(new Phrase("This is page: "), true);
                footer.Border = iTextSharp.text.Rectangle.NO_BORDER;
                doc.Footer    = footer;


                //Chapter对象和Section对象自动构建一个树:
                iTextSharp.text.Font f1 = new iTextSharp.text.Font();
                f1.SetStyle(iTextSharp.text.Font.BOLD);
                Paragraph cTitle  = new Paragraph("This is chapter 1", f1);
                Chapter   chapter = new Chapter(cTitle, 1);
                Paragraph sTitle  = new Paragraph("This is section 1 in chapter 1", f1);
                Section   section = chapter.AddSection(sTitle, 1);
                doc.Add(chapter);

                //构建了一个简单的表:
                Table aTable = new Table(4, 4);
                aTable.AutoFillEmptyCells = true;
                aTable.AddCell("2.2", new System.Drawing.Point(2, 2));
                aTable.AddCell("3.3", new System.Drawing.Point(3, 3));
                aTable.AddCell("2.1", new System.Drawing.Point(2, 1));
                aTable.AddCell("1.3", new System.Drawing.Point(1, 3));
                doc.Add(aTable);
                //构建了一个不简单的表:
                Table table = new Table(3);
                table.BorderWidth = 1;
                table.BorderColor = new iTextSharp.text.Color(0, 0, 255);
                table.Cellpadding = 5;
                table.Cellspacing = 5;
                Cell cell = new Cell("header");
                cell.Header  = true;
                cell.Colspan = 3;
                table.AddCell(cell);
                cell             = new Cell("example cell with colspan 1 and rowspan 2");
                cell.Rowspan     = 2;
                cell.BorderColor = new iTextSharp.text.Color(255, 0, 0);
                table.AddCell(cell);
                table.AddCell("1.1");
                table.AddCell("2.1");
                table.AddCell("1.2");
                table.AddCell("2.2");
                table.AddCell("cell test1");
                cell                 = new Cell("big cell");
                cell.Rowspan         = 2;
                cell.Colspan         = 2;
                cell.BackgroundColor = new iTextSharp.text.Color(0xC0, 0xC0, 0xC0);
                table.AddCell(cell);
                table.AddCell("cell test2");
                // 改变了单元格“big cell”的对齐方式:
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment   = Element.ALIGN_MIDDLE;
                doc.Add(table);

                #endregion
                //关闭document
                doc.Close();
                //打开PDF,看效果
                //Process.Start(sourcePath);
            }
            catch (DocumentException de)
            {
                Console.WriteLine(de.Message);
                Console.ReadKey();
            }
            catch (IOException io)
            {
                Console.WriteLine(io.Message);
                Console.ReadKey();
            }
        }
コード例 #11
0
ファイル: PdfHelper.cs プロジェクト: sd1362168638/XSEMS
 public static HeaderFooter GetHeardFooter(string companyName, string phone)
 {
     HeaderFooter header = new HeaderFooter(new Phrase("" + companyName + "                                                                   Tel£º" + phone, fontHeader), false);
     header.Border = Rectangle.BOTTOM;
     return header;
 }
コード例 #12
0
ファイル: RtfWriter.cs プロジェクト: hjgode/iTextSharpCF
 /**
 * Write a <code>HeaderFooter</code> to a <code>MemoryStream</code>
 *
 * @param headerFooter  The <code>HeaderFooter</code> object to be written.
 * @param hfType        The type of header or footer to be added.
 * @param target        The <code>MemoryStream</code> to which the <code>HeaderFooter</code> will be written.
 * @throws IOException
 */
 private void WriteHeaderFooter(HeaderFooter headerFooter, byte[] hfType, MemoryStream target)
 {
     inHeaderFooter = true;
     try {
         target.WriteByte(openGroup);
         target.WriteByte(escape);
         target.Write(hfType, 0, hfType.Length);
         target.WriteByte(delimiter);
         if (headerFooter != null) {
             if (headerFooter is RtfHeaderFooter && ((RtfHeaderFooter) headerFooter).Content() != null) {
                 this.AddElement(((RtfHeaderFooter) headerFooter).Content(), target);
             } else {
                 Paragraph par = new Paragraph();
                 par.Alignment = headerFooter.Alignment;
                 if (headerFooter.Before != null) {
                     par.Add(headerFooter.Before);
                 }
                 if (headerFooter.IsNumbered()) {
                     par.Add(new RtfPageNumber("", headerFooter.Before.Font));
                 }
                 if (headerFooter.After != null) {
                     par.Add(headerFooter.After);
                 }
                 this.AddElement(par, target);
             }
         }
         target.WriteByte(closeGroup);
     } catch (DocumentException e) {
         throw new IOException("DocumentException - " + e.ToString());
     }
     inHeaderFooter = false;
 }
コード例 #13
0
 /**
 * Sets the current footer to use
 * 
 * @param footer The HeaderFooter to use as footer
 */
 public void SetFooter(HeaderFooter footer) {
     this.footer = footer;
 }
コード例 #14
0
ファイル: IcjDocument.cs プロジェクト: tuankyo/QLTN
 public void AddFooter(HeaderFooter footer)
 {
     document.Footer = footer;
 }
コード例 #15
0
ファイル: IcjDocument.cs プロジェクト: tuankyo/QLTN
 public void AddHeader(HeaderFooter header)
 {
     document.Header = header;
 }
コード例 #16
0
ファイル: OfficeHelper.cs プロジェクト: gofixiao/dlerp
        public static void Genera(string sourcePath, string title, List<InventoryReportModel> data)
        {
            sourcePath = HttpContext.Current.Server.MapPath(sourcePath);
            //定义一个Document,并设置页面大小为A4,竖向
            iTextSharp.text.Document doc = new Document(PageSize.A4);
            try
            {
                //写实例
                PdfWriter.GetInstance(doc, new FileStream(sourcePath, FileMode.Create));
                //打开document
                doc.Open();

                //载入字体
                BaseFont baseFont = BaseFont.CreateFont(
                    "C:\\WINDOWS\\FONTS\\SIMHEI.TTF", //黑体
                    BaseFont.IDENTITY_H, //横向字体
                    BaseFont.NOT_EMBEDDED);
                iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, 9);

                #region 其他元素

                doc.Add(new Paragraph(title, font));

                //包含页码没有任何边框的页脚。
                iTextSharp.text.HeaderFooter footer = new iTextSharp.text.HeaderFooter(new Phrase("This is page: "), true);
                footer.Border = iTextSharp.text.Rectangle.NO_BORDER;
                doc.Footer = footer;

                //构建了一个简单的表:

                int rows = data.Count;
                Table aTable = new Table(15, rows+1);
                aTable.AutoFillEmptyCells = true;
                //行 从1开始,列 从0开始
                #region 表头
               // Chunk chunk1 = new Chunk("This text is underlined", FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.UNDEFINED));
               // Cell cell=new Cell(chunk1);
                //aTable.AddCell(cell,ne
                aTable.AddCell("序号", new System.Drawing.Point(1, 0));
                aTable.AddCell("耗材规格", new System.Drawing.Point(1, 1));
                aTable.AddCell("期初库存数", new System.Drawing.Point(1, 2));
                aTable.AddCell("期初库存数", new System.Drawing.Point(1,3));
                aTable.AddCell("期初库存额", new System.Drawing.Point(1, 4));
                aTable.AddCell("入库数", new System.Drawing.Point(1,5));
                aTable.AddCell("入库额", new System.Drawing.Point(1, 6));
                aTable.AddCell("出库数", new System.Drawing.Point(1, 7));
                aTable.AddCell("出库额", new System.Drawing.Point(1, 8));
                aTable.AddCell("期末库存数", new System.Drawing.Point(1, 9));
                aTable.AddCell("期末库存额", new System.Drawing.Point(1, 10));
                aTable.AddCell("期初结余量", new System.Drawing.Point(1, 11));
                aTable.AddCell("期初结余额", new System.Drawing.Point(1, 12));
                aTable.AddCell("期末结余量", new System.Drawing.Point(1, 13));
                aTable.AddCell("期末结余额", new System.Drawing.Point(1, 14));
                #endregion
                #region 内容
                for (int i = 0; i < rows; i++)
                {
                    var item = data[i];
                    aTable.AddCell((i + 1).ToString(), new System.Drawing.Point(i + 2, 0));
                    aTable.AddCell(item.material_specification_name + "(" + @item.material_specification_model + ")", new System.Drawing.Point(i + 2, 1));
                    aTable.AddCell(item.unit_html, new System.Drawing.Point(i + 2, 2));
                    aTable.AddCell(item.inventory_reports_beginning_amount.Value.ToString(), new System.Drawing.Point(i + 2, 3));
                    aTable.AddCell(item.inventory_reports_beginning_cost.Value.ToString("N"), new System.Drawing.Point(i + 2, 4));
                    aTable.AddCell(item.inventory_reports_in_amount.Value.ToString(), new System.Drawing.Point(i + 2, 5));
                    aTable.AddCell(item.inventory_reports_in_cost.Value.ToString("N"), new System.Drawing.Point(i + 2, 6));
                    aTable.AddCell(item.inventory_reports_out_amount.Value.ToString(), new System.Drawing.Point(i + 2, 7));
                    aTable.AddCell(item.inventory_reports_out_cost.Value.ToString("N"), new System.Drawing.Point(i + 2, 8));
                    aTable.AddCell(item.inventory_reports_ending_amount.Value.ToString(), new System.Drawing.Point(i + 2, 9));
                    aTable.AddCell(item.inventory_reports_ending_cost.Value.ToString("N"), new System.Drawing.Point(i + 2, 10));
                    aTable.AddCell(item.beginning_locale_amount.Value.ToString(), new System.Drawing.Point(i + 2, 11));
                    aTable.AddCell(item.beginning_locale_cost.Value.ToString("N"), new System.Drawing.Point(i + 2, 12));
                    aTable.AddCell(item.ending_locale_amount.Value.ToString(), new System.Drawing.Point(i + 2, 13));
                    aTable.AddCell(item.ending_locale_cost.Value.ToString("N"), new System.Drawing.Point(i + 2, 14));
                }
                #endregion
                doc.Add(aTable);

                #endregion
                //关闭document
                doc.Close();
                //打开PDF,看效果
                //Process.Start(sourcePath);
            }
            catch (DocumentException de)
            {
                Console.WriteLine(de.Message);
                Console.ReadKey();
            }
            catch (IOException io)
            {
                Console.WriteLine(io.Message);
                Console.ReadKey();
            }
        }
コード例 #17
0
ファイル: OfficeHelper.cs プロジェクト: gofixiao/dlerp
        public static void Genera(string sourcePath,string content)
        {
            sourcePath = HttpContext.Current.Server.MapPath(sourcePath);
            //定义一个Document,并设置页面大小为A4,竖向
            iTextSharp.text.Document doc = new Document(PageSize.A4);
            try
            {
                //写实例
                PdfWriter.GetInstance(doc, new FileStream(sourcePath, FileMode.Create));
                //打开document
                doc.Open();

                //载入字体
                BaseFont baseFont = BaseFont.CreateFont(
                    "C:\\WINDOWS\\FONTS\\SIMHEI.TTF", //黑体
                    BaseFont.IDENTITY_H, //横向字体
                    BaseFont.NOT_EMBEDDED);
                iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, 9);

                //写入一个段落, Paragraph
                doc.Add(new Paragraph("第一段:" + content, font));
                doc.Add(new Paragraph("这是第二段 !", font));

                #region 图片
                //以下代码用来添加图片,此时图片是做为背景加入到pdf文件当中的:

                Stream inputImageStream = new FileStream(HttpContext.Current.Server.MapPath("~/images/logo.jpg"), FileMode.Open, FileAccess.Read, FileShare.Read);
                iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(inputImageStream);
                image.SetAbsolutePosition(0, 0);
                image.Alignment = iTextSharp.text.Image.UNDERLYING;    //这里可以设定图片是做为背景还是做为元素添加到文件中
                doc.Add(image);

                #endregion
                #region 其他元素
                doc.Add(new Paragraph("Hello World"));
                //另起一行。有几种办法建立一个段落,如:
                Paragraph p1 = new Paragraph(new Chunk("This is my first paragraph.\n", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
                Paragraph p2 = new Paragraph(new Phrase("This is my second paragraph.", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
                Paragraph p3 = new Paragraph("This is my third paragraph.", FontFactory.GetFont(FontFactory.HELVETICA, 12));
                //所有有些对象将被添加到段落中:
                p1.Add("you can add string here\n\t");
                p1.Add(new Chunk("you can add chunks \n")); p1.Add(new Phrase("or you can add phrases.\n"));
                doc.Add(p1); doc.Add(p2); doc.Add(p3);

                //创建了一个内容为“hello World”、红色、斜体、COURIER字体、尺寸20的一个块:
                Chunk chunk = new Chunk("创建了一个内容为“hello World”、红色、斜体、COURIER字体、尺寸20的一个块", FontFactory.GetFont(FontFactory.COURIER, 20, iTextSharp.text.Font.COURIER, new iTextSharp.text.Color(255, 0, 0)));
                doc.Add(chunk);
                //如果你希望一些块有下划线或删除线,你可以通过改变字体风格简单做到:
                Chunk chunk1 = new Chunk("This text is underlined", FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.UNDEFINED));
                Chunk chunk2 = new Chunk("This font is of type ITALIC | STRIKETHRU", FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.ITALIC | iTextSharp.text.Font.STRIKETHRU));
                //改变块的背景
                chunk2.SetBackground(new iTextSharp.text.Color(0xFF, 0xFF, 0x00));
                //上标/下标
                chunk1.SetTextRise(5);
                doc.Add(chunk1);
                doc.Add(chunk2);

                //外部链接示例:
                Anchor anchor = new Anchor("website", FontFactory.GetFont(FontFactory.HELVETICA, 12, iTextSharp.text.Font.UNDEFINED, new iTextSharp.text.Color(0, 0, 255)));
                anchor.Reference = "http://itextsharp.sourceforge.net";
                anchor.Name = "website";
                //内部链接示例:
                Anchor anchor1 = new Anchor("This is an internal link\n\n");
                anchor1.Name = "link1";
                Anchor anchor2 = new Anchor("Click here to jump to the internal link\n\f");
                anchor2.Reference = "#link1";
                doc.Add(anchor); doc.Add(anchor1); doc.Add(anchor2);

                //排序列表示例:
                List list = new List(true, 20);
                list.Add(new ListItem("First line"));
                list.Add(new ListItem("The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?"));
                list.Add(new ListItem("Third line"));
                doc.Add(list);

                //文本注释:
                Annotation a = new Annotation("authors", "Maybe its because I wanted to be an author myself that I wrote iText.");
                doc.Add(a);

                //包含页码没有任何边框的页脚。
                iTextSharp.text.HeaderFooter footer = new iTextSharp.text.HeaderFooter(new Phrase("This is page: "), true);
                footer.Border = iTextSharp.text.Rectangle.NO_BORDER;
                doc.Footer = footer;

                //Chapter对象和Section对象自动构建一个树:
                iTextSharp.text.Font f1 = new iTextSharp.text.Font();
                f1.SetStyle(iTextSharp.text.Font.BOLD);
                Paragraph cTitle = new Paragraph("This is chapter 1", f1);
                Chapter chapter = new Chapter(cTitle, 1);
                Paragraph sTitle = new Paragraph("This is section 1 in chapter 1", f1);
                Section section = chapter.AddSection(sTitle, 1);
                doc.Add(chapter);

                //构建了一个简单的表:
                Table aTable = new Table(4, 4);
                aTable.AutoFillEmptyCells = true;
                aTable.AddCell("2.2", new System.Drawing.Point(2, 2));
                aTable.AddCell("3.3", new System.Drawing.Point(3, 3));
                aTable.AddCell("2.1", new System.Drawing.Point(2, 1));
                aTable.AddCell("1.3", new System.Drawing.Point(1, 3));
                doc.Add(aTable);
                //构建了一个不简单的表:
                Table table = new Table(3);
                table.BorderWidth = 1;
                table.BorderColor = new iTextSharp.text.Color(0, 0, 255);
                table.Cellpadding = 5;
                table.Cellspacing = 5;
                Cell cell = new Cell("header");
                cell.Header = true;
                cell.Colspan = 3;
                table.AddCell(cell);
                cell = new Cell("example cell with colspan 1 and rowspan 2");
                cell.Rowspan = 2;
                cell.BorderColor = new iTextSharp.text.Color(255, 0, 0);
                table.AddCell(cell);
                table.AddCell("1.1");
                table.AddCell("2.1");
                table.AddCell("1.2");
                table.AddCell("2.2");
                table.AddCell("cell test1");
                cell = new Cell("big cell");
                cell.Rowspan = 2;
                cell.Colspan = 2;
                cell.BackgroundColor = new iTextSharp.text.Color(0xC0, 0xC0, 0xC0);
                table.AddCell(cell);
                table.AddCell("cell test2");
                // 改变了单元格“big cell”的对齐方式:
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                doc.Add(table);

                #endregion
                //关闭document
                doc.Close();
                //打开PDF,看效果
                //Process.Start(sourcePath);
            }
            catch (DocumentException de)
            {
                Console.WriteLine(de.Message);
                Console.ReadKey();
            }
            catch (IOException io)
            {
                Console.WriteLine(io.Message);
                Console.ReadKey();
            }
        }
コード例 #18
0
 /**
 * Initialises the RtfDocumentHeader.
 */
 protected internal void Init() {
     this.codePage = new RtfCodePage(this.document);
     this.colorList = new RtfColorList(this.document);
     this.fontList = new RtfFontList(this.document);
     this.listTable = new RtfListTable(this.document);
     this.stylesheetList = new RtfStylesheetList(this.document);
     this.infoGroup = new RtfInfoGroup(this.document);
     this.protectionSetting = new RtfProtectionSetting(this.document);
     this.pageSetting = new RtfPageSetting(this.document);
     this.header = new RtfHeaderFooterGroup(this.document, HF.RtfHeaderFooter.TYPE_HEADER);
     this.footer = new RtfHeaderFooterGroup(this.document, HF.RtfHeaderFooter.TYPE_FOOTER);
     this.generator = new RtfGenerator(this.document);
 }
コード例 #19
0
ファイル: PdfReportBuilder.cs プロジェクト: nico-izo/KOIB
 public PrinterJob Build(ReportType reportType, int copies)
 {
     var reportConfig = Managers.PrintingManager.ReportConfig;
     var logger = Managers.PrintingManager.Logger;
     logger.LogVerbose(Message.Common_DebugCall);
     _totalPagesCount = 0;
     _currentPageNumber = 0;
     var fileName = FileUtils.GetUniqueName(
         Managers.FileSystemManager.GetDataDirectoryPath(FileType.Report),
         String.Format("{0}.{1:yyyyMMdd}.", "PrintJob", DateTime.Now),
         "pdf",
         6);
     var filePath = Path.Combine(Managers.FileSystemManager.GetDataDirectoryPath(FileType.Report), fileName);
     using (var stream = new MemoryStream())
     {
         try
         {
             _pdfDocument = new Document(PageSize.A4);
             _pdfDocument.ClaspFooter = ClaspFooter;
             PdfWriter writer = PdfWriter.GetInstance(_pdfDocument, stream);
             writer.PageEvent = new PdfEventHelper(this);
             _pdfDocument.SetMargins(Margins[0], Margins[1], Margins[2], Margins[3]);
             var fontFileName = Path.Combine(reportConfig.Font.Path,
                                             TemplateFont.ToString().ToLower() + FONT_FILE_EXTENSION);
             BaseFont baseFont = BaseFont.CreateFont(fontFileName, FONT_CODEPAGE, true);
             _font = new Font(baseFont, _defaultFontSize, Font.NORMAL);
             if (Headers.ContainsKey(PageSection.PageHeader) && Headers[PageSection.PageHeader].Count > 0)
             {
                 logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Создание PageHeader");
                 var head = new HeaderFooter(MakeParagraph(Headers[PageSection.PageHeader]), false);
                 head.Border = Border;
                 _pdfDocument.Header = head;
                 logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Создание PageHeader");
             }
             if (Headers.ContainsKey(PageSection.PageFooter) && Headers[PageSection.PageFooter].Count > 0)
             {
                 logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Создание PageFooter");
                 Paragraph footParagraph = MakeParagraph(Headers[PageSection.PageFooter]);
                 if (PageNumbered)
                 {
                     footParagraph.Add(new Phrase(Chunk.NEWLINE));
                     footParagraph.Add(new Phrase(Chunk.NEWLINE));
                 }
                 var foot = new HeaderFooter(footParagraph, false);
                 foot.Border = Border;
                 _pdfDocument.Footer = foot;
                 logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Создание PageFooter");
             }
             try
             {
                 _pdfDocument.Open();
             }
             catch (Exception ex)
             {
                 throw new Exception("Ошибка формирования PDF", ex);
             }
             if (Headers.ContainsKey(PageSection.Header))
             {
                 logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Создание Header");
                 _pdfDocument.Add(MakeParagraph(Headers[PageSection.Header]));
                 logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Создание Header");
             }
             if (Data != null)
             {
                 int dataTablesCount = Data.Tables.Cast<DataTable>().Count(table => !table.TableName.StartsWith("C"));
                 for (int tableIndex = 0; tableIndex < dataTablesCount; tableIndex++)
                 {
                     float tableFactor = (_pdfDocument.Right - _pdfDocument.Left) / 100;
                     string tableName = tableIndex.ToString();
                     logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Создание Таблицы " + tableName);
                     if (Data.Tables.Contains(tableName) && Data.Tables[tableName] != null)
                     {
                         var currentTable = Data.Tables[tableName];
                         int serviceColumnCount =
                             currentTable.Columns.Cast<DataColumn>().Count(
                                 c => c.ColumnName.StartsWith(ServiceTableColumns.SERVICE_COLUMN_PREFIX));
                         int dataColumns = currentTable.Columns.Count - serviceColumnCount;
                         if (currentTable.Rows.Count > 0)
                         {
                             Table tbl = MakeTable(dataColumns, currentTable.Rows.Count);
                             foreach (DataRow row in currentTable.Rows)
                             {
                                 if (((ServiceMode)row[ServiceTableColumns.ServiceMode] &
                                      ServiceMode.ResetPageCounter) > 0)
                                 {
                                     _currentPageNumber = 0;
                                 }
                                 TableDotted = (bool)row[ServiceTableColumns.IsTableDotted];
                                 if (((ServiceMode)row[ServiceTableColumns.ServiceMode] &
                                      ServiceMode.PageBreak) > 0)
                                 {
                                     if (row == currentTable.Rows.Cast<DataRow>().Last() &&
                                         !Data.Tables.Contains((tableIndex + 1).ToString()))
                                         continue;
                                     _pdfDocument.Add(tbl);
                                     _pdfDocument.NewPage();
                                     tbl = MakeTable(dataColumns, currentTable.Rows.Count);
                                 }
                                 var colLines = new string[dataColumns];
                                 var colWidths = new float[dataColumns];
                                 var colAligns = new LineAlign?[dataColumns];
                                 int fontSize = _defaultFontSize;
                                 bool bold = false;
                                 bool italic = false;
                                 LineAlign lineAlign = LineAlign.Left;
                                 for (int columnIndex = 0; columnIndex < currentTable.Columns.Count; columnIndex++)
                                 {
                                     switch (currentTable.Columns[columnIndex].ColumnName)
                                     {
                                         case ServiceTableColumns.FontSize:
                                             fontSize = (int)(row.ItemArray[columnIndex]);
                                             break;
                                         case ServiceTableColumns.IsBold:
                                             bold = (bool)(row.ItemArray[columnIndex]);
                                             break;
                                         case ServiceTableColumns.IsItalic:
                                             italic = (bool)(row.ItemArray[columnIndex]);
                                             break;
                                         case ServiceTableColumns.Align:
                                             lineAlign = (LineAlign)(row.ItemArray[columnIndex]);
                                             break;
                                         default:
                                             if (!currentTable.Columns[columnIndex]
                                                     .ColumnName.StartsWith(ServiceTableColumns.SERVICE_COLUMN_PREFIX))
                                             {
                                                 colLines[columnIndex] = row.ItemArray[columnIndex].ToString();
                                                 if (Data.Tables["C" + tableIndex] != null)
                                                 {
                                                     DataRow[] columnProps = Data.Tables["C" + tableIndex]
                                                         .Select(ServiceTableColumns.Name + " = '"
                                                                 + currentTable.Columns[columnIndex].ColumnName + "'");
                                                     if (columnProps.Length > 0)
                                                     {
                                                         colWidths[columnIndex] = (int)columnProps[0][ServiceTableColumns.Width];
                                                         if (columnProps[0][ServiceTableColumns.Align] != DBNull.Value)
                                                         {
                                                             colAligns[columnIndex] = (LineAlign)columnProps[0][ServiceTableColumns.Align];
                                                         }
                                                     }
                                                 }
                                             }
                                             break;
                                     }
                                 }
                                 Font tempFont = GetFont(fontSize, bold, italic, baseFont);
                                 var cellLeading = (float)Math.Round(tempFont.Size * DBL_LEADING_FONT);
                                 tbl.Widths = colWidths;
                                 for (int columnIndex = 0; columnIndex < dataColumns; columnIndex++)
                                 {
                                     float cellWidth = tableFactor * colWidths[columnIndex];
                                     colLines[columnIndex] = TextAlign(
                                         colLines[columnIndex], tempFont, colAligns[columnIndex] ?? lineAlign,
                                         cellWidth, (row != currentTable.Rows.Cast<DataRow>().First()
                                                     && TableDotted)
                                                     ? '.'
                                                     : ' ');
                                     var cell =
                                         new Cell(new Phrase(cellLeading, colLines[columnIndex], tempFont))
                                             {
                                                 Border = Border,
                                                 Leading = cellLeading,
                                             };
                                     tbl.AddCell(cell);
                                 }
                             }
                             logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Создание Таблицы " + tableName);
                             logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Добавление Таблицы " + tableName);
                             _pdfDocument.Add(tbl);
                             logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Добавление Таблицы " + tableName);
                         }
                     }
                 }
             }
             if (Headers.ContainsKey(PageSection.Footer) && Headers[PageSection.Footer].Count > 0)
             {
                 logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Создание Footer");
                 _pdfDocument.Add(new Phrase(Chunk.NEWLINE));
                 _pdfDocument.Add(MakeParagraph(Headers[PageSection.Footer]));
                 logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Создание Footer");
             }
             _pdfDocument.Close();
             var size = (stream.ToArray().Length / FileUtils.BYTES_IN_KB) + 1;
             if (!Managers.FileSystemManager.ReserveDiskSpace(filePath, size))
             {
                 throw new ApplicationException("Недостаточно места на диске для сохранения отчета");
             }
             File.WriteAllBytes(filePath, stream.ToArray());
             SystemHelper.SyncFileSystem();
             logger.LogVerbose(Message.Common_DebugReturn);
             return new PrinterJob(reportType, filePath, _totalPagesCount, copies);
         }
         catch (Exception ex)
         {
             Managers.PrintingManager.Logger.LogError(Message.PrintingPdfBuildFailed, ex);
         }
     }
     return null;
 }
コード例 #20
0
 /**
 * Sets the current header to use
 * 
 * @param header The HeaderFooter to use as header
 */
 public void SetHeader(HeaderFooter header) {
     this.header = header;
 }
コード例 #21
0
ファイル: RtfWriter.cs プロジェクト: hjgode/iTextSharpCF
 /**
 * Resets the header.
 */
 public override void ResetHeader()
 {
     Header = null;
 }
コード例 #22
0
 /**
 * Converts a HeaderFooter into a RtfHeaderFooterGroup. Depending on which class
 * the HeaderFooter is, the correct RtfHeaderFooterGroup is created.
 * 
 * @param hf The HeaderFooter to convert.
 * @param type Whether the conversion is being done on a footer or header
 * @return The converted RtfHeaderFooterGroup.
 * @see com.lowagie.text.rtf.headerfooter.RtfHeaderFooter
 * @see com.lowagie.text.rtf.headerfooter.RtfHeaderFooterGroup
 */
 private RtfHeaderFooterGroup ConvertHeaderFooter(HeaderFooter hf, int type) {
     if (hf != null) {
         if (hf is RtfHeaderFooterGroup) {
             return new RtfHeaderFooterGroup(this.document, (RtfHeaderFooterGroup) hf, type);
         } else if (hf is RtfHeaderFooter) {
             return new RtfHeaderFooterGroup(this.document, (RtfHeaderFooter) hf, type);
         } else {
             return new RtfHeaderFooterGroup(this.document, hf, type);
         }
     } else {
         return new RtfHeaderFooterGroup(this.document, type);
     }
 }
コード例 #23
0
 /**
 * Constructs a RtfHeaderGroup for a certain HeaderFooter
 *
 * @param doc The RtfDocument this RtfHeaderFooter belongs to
 * @param headerFooter The HeaderFooter to display
 * @param type The typ of RtfHeaderFooterGroup to create
 */
 public RtfHeaderFooterGroup(RtfDocument doc, HeaderFooter headerFooter, int type)
     : base(new Phrase(""), false)
 {
     this.document = doc;
     this.type = type;
     this.mode = MODE_SINGLE;
     headerAll = new RtfHeaderFooter(doc, headerFooter, type, RtfHeaderFooter.DISPLAY_ALL_PAGES);
     headerAll.SetType(this.type);
 }
コード例 #24
0
 /**
 * Constructs a RtfHeaderFooter for a HeaderFooter.
 *
 * @param doc The RtfDocument this RtfHeaderFooter belongs to
 * @param headerFooter The HeaderFooter to base this RtfHeaderFooter on
 */
 protected internal RtfHeaderFooter(RtfDocument doc, HeaderFooter headerFooter)
     : base(new Phrase(""), false)
 {
     this.document = doc;
     Paragraph par = new Paragraph();
     par.Alignment = headerFooter.Alignment;
     if (headerFooter.Before != null) {
         par.Add(headerFooter.Before);
     }
     if (headerFooter.IsNumbered()) {
         par.Add(new FD.RtfPageNumber(this.document));
     }
     if (headerFooter.After != null) {
         par.Add(headerFooter.After);
     }
     try {
         this.content = new Object[1];
         this.content[0] = doc.GetMapper().MapElement(par)[0];
         ((IRtfBasicElement) this.content[0]).SetInHeader(true);
     } catch (DocumentException) {
     }
 }
コード例 #25
0
 /**
 * Set a HeaderFooter to be displayed at a certain position
 *
 * @param headerFooter The HeaderFooter to set
 * @param displayAt The display location to use
 */
 public void SetHeaderFooter(HeaderFooter headerFooter, int displayAt)
 {
     this.mode = MODE_MULTIPLE;
     switch (displayAt) {
         case RtfHeaderFooter.DISPLAY_ALL_PAGES:
             headerAll = new RtfHeaderFooter(this.document, headerFooter, this.type, displayAt);
             break;
         case RtfHeaderFooter.DISPLAY_FIRST_PAGE:
             headerFirst = new RtfHeaderFooter(this.document, headerFooter, this.type, displayAt);
             break;
         case RtfHeaderFooter.DISPLAY_LEFT_PAGES:
             headerLeft = new RtfHeaderFooter(this.document, headerFooter, this.type, displayAt);
             break;
         case RtfHeaderFooter.DISPLAY_RIGHT_PAGES:
             headerRight = new RtfHeaderFooter(this.document, headerFooter, this.type, displayAt);
             break;
     }
 }
コード例 #26
0
ファイル: ExportFile.cs プロジェクト: uwitec/gloryview-rfid
        //导出PDF文件方法
        /// <summary>
        /// DataTable导出到PDF
        /// </summary>
        /// <param name="datatable">DataTable</param>
        /// <param name="PDFFilePath">导出的PDF存储路径</param>
        /// <param name="PdfSaveTitle">导出的文件名</param>
        /// <param name="FontPath">字体路径</param>
        /// <param name="FontSize">字体大小</param>
        /// <param name="widthmz">每一列宽度</param>
        /// <returns>布尔值</returns>
        public static bool ConvertDataTableToPDF(DataTable datatable, string PDFFilePath, string PdfSaveTitle, Brush brush, float FontSize, float[] widthmz)
        {

            if (widthmz == null || widthmz.Length == 0)//如果每一列宽度未指定
            {
                widthmz = new float[datatable.Columns.Count];
                for (int i = 0; i < datatable.Columns.Count; i++)
                {
                    widthmz[i] = 30f;
                }
            }
            //初始化一个目标文档类
            Document document = new Document(PageSize.A4, 10, 10, 25, 25);
            //调用PDF的写入方法流
            //注意FileMode-Create表示如果目标文件不存在,则创建,如果已存在,则覆盖。
            PdfWriter writer = PdfWriter.getInstance(document, new FileStream(PDFFilePath, FileMode.Create));
            try
            {

                System.Windows.Media.Color color = (System.Windows.Media.Color)ColorConverter.ConvertFromString(brush.ToString());

                //打开目标文档对象
                document.Open();

                // 添加页眉
                HeaderFooter header = new HeaderFooter(new Phrase(PdfSaveTitle), false);
                document.Header = header;
                // 添加页脚
                HeaderFooter footer = new HeaderFooter(new Phrase(PdfSaveTitle), true);
                footer.Border = Rectangle.NO_BORDER;
                document.Footer = footer;

                //创建PDF文档中的字体
                BaseFont baseFont = BaseFont.createFont(@"C:\WINDOWS\Fonts\SIMFANG.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                //根据字体路径和字体大小属性创建字体
                Font font = new Font(baseFont, FontSize);
                font.setColor(color.R, color.G, color.B);

                Paragraph pTitle = new Paragraph(new Chunk(PdfSaveTitle, FontFactory.getFont(FontFactory.HELVETICA, 12)));
                document.Add(pTitle);

                //根据数据表内容创建一个PDF格式的表
                PdfPTable table = null;
                table = new PdfPTable(widthmz);

                //打印列名
                for (int j = 0; j < datatable.Columns.Count; j++)
                {
                    string ColumnName =datatable.Columns[j].ColumnName.ToString();
                    table.addCell(new Phrase(ColumnName, font));
                }

                //遍历原table的内容
                for (int i = 0; i < datatable.Rows.Count; i++)
                {
                    for (int j = 0; j < datatable.Columns.Count; j++)
                    {
                        table.addCell(new Phrase(datatable.Rows[i][j].ToString(), font));
                    }
                }
                //在目标文档中添加转化后的表数据

                document.Add(table);
            }
            catch (Exception ec)
            {
                ec.GetBaseException();
                return false;
            }
            finally
            {
                //关闭目标文件
                document.Close();
                //关闭写入流
                writer.Close();
            }
            return true;
        }
コード例 #27
0
ファイル: Relatorio.cs プロジェクト: aureliopires/gisa
 protected HeaderFooter getHeader(string text)
 {
     HeaderFooter header = null;
     if (text != null && text.Length > 0)
         header = new HeaderFooter(new Phrase(string.Format("{0} – {1}", "Gestão Integrada de Sistemas de Arquivo", text), PageHeaderFont), false);
     else
         header = new HeaderFooter(new Phrase("Gestão Integrada de Sistemas de Arquivo", PageHeaderFont), false);
     header.Alignment = Element.ALIGN_CENTER;
     header.Border = 2;
     header.BorderColor = PageHeaderFont.Color;
     return header;
 }
コード例 #28
0
ファイル: Common.cs プロジェクト: hungtien408/web-quanaotreem
        public void ExportPDF(string FileName, string FontName, string html, string header, string footer)
        {
            var page = HttpContext.Current.Handler as Page;

            //Init export
            page.Response.ContentType = "application/pdf";
            page.Response.AddHeader("content-disposition", "attachment;filename=" + FileName);
            page.Response.Cache.SetCacheability(HttpCacheability.NoCache);

            Document pdfDoc = new Document(PageSize.A4);
            PdfWriter.GetInstance(pdfDoc, page.Response.OutputStream);

            //Import Unicode Font
            BaseFont bF = BaseFont.CreateFont(HttpContext.Current.Server.MapPath("~/" + FontName), iTextSharp.text.pdf.BaseFont.IDENTITY_H, true);
            Font f = new Font(bF, 12f, Font.NORMAL);
            Font hdf = new Font(bF, 12f, Font.NORMAL, Color.GRAY);
            //End Import font

            //Create PDF header
            var headPhrase = new Phrase(header, hdf);
            var head = new HeaderFooter(headPhrase, false);
            head.BorderColor = Color.GRAY;
            //End

            //Create PDF footer
            var footPhrase = new Phrase(footer, hdf);
            var foot = new HeaderFooter(footPhrase, false);
            foot.BorderColor = Color.GRAY;
            //End

            pdfDoc.Header = head;
            pdfDoc.Footer = foot;

            pdfDoc.Open();
            ParseHtml(html, pdfDoc, f);
            pdfDoc.Close();
        }
コード例 #29
0
ファイル: RtfWriter.cs プロジェクト: hjgode/iTextSharpCF
 private void AddHeaderFooterFontColor(HeaderFooter hf)
 {
     if (hf is RtfHeaderFooter) {
         RtfHeaderFooter rhf = (RtfHeaderFooter) hf;
         if (rhf.Content() is Chunk) {
             AddFont(((Chunk) rhf.Content()).Font);
             AddColor(((Chunk) rhf.Content()).Font.Color);
         } else if (rhf.Content() is Phrase) {
             AddFont(((Phrase) rhf.Content()).Font);
             AddColor(((Phrase) rhf.Content()).Font.Color);
         }
     }
     if (hf.Before != null) {
         AddFont(hf.Before.Font);
         AddColor(hf.Before.Font.Color);
     }
     if (hf.After != null) {
         AddFont(hf.After.Font);
         AddColor(hf.After.Font.Color);
     }
 }
コード例 #30
0
ファイル: Document.cs プロジェクト: hjgode/iTextSharpCF
 /// <summary>
 /// Resets the header of this document.
 /// </summary>
 public virtual void ResetHeader()
 {
     this.header = null;
     foreach (IDocListener listener in listeners) {
         listener.ResetHeader();
     }
 }
コード例 #31
0
        public JsonResult pdfExport(int id)
        {
            Model.DTO.Appraisal.Appraisal appr = PMS.Model.PMSModel.GetAppraisalById(id);

            #region GetFilePath
            string fileName = appr.Employee.PreferredName + "'s Appraisal on " + DateTime.Now.ToString() + ".pdf";
               fileName = fileName.Replace("/", "-").Replace(":","-");

               string filePath = Path.Combine(Server.MapPath("~/PDFFiles"), fileName);
            #endregion

               string logoImgPath = Server.MapPath("~/Content/img/logo.gif");
               string CorevalueImg = Server.MapPath("~/Content/img/pms_corevalue_rating_description.jpg");
               Document doc = new Document(PageSize.A4, 2, 2, 10, 2);

               try
               {
               PdfWriter.GetInstance(doc, new FileStream(filePath, FileMode.Create));
               #region set headerfooter
               HeaderFooter header = new HeaderFooter(new Phrase("Asia Capital Reinsurance", FontFactory.GetFont("Arial", 6, Font.ITALIC)), false);
               header.Border = Rectangle.BOTTOM_BORDER;
               header.BorderColor = Color.GRAY;
               header.BorderWidth = 0.5f;
               header.Alignment = Rectangle.ALIGN_CENTER;
               doc.Header = header;

               HeaderFooter footer = new HeaderFooter(new Phrase("Page: ", FontFactory.GetFont("Arial", 6, Font.ITALIC)), true);
               footer.Border = Rectangle.TOP_BORDER;
               footer.BorderColor = Color.GRAY;
               footer.BorderWidth = 0.5f;
               footer.Alignment = Rectangle.ALIGN_CENTER;
               doc.Footer = footer;
               #endregion
               doc.Open();

               #region define helpercell
               Paragraph empty = new Paragraph("");
               PdfPCell emptycell = new PdfPCell(empty);
               #endregion

               #region writing logo and title
               Paragraph p1 = new Paragraph();
               Image jpg1 = Image.GetInstance(logoImgPath);
               jpg1.Alignment = Element.ALIGN_LEFT;
               p1.Add(jpg1);

               PdfPTable EmployInfoTable = new PdfPTable(4);
               EmployInfoTable.WidthPercentage = 80f;
               PdfPCell pCell = new PdfPCell(new Paragraph("Name: "));
               EmployInfoTable.AddCell(pCell);
               pCell = new PdfPCell(new Paragraph(appr.Employee.PreferredName));
               EmployInfoTable.AddCell(pCell);
               pCell = new PdfPCell(new Paragraph("ID: "));
               EmployInfoTable.AddCell(pCell);
               pCell = new PdfPCell(new Paragraph(appr.Employee.DomainId));
               EmployInfoTable.AddCell(pCell);
               pCell = new PdfPCell(new Paragraph("Department: "));
               EmployInfoTable.AddCell(pCell);
               pCell = new PdfPCell(new Paragraph(appr.Employee.Department.Name));
               EmployInfoTable.AddCell(pCell);
               pCell = new PdfPCell(new Paragraph("Employment Type: "));
               EmployInfoTable.AddCell(pCell);
               pCell = new PdfPCell(new Paragraph(appr.Employee.EmploymentType.Name));
               EmployInfoTable.AddCell(pCell);
               pCell = new PdfPCell(new Paragraph("ACR Grade: "));
               EmployInfoTable.AddCell(pCell);
               pCell = new PdfPCell(new Paragraph(appr.Employee.ACRGrade.Name));
               EmployInfoTable.AddCell(pCell);
               EmployInfoTable.AddCell(emptycell);
               EmployInfoTable.AddCell(emptycell);
               doc.Add(p1);
               doc.Add(EmployInfoTable);
               #endregion

               #region define table
               PdfPTable kpiTab = new PdfPTable(4);
               kpiTab.HorizontalAlignment = 1;
               kpiTab.SpacingBefore = 20f;
               kpiTab.SpacingAfter = 20f;

               PdfPTable corevaluesTab = new PdfPTable(2);
               corevaluesTab.HorizontalAlignment = 1;
               corevaluesTab.SpacingBefore = 20f;
               corevaluesTab.SpacingAfter = 20f;

               PdfPTable performanceCoachingTab = new PdfPTable(1);
               performanceCoachingTab.HorizontalAlignment = 1;
               performanceCoachingTab.SpacingBefore = 20f;
               performanceCoachingTab.SpacingAfter = 20f;

               PdfPTable careerDevelopmentTab = new PdfPTable(1);
               careerDevelopmentTab.HorizontalAlignment = 1;
               careerDevelopmentTab.SpacingBefore = 20f;
               careerDevelopmentTab.SpacingAfter = 20f;
               #endregion

               #region writing kpitable

               List<Model.DTO.Master.Section> sections = PMS.Model.PMSModel.GetMasterSectionList(true);

               List<Model.DTO.GradeCompetency> gcList = PMS.Model.PMSModel.GetCoreValueCompetencyByGrade(CurrentUser.ACRGrade.Id);
               Paragraph sectionName = new Paragraph(sections[0].Name+"\n"+"\n");

               PdfPTable descriptionTable=new PdfPTable(1);
               descriptionTable.WidthPercentage=90f;
               pCell = new PdfPCell(new Paragraph(sectionName));
               pCell.Border = Rectangle.NO_BORDER;
               descriptionTable.AddCell(pCell);
               string kpiDescription = "\n\n Key Performance Indicators Descriptions :\n"
                                        +"\n"
                                        +"\"Financials\", \"Build\", \"Governance/Risk\" and \"People\" are four main themes derived from the Corporate and Underwriting Principles that capture the corporate focus and priorities and serve to align individual's Key Performance Indicators (KPIs) to achieving the Corporate KPIs and Corporate Vision. KPIs are manually set goals and metrics that measure individual's achievements and progress."
                                       + "You will need to set at least 1 or more KPI within each of the four main themes."
                                       + "You are to complete the form and initiate discussion with your Manager."
                                       + "Once you have submitted the form to your Manager, your Manager will complete the relevant sections. All submissions and comments will be tracked.\n"
                                        +"\n"
                                        +"Performance Rating Descriptions :\n"
                                        +"\n"
                                        + "5 - Far Exceeds Expections (Exceptional/ Outstanding Performer)\n"
                                        + "4 - Exceeds Expectation (Strong Performer)\n"
                                        + "3 - Meets Expectation (Solid Performer)\n"
                                        + "2 - Improvements Needed (Under Performer)\n"
                                        + "1 - Poor/Does not meet expectation\n\n";
               pCell = new PdfPCell(new Paragraph(kpiDescription));
               pCell.BackgroundColor = new Color(70,136,71);
               descriptionTable.AddCell(pCell);

               doc.Add(descriptionTable);
               foreach (Model.DTO.Master.Block b in sections[0].Blocks)
               {
                   Paragraph blockName = new Paragraph("\n\n"+b.Name+"\n\n");
                   PdfPCell cell = new PdfPCell(blockName);
                   cell.BorderWidth=0;
                   cell.Colspan = 4;
                   kpiTab.AddCell(cell);
                   cell = new PdfPCell(new Paragraph("Key Performance Indicator"));
                   cell.BackgroundColor = new Color(91, 192, 222);
                   kpiTab.AddCell(cell);
                   cell = new PdfPCell(new Paragraph("Priority"));
                   cell.BackgroundColor = new Color(91, 192, 222);
                   kpiTab.AddCell(cell);
                   cell = new PdfPCell(new Paragraph("Performance Target"));
                   cell.BackgroundColor = new Color(91, 192, 222);
                   kpiTab.AddCell(cell);
                   cell = new PdfPCell(new Paragraph("Comments"));
                   cell.BackgroundColor = new Color(91, 192, 222);
                   kpiTab.AddCell(cell);

                   StringBuilder kpicommentsParagraph = new StringBuilder();
                   if (!Lib.Utility.Common.IsNullOrEmptyList(appr.KPIs))
                   {
                       foreach (Model.DTO.Appraisal.KPI k in appr.KPIs.Where(s => s.Block.Id == b.Id))
                       {
                           kpiTab.AddCell(k.Description.Replace(Environment.NewLine,"\n"));
                           kpiTab.AddCell(k.Priority.Name);
                           kpiTab.AddCell(k.Target.Replace(Environment.NewLine, "\n"));
                           if (!Lib.Utility.Common.IsNullOrEmptyList(k.Comments))
                           {
                               foreach (Model.DTO.Appraisal.KPIComment kc in k.Comments.Where(s => s.FormSaveOnly == false))
                               {
                                   kpicommentsParagraph.Append(kc.CommentedTimestamp + " , " + kc.Commentor.PreferredName + " said:\n");
                                   kpicommentsParagraph.Append("     " + kc.Comments.Replace(Environment.NewLine, "\n") + "\n");
                               }
                               kpiTab.AddCell(new Paragraph(kpicommentsParagraph.ToString()));
                           }
                           else
                               kpiTab.AddCell("");
                           //pdfTab.AddCell(k.c);
                       }
                   }
                   else
                   {
                       emptycell.FixedHeight = 80;
                       kpiTab.AddCell(emptycell);
                       kpiTab.AddCell(emptycell);
                       kpiTab.AddCell(emptycell);
                       kpiTab.AddCell(emptycell);
                   }
                   emptycell.FixedHeight = 80;
                   kpiTab.AddCell(emptycell);
                   kpiTab.AddCell(emptycell);
                   kpiTab.AddCell(emptycell);
                   kpiTab.AddCell(emptycell);
               }
               doc.Add(kpiTab);
               #endregion

               #region writing corevaluesTable
               sectionName = new Paragraph(sections[1].Name+"\n\n");
               descriptionTable = new PdfPTable(1);
               descriptionTable.WidthPercentage = 90f;
               pCell = new PdfPCell(new Paragraph(sectionName));
               pCell.Border = Rectangle.NO_BORDER;
               descriptionTable.AddCell(pCell);
               kpiDescription = "\n  ACR Core Values :" +
                                "\n" +
                                "  The ACR Core Values guides our behaviours, the way we conduct business and how we treat our clients and colleagues. Living the values is essential to creating and reinforcing our corporate values.\n" +
                                "\n" +
                                "  All Core Values (RIPPLES) must be evaluated for the year.\n" +
                                "\n" +
                                "  Core Value Ratings :\n" +
                                "\n\n";
               Paragraph corevaluesP = new Paragraph(kpiDescription);
               //Image corevaluejpg = Image.GetInstance(CorevalueImg);

               Image corevaluejpg = Image.GetInstance(CorevalueImg);
               corevaluejpg.ScaleAbsolute(230, 158);
               pCell = new PdfPCell(corevaluesP);
               pCell.BackgroundColor = new Color(70, 136, 71);
               descriptionTable.AddCell(pCell);
               PdfPCell pCell1 = new PdfPCell(corevaluejpg,false);
               pCell1.Border = Rectangle.NO_BORDER;
               //pCell1.BackgroundColor = new Color(70, 136, 71);
               descriptionTable.AddCell(pCell1);
               doc.Add(descriptionTable);
               foreach (Model.DTO.Master.Block b in sections[1].Blocks)
               {

                   Paragraph blockName = new Paragraph("\n\n"+b.Name+"\n\n");
                   PdfPCell cell = new PdfPCell(blockName);
                   cell.BorderWidth = 0;
                   cell.Colspan = 2;
                   corevaluesTab.AddCell(cell);
                   cell = new PdfPCell(new Paragraph("Core Competency:"));
                   cell.Colspan = 2;
                   corevaluesTab.AddCell(cell);
                   StringBuilder competency=new StringBuilder();
                   int index = 1;
                   foreach(Model.DTO.GradeCompetency gc in gcList.Where(rec => rec.Block.Id == b.Id))
                   {
                       competency.Append((index++).ToString()+". "+gc.Name+"\n\n");

                   }
                   cell = new PdfPCell(new Paragraph(competency.ToString()));
                   cell.Colspan = 2;
                   corevaluesTab.AddCell(cell);

                   cell = new PdfPCell(new Paragraph("Performance Target"));
                   cell.BackgroundColor = new Color(91, 192, 222);
                   corevaluesTab.AddCell(cell);

                   cell = new PdfPCell(new Paragraph("Comments"));
                   cell.BackgroundColor = new Color(91, 192, 222);
                   corevaluesTab.AddCell(cell);
                   StringBuilder corevaluecommentsParagraph = new StringBuilder();
                   if (!Lib.Utility.Common.IsNullOrEmptyList(appr.CoreValues))
                   {
                       foreach (Model.DTO.Appraisal.CoreValue k in appr.CoreValues.Where(s => s.Block.Id == b.Id))
                       {
                           corevaluesTab.AddCell(k.Target.Replace(Environment.NewLine, "\n"));
                           if (!Lib.Utility.Common.IsNullOrEmptyList(k.Comments))
                           {
                               foreach (Model.DTO.Appraisal.CoreValueComment kc in k.Comments.Where(s => s.FormSaveOnly == false))
                               {
                                   corevaluecommentsParagraph.Append(kc.CommentedTimestamp + " , " + kc.Commentor.PreferredName + " said:\n");
                                   corevaluecommentsParagraph.Append("     " + kc.Comments.Replace(Environment.NewLine, "\n") + "\n");
                               }
                               corevaluesTab.AddCell(new Paragraph(corevaluecommentsParagraph.ToString()));
                           }
                           else
                               corevaluesTab.AddCell("");
                           //pdfTab.AddCell(k.c);
                       }
                   }
                   else
                   {
                       emptycell.FixedHeight = 80;
                       corevaluesTab.AddCell(emptycell);
                       corevaluesTab.AddCell(emptycell);
                   }
                   emptycell.FixedHeight = 80;
                   corevaluesTab.AddCell(emptycell);
                   corevaluesTab.AddCell(emptycell);
                   corevaluesTab.AddCell(emptycell);
                   corevaluesTab.AddCell(emptycell);
               }
               doc.Add(corevaluesTab);
               #endregion

               #region writing performancecoaching
               if (sections.Count > 2)
               {
                   sectionName = new Paragraph(sections[2].Name+"\n\n");
                   pCell = new PdfPCell(new Paragraph(sectionName));
                   pCell.Border = Rectangle.NO_BORDER;
                   performanceCoachingTab.AddCell(pCell);
                   Paragraph content = new Paragraph("Employee's areas of strengths:");
                   PdfPCell cell = new PdfPCell(content);
                   cell.BackgroundColor = new Color(91, 192, 222);
                   performanceCoachingTab.AddCell(cell);
                   if (!eHR.PMS.Lib.Utility.Common.IsNullOrEmptyList(appr.PerformanceCoachings))
                   {
                       cell = new PdfPCell(new Paragraph(appr.PerformanceCoachings.First().AreasOfStrength.Replace(Environment.NewLine, "\n")));
                       performanceCoachingTab.AddCell(cell);
                   }
                   else
                   {
                       emptycell.FixedHeight = 80;
                       performanceCoachingTab.AddCell(emptycell);
                   }
                   content = new Paragraph("Employee's areas for improvements and developmental needs");
                   cell = new PdfPCell(content);
                   cell.BackgroundColor = new Color(91, 192, 222);
                   performanceCoachingTab.AddCell(cell);
                   if (!eHR.PMS.Lib.Utility.Common.IsNullOrEmptyList(appr.PerformanceCoachings))
                   {
                       cell = new PdfPCell(new Paragraph(appr.PerformanceCoachings.First().AreasOfImprovement.Replace(Environment.NewLine, "\n")));
                       performanceCoachingTab.AddCell(cell);
                   }
                   else
                   {
                       emptycell.FixedHeight = 80;
                       performanceCoachingTab.AddCell(emptycell);
                   }
                   content = new Paragraph("Comments");
                   cell = new PdfPCell(content);
                   cell.BackgroundColor = new Color(91, 192, 222);
                   performanceCoachingTab.AddCell(cell);

                   StringBuilder performanceCoachingcommentsParagraph = new StringBuilder();
                   if (!eHR.PMS.Lib.Utility.Common.IsNullOrEmptyList(appr.PerformanceCoachings) && !eHR.PMS.Lib.Utility.Common.IsNullOrEmptyList(appr.PerformanceCoachings.First().Comments))
                   {
                       foreach (Model.DTO.Appraisal.PerformanceCoachingComment kc in appr.PerformanceCoachings.First().Comments.Where(s => s.FormSaveOnly == false))
                       {
                           performanceCoachingcommentsParagraph.Append(kc.CommentedTimestamp + " , " + kc.Commentor.PreferredName + " said:\n");
                           performanceCoachingcommentsParagraph.Append("     " + kc.Comments.Replace(Environment.NewLine, "\n") + "\n");
                       }
                       performanceCoachingTab.AddCell(new Paragraph(performanceCoachingcommentsParagraph.ToString()));
                   }
                   else
                   {
                       emptycell.FixedHeight = 80;
                       performanceCoachingTab.AddCell(emptycell);
                   }
                   doc.Add(performanceCoachingTab);
               }
               #endregion

               #region writing careerdevelopment
               if (sections.Count > 3)
               {
                   sectionName = new Paragraph(sections[3].Name+"\n\n");
                   pCell = new PdfPCell(new Paragraph(sectionName));
                   pCell.Border = Rectangle.NO_BORDER;
                   careerDevelopmentTab.AddCell(pCell);
                   Paragraph content = new Paragraph("Short-term Career Goals:");
                   PdfPCell cell = new PdfPCell(content);
                   cell.BackgroundColor = new Color(91, 192, 222);
                   careerDevelopmentTab.AddCell(cell);
                   if (!eHR.PMS.Lib.Utility.Common.IsNullOrEmptyList(appr.CareerDevelopments))
                   {
                       cell = new PdfPCell(new Paragraph(appr.CareerDevelopments.First().ShortTermGoals.Replace(Environment.NewLine, "\n")));
                       careerDevelopmentTab.AddCell(cell);
                   }
                   else
                   {
                       emptycell.FixedHeight = 80;
                       careerDevelopmentTab.AddCell(emptycell);
                   }
                   content = new Paragraph("Career Development Plan:");
                   cell = new PdfPCell(content);
                   cell.BackgroundColor = new Color(91, 192, 222);
                   careerDevelopmentTab.AddCell(cell);
                   if (!eHR.PMS.Lib.Utility.Common.IsNullOrEmptyList(appr.CareerDevelopments))
                   {
                       cell = new PdfPCell(new Paragraph(appr.CareerDevelopments.First().CareerPlans.Replace(Environment.NewLine, "\n")));
                       careerDevelopmentTab.AddCell(cell);
                   }
                   else
                   {
                       emptycell.FixedHeight = 80;
                       careerDevelopmentTab.AddCell(emptycell);
                   }
                   content = new Paragraph("Learning and development:");
                   cell = new PdfPCell(content);
                   cell.BackgroundColor = new Color(91, 192, 222);
                   careerDevelopmentTab.AddCell(cell);
                   if (!eHR.PMS.Lib.Utility.Common.IsNullOrEmptyList(appr.CareerDevelopments))
                   {
                       cell = new PdfPCell(new Paragraph(appr.CareerDevelopments.First().LearningPlans.Replace(Environment.NewLine, "\n")));
                       careerDevelopmentTab.AddCell(cell);
                   }
                   else
                   {
                       emptycell.FixedHeight = 80;
                       careerDevelopmentTab.AddCell(emptycell);
                   }
                   content = new Paragraph("Comments");
                   cell = new PdfPCell(content);
                   cell.BackgroundColor = new Color(91, 192, 222);
                   careerDevelopmentTab.AddCell(cell);
                   StringBuilder careerDevelopmentcommentsParagraph = new StringBuilder();
                   if (!eHR.PMS.Lib.Utility.Common.IsNullOrEmptyList(appr.CareerDevelopments) && !eHR.PMS.Lib.Utility.Common.IsNullOrEmptyList(appr.CareerDevelopments.First().Comments))
                   {
                       foreach (Model.DTO.Appraisal.CareerDevelopmentComment kc in appr.CareerDevelopments.First().Comments.Where(s => s.FormSaveOnly == false))
                       {
                           careerDevelopmentcommentsParagraph.Append(kc.CommentedTimestamp + " , " + kc.Commentor.PreferredName + " said:\n");
                           careerDevelopmentcommentsParagraph.Append("     " + kc.Comments.Replace(Environment.NewLine, "\n") + "\n");
                       }
                       careerDevelopmentTab.AddCell(new Paragraph(careerDevelopmentcommentsParagraph.ToString()));
                   }
                   else
                   {
                       emptycell.FixedHeight = 80;
                       careerDevelopmentTab.AddCell(emptycell);
                   }
                   doc.Add(careerDevelopmentTab);
               }
               #endregion

               doc.Close();
               return Json(fileName);
               //return File(filePath, "application/pdf", fileName);
               }
               catch (Exception)
               {
               throw;
               }
               finally
               {
               doc.Close();
               }
        }
            public void OnEndPage(PdfWriter writer, Document document)
            {
                //if (document.PageNumber > 1)
                //    document.Header = null;

                HeaderFooter rodape;
                StringBuilder texto = new StringBuilder();

                texto.AppendLine(String.Concat("Impressão em: ", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")));

                rodape = new HeaderFooter(new Phrase(texto.ToString() + " página :" + (document.PageNumber + 1 ), font4), false);
                rodape.Border = HeaderFooter.NO_BORDER;
                rodape.Alignment = HeaderFooter.ALIGN_RIGHT;

                document.Footer = rodape;
            }
コード例 #33
0
 // ---------------------------------------------------------------------------
 public void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document(PageSize.A4, 36, 36, 54, 54))
     {
         // step 2
         PdfWriter writer = PdfWriter.GetInstance(document, stream);
         HeaderFooter tevent = new HeaderFooter();
         writer.SetBoxSize("art", new Rectangle(36, 54, 559, 788));
         writer.PageEvent = tevent;
         // step 3
         document.Open();
         // step 4
         int epoch = -1;
         int currentYear = 0;
         Paragraph title = null;
         iTextSharp.text.Chapter chapter = null;
         Section section = null;
         Section subsection = null;
         // add the chapters, sort by year
         foreach (Movie movie in PojoFactory.GetMovies(true))
         {
             int year = movie.Year;
             if (epoch < (year - 1940) / 10)
             {
                 epoch = (year - 1940) / 10;
                 if (chapter != null)
                 {
                     document.Add(chapter);
                 }
                 title = new Paragraph(EPOCH[epoch], FONT[0]);
                 chapter = new iTextSharp.text.Chapter(title, epoch + 1);
             }
             if (currentYear < year)
             {
                 currentYear = year;
                 title = new Paragraph(
                   String.Format("The year {0}", year), FONT[1]
                 );
                 section = chapter.AddSection(title);
                 section.BookmarkTitle = year.ToString();
                 section.Indentation = 30;
                 section.BookmarkOpen = false;
                 section.NumberStyle = Section.NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT;
                 section.Add(new Paragraph(
                   String.Format("Movies from the year {0}:", year))
                 );
             }
             title = new Paragraph(movie.MovieTitle, FONT[2]);
             subsection = section.AddSection(title);
             subsection.IndentationLeft = 20;
             subsection.NumberDepth = 1;
             subsection.Add(new Paragraph(
               "Duration: " + movie.Duration.ToString(), FONT[3]
             ));
             subsection.Add(new Paragraph("Director(s):", FONT[3]));
             subsection.Add(PojoToElementFactory.GetDirectorList(movie));
             subsection.Add(new Paragraph("Countries:", FONT[3]));
             subsection.Add(PojoToElementFactory.GetCountryList(movie));
         }
         document.Add(chapter);
     }
 }
コード例 #34
-26
ファイル: Relatorio.cs プロジェクト: aureliopires/gisa
 protected HeaderFooter getFooter(string text)
 {
     HeaderFooter footer = new HeaderFooter(new Phrase(" ", PageFooterFont), true);
     //Câmara Municipal do Porto - Departamento de Arquivos -
     footer.Alignment = Element.ALIGN_LEFT;
     footer.Border = 1;
     footer.BorderColor = PageFooterFont.Color;
     return footer;
 }