// we override the onEndPage method
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            _lastPageNumber++;

            int    pageN = _lastPageNumber;
            string text  = "Page " + pageN.ToString() + " of ";
            float  len   = _bf.GetWidthPoint(text, 8);

            _cb.BeginText();
            _cb.SetFontAndSize(_bf, 8);
            _cb.SetTextMatrix(280, 30);
            _cb.ShowText(text);
            _cb.EndText();
            _cb.AddTemplate(_template, 280 + len, 30);

            if (_lastShid != _shid)
            {
                // close out the last section of pages
                _template.BeginText();
                _template.SetFontAndSize(_bf, 8);
                _template.ShowText((_lastPageNumber).ToString());
                _template.EndText();
            }

            base.OnEndPage(writer, document);
        }
Beispiel #2
0
        public override void OnCloseDocument(PdfWriter writer, Document document)
        {
            base.OnCloseDocument(writer, document);

            template.BeginText();
            template.SetFontAndSize(BF_Light, ContentFontSize);
            template.SetTextMatrix(0, 0);
            template.ShowText("" + (CurrentPage.ToString()));
            template.EndText();
        }
 public override void OnCloseDocument(PdfWriter writer, iTextSharp.text.Document document)
 {
     template.BeginText();
     template.SetFontAndSize(footerBaseFont, 8);
     template.ShowText((writer.PageNumber - 1).ToString());
     template.EndText();
 }
Beispiel #4
0
 public override void OnCloseDocument(PdfWriter writer, Document document)
 {
     template.BeginText();
     template.SetFontAndSize(bf, 8);
     template.ShowText((writer.PageNumber - 1).ToString());
     template.EndText();
 }
Beispiel #5
0
// ---------------------------------------------------------------------------

        /**
         * Generates a PDF file with the text 'Hello World'
         */
        public byte[] CreatePdf()
        {
            using (MemoryStream ms = new MemoryStream()) {
                using (Document document = new Document()) {
                    // step 2
                    PdfWriter writer = PdfWriter.GetInstance(document, ms);
                    // step 3
                    document.Open();
                    // step 4
                    // we add the text to the direct content, but not in the right order
                    PdfContentByte cb = writer.DirectContent;
                    BaseFont       bf = BaseFont.CreateFont();
                    cb.BeginText();
                    cb.SetFontAndSize(bf, 12);
                    cb.MoveText(88.66f, 367);
                    cb.ShowText("ld");
                    cb.MoveText(-22f, 0);
                    cb.ShowText("Wor");
                    cb.MoveText(-15.33f, 0);
                    cb.ShowText("llo");
                    cb.MoveText(-15.33f, 0);
                    cb.ShowText("He");
                    cb.EndText();
                    // we also add text in a form XObject
                    PdfTemplate tmp = cb.CreateTemplate(250, 25);
                    tmp.BeginText();
                    tmp.SetFontAndSize(bf, 12);
                    tmp.MoveText(0, 7);
                    tmp.ShowText("Hello People");
                    tmp.EndText();
                    cb.AddTemplate(tmp, 36, 343);
                }
                return(ms.ToArray());
            }
        }
Beispiel #6
0
 public void OnCloseDocument(PdfWriter writer, Document document)
 {
     _tm.BeginText();
     _tm.SetFontAndSize(_bf, 10.5f);
     _tm.ShowText((writer.PageNumber - 1).ToString());
     _tm.EndText();
 }
 void IPdfPageEvent.OnCloseDocument(PdfWriter writer, Document document)
 {
     m_template.BeginText();
     m_template.SetFontAndSize(m_bf, 8);
     m_template.ShowText((writer.PageNumber - 1).ToString());
     m_template.EndText();
 }
