當前位置: 首頁>>代碼示例>>C#>>正文


C# PdfContentByte.AddTemplate方法代碼示例

本文整理匯總了C#中iTextSharp.text.pdf.PdfContentByte.AddTemplate方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfContentByte.AddTemplate方法的具體用法?C# PdfContentByte.AddTemplate怎麽用?C# PdfContentByte.AddTemplate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在iTextSharp.text.pdf.PdfContentByte的用法示例。


在下文中一共展示了PdfContentByte.AddTemplate方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: OnEndPage

        public override void OnEndPage(PdfWriter writer, Document document)
        {
            base.OnEndPage(writer, document);

            if (_isLastPage)
            {
                var relativeWidths = ColumnsHelper.GetRelativeColumnsForProducts(PageSize.A4);

                //RODAPE
                var pdfTableFooter = new BuilderTable().Create(relativeWidths).Standard();
                pdfTableFooter.AddCell(new BuilderCell("", 5).Create("DADOS ADICIONAIS").FixedHeight(15).Bold().HorizontalLeft().VerticalBottom().Colspan(42).NoBorder().BorderBuilder(false, false, false, false).Standard());

                pdfTableFooter.AddCell(new BuilderCell("", 5).Create("INFORMAÇÕES COMPLEMENTARES").FixedHeight(5).Bold().HorizontalLeft().VerticalTop().Colspan(32).NoBorder().BorderBuilder(true, true, false, true).Standard());
                pdfTableFooter.AddCell(new BuilderCell("", 5).Create("RESERVADO AO FISCO").Bold().HorizontalLeft().VerticalTop().Colspan(10).NoBorder().BorderBuilder(true, true, false, true).Standard());

                var infAdicional = _nfe.NFe.infNFe.infAdic;
                pdfTableFooter.AddCell(new BuilderCell("", 5).Create(infAdicional.infCpl).FixedHeight(25).HorizontalLeft().VerticalTop().Colspan(32).NoBorder().BorderBuilder(true, true, false, false).Standard());
                pdfTableFooter.AddCell(new BuilderCell("", 5).Create(" ").HorizontalLeft().VerticalTop().Colspan(10).NoBorder().BorderBuilder(true, true, false, false).Standard());

                if (_isHomolog)
                {
                    pdfTableFooter.AddCell(new BuilderCell("", 5).Create("SEM VALOR FISCAL").FixedHeight(5).HorizontalLeft().VerticalTop().Colspan(32).NoBorder().BorderBuilder(true, true, true, false).Standard());
                    pdfTableFooter.AddCell(new BuilderCell("", 5).Create(" ").HorizontalLeft().VerticalTop().Colspan(10).NoBorder().BorderBuilder(true, true, true, false).Standard());
                }

                document.Add(pdfTableFooter);
            }

            const float posX = 325f;
            const float posY = 662f;

            var pageN = writer.PageNumber;
            var text = "Folha " + pageN + "/";
            var len = _baseFont.GetWidthPoint(text, 8);

            _pdfContent = writer.DirectContent;
            _pdfContent.SetRGBColorFill(100, 100, 100);
            _pdfContent.BeginText();
            _pdfContent.SetFontAndSize(_baseFont, 8f);
            _pdfContent.SetTextMatrix(posX, posY);
            _pdfContent.ShowText(text);
            _pdfContent.EndText();
            _pdfContent.AddTemplate(_pageNumberTemplate, posX + len, posY);
            _pdfContent.BeginText();
            _pdfContent.SetFontAndSize(_baseFont, 8f);
            _pdfContent.EndText();
        }
開發者ID:spltechnology,項目名稱:spldanfe,代碼行數:47,代碼來源:DanfeHeader.cs