Beispiel #8
0
        private void ImagemRodape(PdfWriter writer, int numberPage)
        {
            BaseFont       f_tr   = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            PdfContentByte canvas = writer.DirectContent;

            //Classe do ItextSharp para instânciar uma imagem
            Image image1 = Image.GetInstance("..\\..\\Imagens\\imagem1.png");

            image1.SetAbsolutePosition(40, 1); //Horizontal, vertical
            image1.ScaleAbsoluteHeight(60);
            image1.ScaleAbsoluteWidth(60);

            canvas.AddImage(image1);

            //Linha
            canvas.MoveTo(40, 60);
            canvas.LineTo(575, 60);
            canvas.SetLineWidth(2);
            canvas.Stroke();

            //Rodapé
            PdfTemplate tmpFooter = canvas.CreateTemplate(540, 70);

            canvas.AddTemplate(tmpFooter, 50, 1);
            tmpFooter.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, false), 5);
            tmpFooter.BeginText();
            tmpFooter.SetFontAndSize(f_tr, 8);
            tmpFooter.ShowTextAligned(1, "TextoTextoTextoTextoTextoTextoTextoTexto", 240, 30, 0);
            tmpFooter.ShowTextAligned(2, string.Format("Página {0}", numberPage), 520, 10, 0);
            tmpFooter.EndText();
        }
        private byte[] CreatePdfWithXObject(String xobjectText)
        {
            MemoryStream baos   = new MemoryStream();
            Document     doc    = new Document();
            PdfWriter    writer = PdfWriter.GetInstance(doc, baos);

            writer.CompressionLevel = 0;
            doc.Open();

            doc.Add(new Paragraph("A"));
            doc.Add(new Paragraph("B"));

            PdfTemplate template = writer.DirectContent.CreateTemplate(100, 100);

            template.BeginText();
            template.SetFontAndSize(BaseFont.CreateFont(), 12);
            template.MoveText(5, template.Height - 5);
            template.ShowText(xobjectText);
            template.EndText();

            Image xobjectImage = Image.GetInstance(template);

            doc.Add(xobjectImage);

            doc.Add(new Paragraph("C"));

            doc.Close();

            return(baos.ToArray());
        }
        public override void OnCloseDocument(PdfWriter writer, Document document)
        {
            try
            {
                base.OnCloseDocument(writer, document);

                headerTemplate.BeginText();
                headerTemplate.SetFontAndSize(bf, 12);
                headerTemplate.SetTextMatrix(0, 0);
                headerTemplate.ShowText((writer.PageNumber).ToString());
                headerTemplate.EndText();

                //footerTemplate.BeginText();
                //footerTemplate.SetFontAndSize(bf, 12);
                //footerTemplate.SetTextMatrix(0, 0);
                //footerTemplate.ShowText((writer.PageNumber).ToString());
                //footerTemplate.EndText();
            }
            catch (DocumentException de)
            {
                Console.WriteLine(de.Message);
            }
            catch (System.IO.IOException io)
            {
                Console.WriteLine(io.Message);
            }
        }
Beispiel #11
0
        public override void OnCloseDocument(PdfWriter writer, Document document)
        {
            base.OnCloseDocument(writer, document);

            if (hasHeader)
            {
                headerTemplate.BeginText();
                headerTemplate.SetTextMatrix(0, 0);

                if (NumberSettings == PageNumbers.HeaderPlacement)
                {
                }

                headerTemplate.EndText();
            }

            if (hasFooter)
            {
                footerTemplate.BeginText();
                footerTemplate.SetTextMatrix(0, 0);

                if (NumberSettings == PageNumbers.FooterPlacement)
                {
                }

                footerTemplate.EndText();
            }
        }
Beispiel #12
0
        private void ShowText(PdfContentByte cb, float x, float y, float xPrevious, float yPrevious, double xmidden, double ymidden, String character)
        {
            double corner = CalculateCorner(x, y, xPrevious, yPrevious);

            cb.SaveState();
            PdfTemplate template2 = cb.CreateTemplate(1000, 1000);

            template2.BeginText();
            template2.SetColorFill(BaseColor.BLACK);
            BaseFont bf = BaseFont.CreateFont();

            template2.SetFontAndSize(bf, fontsize);
            //template2.SetTextRise(10);
            //double halfWidthOfCharacter = cb.GetEffectiveStringWidth(character+"", true) / 2.0;
            template2.SetTextMatrix(0, 0);
            template2.ShowText(character + "");
            template2.EndText();
            Matrix translation = new Matrix();

            translation.Translate((float)xmidden, (float)ymidden);
            cb.ConcatCTM(translation);
            Matrix rotation = new Matrix();

            rotation.Rotate((float)corner);
            cb.ConcatCTM(rotation);
            cb.ConcatCTM(1, 0, 0, -1, 0, 0);
            cb.AddTemplate(template2, 0, 0);
            cb.RestoreState();
        }
 //关闭PDF文档时
 public override void OnCloseDocument(PdfWriter writer, Document document)
 {
     tpl.BeginText();
     tpl.SetFontAndSize(bfYaHei, 10);    //生成的模版的字体、颜色
     tpl.ShowText(PageCount.ToString()); //模版显示的内容
     tpl.EndText();
     tpl.ClosePath();
 }
 public override void OnCloseDocument(PdfWriter writer, Document document)
 {
     tpPag.BeginText();
     tpPag.SetFontAndSize(helv, 10);
     tpPag.SetTextMatrix(0, 0);
     tpPag.ShowText("" + (Total - 1));
     tpPag.EndText();
 }
 public void ClosingDocument(PdfWriter writer, Document document, IList <SummaryCellData> columnCellsSummaryData)
 {
     _template.BeginText();
     _template.SetFontAndSize(_pdfRptFont.Fonts[0].BaseFont, 8);
     _template.SetTextMatrix(0, 0);
     _template.ShowText((writer.PageNumber - 1).ToString());
     _template.EndText();
 }
Beispiel #16
0
 /*
  * public override void OnEndPage(PdfWriter writer, Document document)
  * {
  *  base.OnEndPage(writer, document);
  *  int pageN = writer.PageNumber;
  *  String text = "Page " + pageN + " of " + writer.PageNumber;
  *  Rectangle pagesize = document.PageSize;
  *  cb.BeginText();
  *  cb.SetFontAndSize(bf, 10);
  *  cb.SetTextMatrix(pagesize.GetLeft(40), pagesize.GetBottom(30));
  *  cb.ShowText(text);
  *  cb.AddTemplate(template, pagesize.GetLeft(40), pagesize.GetBottom(30));
  *  cb.EndText();
  *  //cb.AddTemplate(template, pagesize.GetLeft(40), pagesize.GetBottom(30));
  * }*/
 public override void OnCloseDocument(PdfWriter writer, Document document)
 {
     base.OnCloseDocument(writer, document);
     template.BeginText();
     //template.SetFontAndSize(bf, 10);
     //template.ShowText("" + (writer.PageNumber));
     template.EndText();
 }
Beispiel #17
0
        /// <summary> /// 关闭PDF文档时发生该事件 /// </summary>
        public override void OnCloseDocument(PdfWriter writer, Document document)
        {
            BaseFont bf = BaseFontAndSize(HeaderFooterFontName);

            tpl.BeginText(); tpl.SetFontAndSize(bf, HeaderFooterFontSize);
            tpl.ShowText((writer.PageNumber - 1).ToString());
            //总页数 tpl.EndText(); tpl.ClosePath();
        }
Beispiel #18
0
 private void setFinalPageNumber(PdfWriter writer)
 {
     _totalPageCountTemplate.BeginText();
     _totalPageCountTemplate.SetFontAndSize(_pdfRptFont.Fonts[0].BaseFont, 8);
     _totalPageCountTemplate.SetTextMatrix(0, 0);
     _totalPageCountTemplate.ShowText("" + (writer.CurrentPageNumber - 1));
     _totalPageCountTemplate.EndText();
 }