示例2: PdfGraphics

 internal PdfGraphics(string filename, int width, int height)
 {
     originalWidth = currentWidth = width;
     originalHeight = currentHeight = height;
     document = new Document(new iTextSharp.text.Rectangle(width, height), 50, 50, 50, 50);
     document.AddAuthor("");
     document.AddSubject("");
     try{
         writer = PdfWriter.GetInstance(document, new FileStream(filename, FileMode.Create));
         document.Open();
         content = writer.DirectContent;
         template = topTemplate = content.CreateTemplate(width, height);
         content.AddTemplate(template, 0, 0);
     } catch (DocumentException de){
         throw new IOException(de.Message);
     }
 }
開發者ID:neuhauser,項目名稱:compbio-base,代碼行數:17,代碼來源:PdfGraphics.cs

示例3: PdfGraphics

 public PdfGraphics(Stream stream, int width, int height)
 {
     originalWidth = currentWidth = width;
     originalHeight = currentHeight = height;
     document = new Document(new Rectangle(width, height), 50, 50, 50, 50);
     document.AddAuthor("");
     document.AddSubject("");
     try{
         writer = PdfWriter.GetInstance(document, stream);
         document.Open();
         content = writer.DirectContent;
         template = topTemplate = content.CreateTemplate(width, height);
         content.AddTemplate(template, 0, 0);
     } catch (DocumentException de){
         throw new IOException(de.Message);
     }
 }
開發者ID:JurgenCox,項目名稱:compbio-base,代碼行數:17,代碼來源:PdfGraphics.cs

示例4: FooterPdfInitialize

        private static void FooterPdfInitialize(PdfWriter writer, Document document, PdfTemplate template, PdfContentByte contentByte, BaseFont baseFont, DateTime PrintTime)
        {
            int pageNumber = writer.PageNumber;
            string footerText = string.Format("Strona {0}{1}", pageNumber, " z ");
            float lenght = baseFont.GetWidthPoint(footerText, textSize);
            Rectangle pageSize = document.PageSize;

            contentByte.SetRGBColorFill(100, 100, 100);
            contentByte.BeginText();
            contentByte.SetFontAndSize(baseFont, textSize);
            contentByte.SetTextMatrix(pageSize.GetLeft(left), pageSize.GetBottom(bottom));
            contentByte.ShowText(footerText);
            contentByte.EndText();
            contentByte.AddTemplate(template, pageSize.GetLeft(left) + lenght, pageSize.GetBottom(bottom));

            contentByte.BeginText();
            contentByte.SetFontAndSize(baseFont, textSize);
            contentByte.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, string.Format("Utworzony: {0}", PrintTime.ToString()), pageSize.GetRight(right), pageSize.GetBottom(bottom), 0);
            contentByte.EndText();
        }
開發者ID:Khaleesy,項目名稱:Csharp,代碼行數:20,代碼來源:PdfFooter.cs

示例5: GetPages

 /// <summary>
 ///  Copy pages from the given reader into the given content.
 /// </summary>
 /// <param name="content">The content container into which data will be copied</param>
 /// <param name="reader">
 ///  The reader to collect data from a PDF document that has been opened with full permissions
 /// </param>
 /// <returns>An await-able task that will complete when all pages are copied</returns>
 private async Task GetPages(PdfContentByte content, PdfReader reader)
 {
     int pageCount = reader.NumberOfPages;
     for (int currentPage = 1; currentPage <= pageCount; currentPage++)
     {
         document.SetPageSize(reader.GetPageSize(currentPage));
         document.NewPage();
         var page = await Task.Run<PdfImportedPage>(() =>
             writer.GetImportedPage(reader, currentPage));
         var rotation = reader.GetPageRotation(currentPage);
         if (rotation == 90 || rotation == 270)
         {
             // Add the page with a transform matrix that rotates 90 degrees.
             await Task.Run(() => content.AddTemplate(page, 0f, -1f, 1f, 0f, 0f, page.Height));
         }
         else
         {
             // Add the page with an identity transform.
             await Task.Run(() => content.AddTemplate(page, 1f, 0f, 0f, 1f, 0f, 0f));
         }
     }
 }
開發者ID:amullins83,項目名稱:pdfmerge,代碼行數:30,代碼來源:PdfMerger.cs

示例6: ShowText

        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();
        }
開發者ID:,項目名稱:,代碼行數:25,代碼來源:

示例7: Render

        public override byte[] Render()
        {
            byte[] buffer = null;

            using (doc = new Document(PageSize.A4))
            using (MemoryStream stream = new MemoryStream())
            {
                writer = PdfWriter.GetInstance(doc, stream);
                writer.CloseStream = false;
                doc.Open();
                dc = writer.DirectContent;

                var r = Reports[0];
                currentReport = r;
                marginTop = r.Margins.Top;
                marginBottom = r.Margins.Bottom;
                marginLeft = r.Margins.Left;
                marginRight = r.Margins.Right;

                var tHeader = RenderHeader();
                var tFooter = RenderFooter();

                dc.AddTemplate(tHeader, 0, -1 * marginTop);
                dc.AddTemplate(tFooter, 0, marginBottom);

                var bodyHeight = PageHeight - (marginBottom + marginTop + r.Header.Height + r.Footer.Height);

                var t = GenerateTable(r.Body.Elements[0] as TableElement);
                t.CalculateHeights();

                var height = 0f;
                var index = 0;
                var page = 1;
                for (int i = 0; i < t.Rows.Count; i++)
                {
                    var rowHeight = t.GetRowHeight(i);
                    if (height + rowHeight > bodyHeight)
                    {
                        t.WriteSelectedRows(index, i, TranslateLeft(r.Body.Elements[0]), TranslateTop(r.Body.Elements[0]) - marginTop - (page > 1 ? t.GetRowHeight(0) : 0), dc);
                        index = i;
                        doc.NewPage();
                        dc.AddTemplate(tHeader, 0, -1 * marginTop);
                        dc.AddTemplate(tFooter, 0, marginBottom);
                        t.WriteSelectedRows(0, 1, TranslateLeft(r.Body.Elements[0]), TranslateTop(r.Body.Elements[0]) - marginTop, dc);
                        height = t.GetRowHeight(0);
                        page++;
                    }
                    else
                        height += rowHeight;
                }
                t.WriteSelectedRows(index, t.Rows.Count, TranslateLeft(r.Body.Elements[0]), TranslateTop(r.Body.Elements[0]) - marginTop - (page > 1 ? t.GetRowHeight(0) : 0), dc);

                doc.Close();
                buffer = stream.GetBuffer();
            }
            return buffer;
        }
開發者ID:koraytaylan,項目名稱:ReportSharp,代碼行數:57,代碼來源:PdfRenderer.cs

示例8: OnEndPage

        public override void OnEndPage(PdfWriter writer, Document document)
        {
            base.OnEndPage(writer, document);

            int pageN = writer.PageNumber;
            string text = pageN + " - ";
            float len = baseFont.GetWidthPoint(text, 8);

            Rectangle pageSize = document.PageSize;
            pdfContent = writer.DirectContent;
            pdfContent.SetRGBColorFill(100, 100, 100);

            pdfContent.BeginText();
            pdfContent.SetFontAndSize(baseFont, 8);
            pdfContent.SetTextMatrix(pageSize.Width / 2, pageSize.GetBottom(30));
            pdfContent.ShowText(text);
            pdfContent.EndText();

            pdfContent.AddTemplate(pageNumberTemplate, (pageSize.Width / 2) + len, pageSize.GetBottom(30));

            pdfContent.BeginText();
            pdfContent.SetFontAndSize(baseFont, 8);
            pdfContent.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, printTime.ToString(), pageSize.GetRight(40), pageSize.GetBottom(30), 0);
            pdfContent.EndText();
        }
開發者ID:huutruongqnvn,項目名稱:vnecoo01,代碼行數:25,代碼來源:PrintHeaderFooter.cs


注:本文中的iTextSharp.text.pdf.PdfContentByte.AddTemplate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。