Beispiel #19
0
 public override void OnCloseDocument(PdfWriter writer, Document document)
 {
     tpl.BeginText();
     tpl.SetFontAndSize(font, 8);
     tpl.ShowText((writer.PageNumber - 1).ToString());
     tpl.EndText();
     base.OnCloseDocument(writer, document);
 }
 public override void OnCloseDocument(PdfWriter writer, iTextSharp.text.Document document)
 {
     template.BeginText();
     template.SetFontAndSize(footerBaseFont, 8);
     template.SetTextMatrix(0, 0);
     template.ShowText(string.Format("{0}", (writer.PageNumber - 1)));
     template.EndText();
 }
Beispiel #21
0
 public override void OnCloseDocument(PdfWriter writer, Document document)
 {
     //ColumnText.ShowTextAligned(templateNumPage, Element.ALIGN_LEFT, new Phrase((writer.PageNumber - 1).ToString()), 0, (document.BottomMargin + 10), 0);
     templateNumPage.BeginText();
     templateNumPage.SetFontAndSize(bf, 8);
     templateNumPage.SetTextMatrix(0, 0);
     templateNumPage.ShowText("" + (writer.PageNumber - 1));
     templateNumPage.EndText();
 }
Beispiel #22
0
 public override void OnCloseDocument(PdfWriter writer, Document document)
 {
     base.OnEndPage(writer, document);
     pdfTemplate.BeginText();
     pdfTemplate.SetFontAndSize(baseFont, 8);
     pdfTemplate.SetTextMatrix(0, 0);
     pdfTemplate.ShowText("" + (writer.PageNumber - 1));
     pdfTemplate.EndText();
 }
Beispiel #23
0
 public override void OnCloseDocument(PdfWriter writer, Document document)
 {
     base.OnCloseDocument(writer, document);
     template.BeginText();
     template.SetFontAndSize(BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1250, BaseFont.NOT_EMBEDDED), 12);
     template.SetTextMatrix(0, 0);
     //template.ShowText("" + (writer.PageNumber - 1));
     template.EndText();
 }
Beispiel #24
0
 //关闭PDF文档时发生该事件
 public override void OnCloseDocument(PdfWriter writer, Document document)
 {
     //BaseFont bf = BaseFont.CreateFont(Path.GetDirectoryName(Application.ExecutablePath) + "\\Fonts\\msyh.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
     tpl.BeginText();
     //tpl.SetFontAndSize(, 16); //生成的模版的字体、颜色
     //tpl.ShowText((writer.PageNumber - 2).ToString()); //模版显示的内容
     tpl.EndText();
     tpl.ClosePath();
 }
Beispiel #25
0
        public override void OnCloseDocument(PdfWriter myPDFWriter, Document document)
        {
            base.OnCloseDocument(myPDFWriter, document);

            if (informe)
            {
                template.BeginText();

                template.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false), 8);
                template.SetTextMatrix(0, 0);
                template.ShowText("" + (myPDFWriter.PageNumber));
                template.EndText();
            }

            if (traza)
            {
                template.BeginText();

                template.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false), 8);
                template.SetTextMatrix(0, 0);
                template.ShowText("" + (myPDFWriter.PageNumber));
                template.EndText();
            }

            if (arfd)
            {
                template.BeginText();

                template.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false), 8);
                template.SetTextMatrix(0, 0);
                template.ShowText("" + (myPDFWriter.PageNumber));
                template.EndText();
            }

            if (lmr)
            {
                template.BeginText();

                template.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false), 8);
                template.SetTextMatrix(0, 0);
                template.ShowText("" + (myPDFWriter.PageNumber));
                template.EndText();
            }
        }
Beispiel #26
0
            /// <summary>
            /// 设置标题
            /// </summary>
            /// <param name="writer"></param>
            public void CreateHeaderFooterTemplate(PdfWriter writer)
            {
                #region 标题
                var tempHeader = writer.DirectContent.CreateTemplate(300, 50);
                tempHeader.BeginText();

                tempHeader.SetFontAndSize(BfFont, 10);
                tempHeader.SetTextMatrix(0, 10);
                tempHeader.ShowText(TableTitle.Title);
                tempHeader.EndText();
                writer.DirectContent.AddTemplate(tempHeader, PageSize.Width * 0.4f, PageSize.Height - 50);
                #endregion

                #region 左边查询文档
                if (TableTitle.SearchList != null && TableTitle.SearchList.Count > 0)
                {
                    int length   = TableTitle.SearchList.Count * 10;
                    var tempLeft = writer.DirectContent.CreateTemplate(PageSize.Width - 80, length);
                    tempLeft.BeginText();
                    tempLeft.SetFontAndSize(BfFont, 8);
                    foreach (var str in TableTitle.SearchList)
                    {
                        length = length - 10;
                        tempLeft.SetTextMatrix(0, length);
                        tempLeft.ShowText(str.Key + ":" + str.Value.ToString());
                    }
                    tempLeft.EndText();
                    writer.DirectContent.AddTemplate(tempLeft, 10, PageSize.Height - 100);
                }
                #endregion

                #region 右边时间显示文档
                var tempRight = writer.DirectContent.CreateTemplate(80, 30);
                tempRight.BeginText();

                tempRight.SetFontAndSize(BfFont, 8);
                tempRight.SetTextMatrix(0, 20);
                tempRight.ShowText("PageNumber:" + writer.CurrentPageNumber.ToString());
                tempRight.SetTextMatrix(0, 10);
                tempRight.ShowText("Run Date:" + TableTitle.RunTime.ToString("yyyy-MM-dd"));
                tempRight.SetTextMatrix(0, 0);
                tempRight.ShowText("Run Time:" + TableTitle.RunTime.ToString("HH:mm:ss"));
                tempRight.EndText();
                writer.DirectContent.AddTemplate(tempRight, PageSize.Width - 100, PageSize.Height - 100);
                #endregion

                #region 尾部
                PdfTemplate template = writer.DirectContent.CreateTemplate(500, 50);
                template.BeginText();
                template.SetFontAndSize(BfFont, 9);
                template.SetTextMatrix(10, 10);
                template.ShowText("提交人签字________________核对人签字_____________审批人签字____________________");
                template.EndText();
                writer.DirectContent.AddTemplate(template, 100, 10);
                #endregion
            }
Beispiel #27
0
        public override void OnCloseDocument(PdfWriter writer, Document document)
        {
            base.OnCloseDocument(writer, document);

            _pageNumberTemplate.BeginText();
            _pageNumberTemplate.SetFontAndSize(_baseFont, 8);
            _pageNumberTemplate.SetTextMatrix(0, 0);
            _pageNumberTemplate.ShowText(string.Empty + (writer.PageNumber - 1));
            _pageNumberTemplate.EndText();
        }
Beispiel #28
0
 public override void OnCloseDocument(PdfWriter writer, Document document)
 {
     base.OnCloseDocument(writer, document);
     BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
     template.BeginText();
     template.SetFontAndSize(bf, 10);
     template.SetTextMatrix(0, 0);
     template.ShowText("" + (writer.PageNumber - 1));
     template.EndText();
 }
Beispiel #29
0
        public override void OnCloseDocument(PdfWriter writer, Document document)
        {
            base.OnCloseDocument(writer, document);

            footer.BeginText();
            footer.SetFontAndSize(footer_font, footer_font_size);
            footer.SetTextMatrix(0, 0);
            footer.ShowText(writer.PageNumber.ToString());
            footer.EndText();
        }
Beispiel #30
0
        public override void OnCloseDocument(PdfWriter writer, Document document)
        {
            base.OnCloseDocument(writer, document);

            template.BeginText();
            template.SetFontAndSize(bf, 8);
            template.SetTextMatrix(0, 0);
            template.ShowText("" + (writer.PageNumber - 1)); // esto añade el numero total de paginas ....
            template.EndText();
        }