public override void OnEndPage(PdfWriter writer, Document doc)
    {
        PdfContentByte cb = writer.DirectContent;

        cb.SetLineWidth(1f);
        cb.SetCMYKColorStroke(66, 59, 57, 38);
        cb.MoveTo(30, 55);
        cb.LineTo(doc.PageSize.Width - 30, 55);
        cb.Stroke();
        cb.MoveTo(185, 80);
        cb.LineTo(185, 25);
        cb.Stroke();

        ColumnText ct      = new ColumnText(cb);
        BaseFont   bfTimes = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false);
        Font       times   = new Font(bfTimes, 10);

        times.SetColor(90, 90, 90);
        ct.SetSimpleColumn(new Phrase("text text", times), 60, 60, 175, 78, 15, Element.ALIGN_MIDDLE);
        ct.Go();
        times.SetColor(1, 73, 144);
        ct.SetSimpleColumn(new Phrase("text textn", times), 60, 38, 175, 55, 15, Element.ALIGN_MIDDLE);
        ct.Go();
        times.SetColor(90, 90, 90);
        ct.SetSimpleColumn(new Phrase("text here", times), 190, 60, doc.PageSize.Width - 32, 78, 15, Element.ALIGN_RIGHT);
        ct.Go();
        times.SetColor(90, 90, 90);
        ct.SetSimpleColumn(new Phrase("text here", times), 190, 38, doc.PageSize.Width - 32, 55, 15, Element.ALIGN_RIGHT);
        ct.Go();
    }
Пример #2
0
// ---------------------------------------------------------------------------
// replace ContentParser.endElement() from Java example
        public void EndElement(string name)
        {
            if ("chapter".Equals(name))
            {
                return;
            }

            String s = buf.ToString().Trim();

            buf = new StringBuilder();
            if (s.Length > 0)
            {
                Paragraph p = new Paragraph(s, font);
                p.Alignment = Element.ALIGN_JUSTIFIED;
                column.AddElement(p);
                int status = column.Go();
                while (ColumnText.HasMoreText(status))
                {
                    canvas.EndMarkedContentSequence();
                    document.NewPage();
                    canvas.BeginMarkedContentSequence(current);
                    column.SetSimpleColumn(36, 36, 384, 569);
                    status = column.Go();
                }
            }
            canvas.EndMarkedContentSequence();
        }
Пример #3
0
        public Chap1005()
        {
            Console.WriteLine("Chapter 10 example 5: Simple Columns");

            // step 1: creation of a document-object
            Document document = new Document();

            try
            {
                // step 2:
                // we create a writer that listens to the document
                // and directs a PDF-stream to a file
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1005.pdf", FileMode.Create));

                // step 3: we open the document
                document.Open();

                // step 4:

                // we create some content
                BaseFont bf   = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                Font     font = new Font(bf, 11, Font.NORMAL);

                Phrase unicodes   = new Phrase(15, "UNI\n", font);
                Phrase characters = new Phrase(15, "\n", font);
                Phrase names      = new Phrase(15, "NAME\n", font);

                for (int i = 0; i < 27; i++)
                {
                    unicodes.Add(uni[i] + "\n");
                    characters.Add(code[i] + "\n");
                    names.Add(name[i] + "\n");
                }

                // we grab the ContentByte and do some stuff with it
                PdfContentByte cb = writer.DirectContent;

                ColumnText ct = new ColumnText(cb);
                ct.SetSimpleColumn(unicodes, 60, 300, 100, 300 + 28 * 15, 15, Element.ALIGN_CENTER);
                ct.Go();
                cb.Rectangle(103, 295, 52, 8 + 28 * 15);
                cb.Stroke();
                ct.SetSimpleColumn(characters, 105, 300, 150, 300 + 28 * 15, 15, Element.ALIGN_RIGHT);
                ct.Go();
                ct.SetSimpleColumn(names, 160, 300, 500, 300 + 28 * 15, 15, Element.ALIGN_LEFT);
                ct.Go();
            }
            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }
            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }

            // step 5: we close the document
            document.Close();
        }
Пример #4
0
 // ===========================================================================
 public override void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter writer = PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         PdfContentByte canvas = writer.DirectContent;
         DrawRectangles(canvas);
         ColumnText ct = new ColumnText(canvas);
         ct.Alignment = Element.ALIGN_JUSTIFIED;
         ct.Leading   = 14;
         int column = 0;
         ct.SetColumns(
             new float[] { 36, 806, 36, 670, 108, 670, 108, 596, 36, 596, 36, 36 },
             new float[] { 296, 806, 296, 484, 259, 484, 259, 410, 296, 410, 296, 36 }
             );
         ct.SetColumns(LEFT[column], RIGHT[column]);
         // ct.SetColumns(LEFT[column], RIGHT[column]);
         // iText-ONLY, 'Initial value of the status' => 0
         // iTextSharp **DOES NOT** include this member variable
         // int status = ColumnText.START_COLUMN;
         int    status = 0;
         Phrase p;
         float  y;
         IEnumerable <Movie> movies = PojoFactory.GetMovies();
         foreach (Movie movie in movies)
         {
             y = ct.YLine;
             p = CreateMovieInformation(movie);
             ct.AddText(p);
             status = ct.Go(true);
             if (ColumnText.HasMoreText(status))
             {
                 column = Math.Abs(column - 1);
                 if (column == 0)
                 {
                     document.NewPage();
                     DrawRectangles(canvas);
                 }
                 ct.SetColumns(LEFT[column], RIGHT[column]);
                 y = 806;
             }
             ct.YLine = y;
             ct.SetText(p);
             status = ct.Go();
         }
     }
 }
Пример #5
0
 // ---------------------------------------------------------------------------
 public void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document(PageSize.A4.Rotate()))
     {
         // step 2
         PdfWriter writer = PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         ColumnText ct     = new ColumnText(writer.DirectContent);
         int        column = 0;
         ct.SetSimpleColumn(
             COLUMNS[column, 0], COLUMNS[column, 1],
             COLUMNS[column, 2], COLUMNS[column, 3]
             );
         // iText-ONLY, 'Initial value of the status' => 0
         // iTextSharp **DOES NOT** include this member variable
         // int status = ColumnText.START_COLUMN;
         int   status = 0;
         float y;
         Image img;
         IEnumerable <Movie> movies = PojoFactory.GetMovies();
         foreach (Movie movie in movies)
         {
             y   = ct.YLine;
             img = Image.GetInstance(
                 Path.Combine(RESOURCE, movie.Imdb + ".jpg")
                 );
             img.ScaleToFit(80, 1000);
             AddContent(ct, movie, img);
             status = ct.Go(true);
             if (ColumnText.HasMoreText(status))
             {
                 column = (column + 1) % 4;
                 if (column == 0)
                 {
                     document.NewPage();
                 }
                 ct.SetSimpleColumn(
                     COLUMNS[column, 0], COLUMNS[column, 1],
                     COLUMNS[column, 2], COLUMNS[column, 3]
                     );
                 y = COLUMNS[column, 3];
             }
             ct.YLine = y;
             ct.SetText(null);
             AddContent(ct, movie, img);
             status = ct.Go();
         }
     }
 }
Пример #6
0
 // ===========================================================================
 public override void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter writer = PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         ColumnText ct = new ColumnText(writer.DirectContent)
         {
             Alignment           = Element.ALIGN_JUSTIFIED,
             ExtraParagraphSpace = 6,
             Leading             = 14,
             Indent         = 10,
             RightIndent    = 3,
             SpaceCharRatio = PdfWriter.NO_SPACE_CHAR_RATIO
         };
         int column = 0;
         // iText-ONLY, 'Initial value of the status' => 0
         // iTextSharp **DOES NOT** include this member variable
         // int status = ColumnText.START_COLUMN;
         int status = 0;
         ct.SetSimpleColumn(
             COLUMNS[column][0], COLUMNS[column][1],
             COLUMNS[column][2], COLUMNS[column][3]
             );
         IEnumerable <Movie> movies = PojoFactory.GetMovies();
         foreach (Movie movie in movies)
         {
             ct.AddText(CreateMovieInformation(movie));
             status = ct.Go();
             if (ColumnText.HasMoreText(status))
             {
                 column = Math.Abs(column - 1);
                 if (column == 0)
                 {
                     document.NewPage();
                 }
                 ct.SetSimpleColumn(
                     COLUMNS[column][0], COLUMNS[column][1],
                     COLUMNS[column][2], COLUMNS[column][3]
                     );
                 ct.YLine = COLUMNS[column][3];
                 status   = ct.Go();
             }
         }
     }
 }
Пример #7
0
 // ===========================================================================
 public override void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter writer = PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         ColumnText ct     = new ColumnText(writer.DirectContent);
         int        column = 0;
         ct.SetSimpleColumn(
             COLUMNS[column][0], COLUMNS[column][1],
             COLUMNS[column][2], COLUMNS[column][3]
             );
         // iText-ONLY, 'Initial value of the status' => 0
         // iTextSharp **DOES NOT** include this member variable
         // int status = ColumnText.START_COLUMN;
         int    status = 0;
         Phrase p;
         float  y;
         IEnumerable <Movie> movies = PojoFactory.GetMovies();
         foreach (Movie movie in movies)
         {
             y = ct.YLine;
             p = CreateMovieInformation(movie);
             ct.AddText(p);
             status = ct.Go(true);
             if (ColumnText.HasMoreText(status))
             {
                 column = Math.Abs(column - 1);
                 if (column == 0)
                 {
                     document.NewPage();
                 }
                 ct.SetSimpleColumn(
                     COLUMNS[column][0], COLUMNS[column][1],
                     COLUMNS[column][2], COLUMNS[column][3]
                     );
                 y = COLUMNS[column][3];
             }
             ct.YLine = y;
             ct.SetText(p);
             status = ct.Go(false);
         }
     }
 }
Пример #8
0
 private static void smethod_1(PdfContentByte pdfContentByte_0, Graphics graphics_0, int int_0, int int_1, int int_2, int int_3, string string_0, System.Drawing.Font font_0, System.Drawing.Color color_0)
 {
     try
     {
         PdfSpotColor sp = new PdfSpotColor("PANTONE 147", 0.9f, new iTextSharp.text.Color(color_0.R, color_0.G, color_0.B));
         pdfContentByte_0.SetColorStroke(sp, 1f);
         pdfContentByte_0.SetColorFill(sp, 1f);
         int style = 0;
         if (font_0.Bold)
         {
             style++;
         }
         if (font_0.Italic)
         {
             style += 2;
         }
         if (font_0.Underline)
         {
             style += 4;
         }
         iTextSharp.text.Font font = new iTextSharp.text.Font(getBaseFont(font_0.Name), font_0.Size, style);
         ColumnText           text = new ColumnText(pdfContentByte_0);
         Phrase phrase             = new Phrase(string_0, font);
         text.SetSimpleColumn(phrase, (float)int_0, (float)int_1, (float)(int_2 + 100), (float)int_3, 0f, 0);
         text.Go();
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception.Message);
     }
 }
Пример #9
0
        public static byte[] AddPDFTextFields(byte[] filePdf, IEnumerable <PdfTextField> pdfFields)
        {
            var reader = new PdfReader(filePdf);
            var result = new MemoryStream();

            using (var stamper = new PdfStamper(reader, result))
            {
                foreach (var field in pdfFields)
                {
                    var        cb = stamper.GetOverContent(field.page);
                    ColumnText ct = new ColumnText(cb);
                    ct.SetSimpleColumn(new Phrase(new Chunk(field.text, FontFactory.GetFont(field.fontName, field.fontEncoding, field.fontEmbeded, field.fontSize, Font.NORMAL, new BaseColor(System.Drawing.ColorTranslator.FromHtml(field.color))))),
                                       field.x, field.y, field.x + field.width, field.y + field.height, field.fontSize, field.align);
                    ct.Go();
                    if (field.showborder)
                    {
                        cb.SetColorStroke(BaseColor.BLUE);
                        cb.Rectangle(field.x, field.y, field.width, field.height);
                        cb.Stroke();
                    }
                }
                stamper.Close();
            }
            reader.Close();
            return(result.ToArray());
        }
Пример #10
0
        public void CreateTaggedPdf21()
        {
            try {
                InitializeDocument("21");

                PdfTemplate template = writer.DirectContent.CreateTemplate(PageSize.A4.Width, PageSize.A4.Height);

                writer.DirectContent.AddTemplate(template, 0, 0, true);

                ColumnText columnText = new ColumnText(template);
                columnText.SetSimpleColumn(36, 36, 250, 750);
                columnText.AddText(new Phrase("Hello word \n\n"));
                columnText.Go();

                document.NewPage();
                writer.DirectContent.AddTemplate(template, 0, 0);

                document.Close();
            }
            catch (Exception conformExc) {
                Assert.AreEqual("Template with tagged content could not be used more than once.", conformExc.Message);
                return;
            }
            finally {
                document.Close();
            }
            Assert.Fail("Expected error: 'Template with tagged content could not be used more than once.");
        }
Пример #11
0
        internal void BigTextLeftColumn(string text, float percentPage)
        {
            var phrase     = new Phrase(text, new Font(GetFont(BaseFont.HELVETICA), 7));
            var columnText = new ColumnText(_contentByte)
            {
                Alignment       = Element.ALIGN_LEFT,
                AdjustFirstLine = false,

                Leading = 10,
            };

            var llx = 25f;
            var lly = (Position - (text.Length / 5.5f));
            var urx = _doc.PageSize.Width * percentPage;
            var ury = Position;

            columnText.SetIndent(0, true);
            columnText.SetText(phrase);

            columnText.SetSimpleColumn(llx, lly, urx, ury);

            CheckPosition(ury - lly);
            columnText.Go();
            SetAtualPosition(lly + 20);
        }
Пример #12
0
        internal void TextRightWithBorder(string total, string forRoom, string daily, string rooms)
        {
            var font = BaseFont.HELVETICA_BOLD;

            var columnText = new ColumnText(_contentByte)
            {
                Alignment           = Element.ALIGN_RIGHT,
                AdjustFirstLine     = false,
                SpaceCharRatio      = 1,
                Leading             = 9,
                ExtraParagraphSpace = 0
            };

            var llx = _doc.PageSize.Width * 0.75f;
            var lly = Position;
            var urx = _doc.PageSize.Width - (_doc.Left * 2);
            var ury = Position + 60;

            columnText.SetIndent(0, true);

            columnText.AddText(new Phrase(total + "\n", new Font(GetFont(font), 10)));
            columnText.AddText(new Phrase(forRoom + "\n", new Font(GetFont(font), 8)));
            columnText.AddText(new Phrase(daily + "\n", new Font(GetFont(font), 8)));
            columnText.AddText(new Phrase(rooms + "\n", new Font(GetFont(font), 8)));

            var adjustX = 20f;
            var adjustY = 10f;

            columnText.SetSimpleColumn(llx - adjustX, lly - adjustY, urx - adjustX, ury - adjustY);
            columnText.Go();
            Rectangle(llx, lly, urx - llx, ury - lly, 0.3f, 0, BaseColor.GRAY);
            SetAtualPosition(lly);
        }
Пример #13
0
        private void Column(List <string> list, float llx)
        {
            var columnText = new ColumnText(_contentByte)
            {
                Alignment           = Element.ALIGN_LEFT,
                AdjustFirstLine     = false,
                SpaceCharRatio      = 1,
                Leading             = 9,
                ExtraParagraphSpace = 0
            };

            var lly = Position - (list.Count * 8);
            var urx = llx + (_doc.PageSize.Width / 4);
            var ury = Position;

            columnText.SetIndent(0, true);

            list.ForEach(x =>
            {
                columnText.AddText(new Phrase(x + "\n", new Font(GetFont(BaseFont.HELVETICA), 8)));
            });

            columnText.SetSimpleColumn(llx, lly, urx, ury + 10);

            columnText.Go();
        }
Пример #14
0
        public override void DrawMe(float printingTop, EbReport Rep, List <Param> Params, int slno)
        {
            ColumnText ct         = new ColumnText(Rep.Canvas);
            string     column_val = Rep.GetDataFieldValue(ColumnName, slno, TableIndex);

            if (Prefix != "" || Suffix != "")
            {
                column_val = Prefix + " " + column_val + " " + Suffix;
            }

            Phrase phrase = GetPhrase(column_val, (DbType)DbType, Rep.Font);

            if (!string.IsNullOrEmpty(LinkRefId))
            {
                Anchor    a = CreateLink(phrase, LinkRefId, Rep.Doc, Params);
                Paragraph p = new Paragraph {
                    a
                };
                p.Font = GetItextFont(this.Font, Rep.Font);
                ct.AddText(p);
            }
            else
            {
                ct.AddText(phrase);
            }
            float ury = Rep.HeightPt - (printingTop + TopPt + Rep.detailprintingtop);
            float lly = Rep.HeightPt - (printingTop + TopPt + HeightPt + Rep.detailprintingtop);

            ct.SetSimpleColumn(Llx, lly, Urx, ury, Leading, (int)TextAlign);
            ct.Go();
        }
Пример #15
0
        public override void DrawMe(float printingTop, EbReport Rep, List <Param> Params, int slno)
        {
            float  ury        = Rep.HeightPt - (printingTop + TopPt + Rep.detailprintingtop);
            float  lly        = Rep.HeightPt - (printingTop + TopPt + HeightPt + Rep.detailprintingtop);
            string column_val = SummarizedValue.ToString();

            ResetSummary();
            column_val = FormatDecimals(column_val, AmountInWords, DecimalPlaces, Rep.CultureInfo?.NumberFormat, FormatUsingCulture);

            if (Rep.SummaryValInRow.ContainsKey(Title))
            {
                Rep.SummaryValInRow[Title] = new PdfNTV {
                    Name = Title.Replace(".", "_"), Type = PdfEbDbTypes.Int32, Value = column_val
                }
            }
            ;
            else
            {
                Rep.SummaryValInRow.Add(Title, new PdfNTV {
                    Name = Title.Replace(".", "_"), Type = PdfEbDbTypes.Int32, Value = column_val
                });
            }

            Phrase     phrase = GetPhrase(column_val, (DbType)DbType, Rep.Font);
            ColumnText ct     = new ColumnText(Rep.Canvas);

            ct.SetSimpleColumn(phrase, Llx, lly, Urx, ury, Leading, (int)TextAlign);
            ct.Go();
        }
Пример #16
0
        public override void DrawMe(float printingTop, EbReport Rep, List <Param> Params, int slno)
        {
            float  ury        = Rep.HeightPt - (printingTop + TopPt + Rep.detailprintingtop);
            float  lly        = Rep.HeightPt - (printingTop + TopPt + HeightPt + Rep.detailprintingtop);
            string column_val = SummarizedValue.ToString();

            ResetSummary();
            Phrase     phrase = GetFormattedPhrase(this.Font, Rep.Font, column_val);
            ColumnText ct     = new ColumnText(Rep.Canvas);

            if (!string.IsNullOrEmpty(LinkRefId))
            {
                Anchor    a = CreateLink(phrase, LinkRefId, Rep.Doc, Params);
                Paragraph p = new Paragraph {
                    a
                };
                p.Font = GetItextFont(this.Font, Rep.Font);
                ct.AddText(p);
            }
            else
            {
                ct.AddText(phrase);
            }
            ct.SetSimpleColumn(Llx, lly, Urx, ury, Leading, (int)TextAlign);
            ct.Go();
        }
Пример #17
0
        public void TabStopOutOfPageBoundColumnTextTest()
        {
            Font       f   = FontFactory.GetFont(FontFactory.COURIER, 11);
            Document   doc = new Document();
            Paragraph  p;
            FileStream fs     = new FileStream(TARGET + "/tabStopOutColumnText.pdf", FileMode.Create);
            PdfWriter  writer = PdfWriter.GetInstance(doc, fs);

            writer.CompressionLevel = 0;
            doc.Open();
            ColumnText ct = new ColumnText(writer.DirectContent);

            ct.SetSimpleColumn(36, 0, 436, 836);
            f.Size = 16;
            p      = new Paragraph(Chunk.TABBING);
            p.Add(new Chunk("Hello world", f));
            List <TabStop> tabStopsList = new List <TabStop>();

            tabStopsList.Add(new TabStop(1000, new DottedLineSeparator()));
            tabStopsList.Add(new TabStop(1050, new LineSeparator(), TabStop.Alignment.ANCHOR, ','));
            tabStopsList.Add(new TabStop(1100, new DottedLineSeparator(), TabStop.Alignment.ANCHOR));
            p.TabSettings = new TabSettings(tabStopsList, 50);
            AddTabs(p, f, 15, "l.aal");
            AddTabs(p, f, 13, "laa,l");
            AddTabs(p, f, 13, "laa.l");
            AddTabs(p, f, 13, "l,aal");
            ct.AddElement(p);
            ct.Go();
            doc.Close();
            writer.Close();
            Assert.IsTrue(CompareInnerText(SOURCE17, TARGET + "/tabStopOutColumnText.pdf"));
        }
Пример #18
0
        public void Verify_Issue37_CanBe_Processed()
        {
            var pdfDoc = new Document(PageSize.A4);

            var pdfFilePath = TestUtils.GetOutputFileName();
            var fileStream  = new FileStream(pdfFilePath, FileMode.Create);
            var writer      = PdfWriter.GetInstance(pdfDoc, fileStream);

            pdfDoc.AddAuthor(TestUtils.Author);
            pdfDoc.Open();

            var ct = new ColumnText(writer.DirectContent);

            var text = new Phrase("TEST paragraph\nAfter Newline");

            text.Add(new Chunk("\u00A0Test Test\u00A0"));
            text.Add(new Chunk("\nNew line"));

            ct.SetSimpleColumn(
                phrase: text,
                llx: 34, lly: 750, urx: 580, ury: 317,
                leading: 15,
                alignment: Element.ALIGN_LEFT);
            ct.Go();

            pdfDoc.Close();
            fileStream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
Пример #19
0
        public void Verify_Unicode_PDF_File_CanBeCreated_Using_Chunks()
        {
            var pdfDoc = new Document(PageSize.A4);

            var pdfFilePath = TestUtils.GetOutputFileName();
            var fileStream  = new FileStream(pdfFilePath, FileMode.Create);
            var pdfWriter   = PdfWriter.GetInstance(pdfDoc, fileStream);

            pdfDoc.AddAuthor(TestUtils.Author);
            pdfDoc.Open();

            var tahomaFont = TestUtils.GetUnicodeFont("Tahoma", TestUtils.GetTahomaFontPath(), 10, Font.NORMAL, BaseColor.Black);

            var ct = new ColumnText(pdfWriter.DirectContent)
            {
                RunDirection = PdfWriter.RUN_DIRECTION_RTL
            };

            ct.SetSimpleColumn(100, 100, 500, 800, 24, Element.ALIGN_RIGHT);

            var chunk = new Chunk("آزمایش", tahomaFont);

            ct.AddElement(chunk);
            ct.Go();

            pdfDoc.Close();
            fileStream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
Пример #20
0
        public void NestedTablesTest01()
        {
            String output = "nestedTablesTest.pdf";
            String cmp    = "cmp_nestedTablesTest.pdf";

            Stopwatch timer = new Stopwatch();

            timer.Start();

            Document  doc    = new Document(PageSize.A4);
            PdfWriter writer = PdfWriter.GetInstance(doc, File.Create(outFolder + output));

            doc.Open();

            ColumnText column = new ColumnText(writer.DirectContent);

            column.SetSimpleColumn(72, 72, 523, 770);
            column.AddElement(CreateNestedTables(15));
            column.Go();

            doc.Close();

            timer.Stop();
            Console.WriteLine(timer.ElapsedMilliseconds);

            CompareDocuments(output, cmp, false);
        }
Пример #21
0
        public void go(Int64 x, Int64 y, Int64 width, Int64 height, bool outline)
        {
            m_column_text.AddText(m_content);
            m_column_text.Leading   = m_leading;
            m_column_text.Alignment = m_alignment;

            m_column_text.SetSimpleColumn(
                dkw(x),
                dkh(y),
                dkw(width),
                dkh(height)
                );

            m_column_text.Go();

            m_height = height - m_page_property.H_R2P((Int64)m_column_text.YLine);
            if (outline)
            {
                m_direct_content.Rectangle(
                    dkw(x),
                    dkh(y),
                    dkw(width - x),
                    dkh(height - y));
                m_direct_content.Stroke();
            }
        }
Пример #22
0
// ---------------------------------------------------------------------------
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document()) {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                BaseFont bf = BaseFont.CreateFont(
                    "c:/windows/fonts/arialuni.ttf",
                    BaseFont.IDENTITY_H, BaseFont.EMBEDDED
                    );
                Font font = new Font(bf, 20);
                document.Add(new Paragraph("Movie title: Lawrence of Arabia (UK)"));
                document.Add(new Paragraph("directed by David Lean"));
                document.Add(new Paragraph("Wrong: " + MOVIE, font));
                ColumnText column = new ColumnText(writer.DirectContent);
                column.SetSimpleColumn(36, 730, 569, 36);
                column.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
                column.AddElement(new Paragraph("Wrong: " + MOVIE_WITH_SPACES, font));
                column.AddElement(new Paragraph(MOVIE, font));
                column.Go();
            }
        }
Пример #23
0
        public override void RenderObject()
        {
            ColumnText itextText = new ColumnText(PdfContent);

            itextText.SetSimpleColumn(ObjectLayoutContainer.Layout.Left.Points, ObjectLayoutContainer.Layout.Top.Points,
                                      ObjectLayoutContainer.Layout.Right.Points,
                                      ObjectLayoutContainer.Layout.Bottom.Points);

            Paragraph pdfContentParagraph = new Paragraph();

            itextText.AddElement(pdfContentParagraph);

            if (_textlines.Count > 0)
            {
                Models.Text.Paragraph currentParagraph = _textlines.First().ParagraphModel;
                pdfContentParagraph.Leading   = currentParagraph.Leading.Points;
                pdfContentParagraph.Alignment = (int)currentParagraph.Alignment;
                foreach (Textline textline in _textlines)
                {
                    if (currentParagraph != textline.ParagraphModel)
                    {
                        pdfContentParagraph = new Paragraph(textline.ParagraphModel.Leading.Points)
                        {
                            Alignment = (int)textline.ParagraphModel.Alignment
                        };
                        itextText.AddElement(pdfContentParagraph);
                    }
                    textline.Render(pdfContentParagraph);
                    currentParagraph = textline.ParagraphModel;
                }
                itextText.Go();
            }
        }
Пример #24
0
    private static void AddInvoiceHeadingPart(PdfContentByte directContent, Invoice invoice)
    {
        var table = new PdfPTable(2)
        {
            HorizontalAlignment = Element.ALIGN_LEFT, WidthPercentage = 100
        };

        table.SetWidths(new float[] { 55, 55 });

        table.AddCell(PdfHelper.GetCell("Factuurdatum", PdfHelper.BoldFont).AlignRight());
        table.AddCell(PdfHelper.GetCell(invoice.Date.ToShortDateString()));

        table.AddCell(PdfHelper.GetCell("Vervaldatum", PdfHelper.BoldFont).AlignRight());
        table.AddCell(PdfHelper.GetCell(invoice.ExpiryDate.ToShortDateString()));

        table.AddCell(PdfHelper.GetCell("Factuurnummer", PdfHelper.BoldFont).AlignRight());
        table.AddCell(PdfHelper.GetCell(invoice.FullNumber).BorderRight());

        if (!string.IsNullOrEmpty(invoice.TheirReference))
        {
            table.AddCell(PdfHelper.GetCell("Uw referentie", PdfHelper.BoldFont).AlignRight());
            table.AddCell(PdfHelper.GetCell(invoice.TheirReference).BorderRight());
        }

        PdfHelper.SurroundBorders(table);

        var columnText = new ColumnText(directContent);
        var size       = directContent.PdfDocument.PageSize;

        columnText.SetSimpleColumn(size.Right - 300, size.Top - 135, size.Right - 50, size.Top - 500);
        columnText.AddElement(table);
        columnText.Go();
    }
Пример #25
0
        // ===========================================================================
        public virtual void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document())
            {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                IEnumerable <Movie> movies = PojoFactory.GetMovies();
                ColumnText          ct     = new ColumnText(writer.DirectContent);
                foreach (Movie movie in movies)
                {
                    ct.AddText(CreateMovieInformation(movie));
                    ct.AddText(Chunk.NEWLINE);
                }
                ct.Alignment           = Element.ALIGN_JUSTIFIED;
                ct.ExtraParagraphSpace = 6;
                ct.SetLeading(0, 1.2f);
                ct.FollowingIndent = 27;
                int linesWritten = 0;
                int column       = 0;
                // iText-ONLY, 'Initial value of the status' => 0
                // iTextSharp **DOES NOT** include this member variable
                // int status = ColumnText.START_COLUMN;
                int status = 0;
                while (ColumnText.HasMoreText(status))
                {
                    ct.SetSimpleColumn(
                        COLUMNS[column][0], COLUMNS[column][1],
                        COLUMNS[column][2], COLUMNS[column][3]
                        );
                    ct.YLine      = COLUMNS[column][3];
                    status        = ct.Go();
                    linesWritten += ct.LinesWritten;
                    column        = Math.Abs(column - 1);
                    if (column == 0)
                    {
                        document.NewPage();
                    }
                }

                ct.AddText(new Phrase("Lines written: " + linesWritten));
                ct.Go();
            }
        }
Пример #26
0
        internal void TextColumn(string text, string nameFont, int sizeFont, float xInfEsq, float yInfEsq, float xSupDir, float ySupDir)
        {
            var ct = new ColumnText(this.PdfContentByte);

            ct.SetSimpleColumn(xInfEsq, yInfEsq, xSupDir, ySupDir);
            ct.AddElement(TextJustified(text, nameFont, sizeFont));
            ct.Go();
        }
Пример #27
0
        private void WriteTable(PdfContentByte directContent, PdfPTable table, Rectangle coordinates)
        {
            ColumnText columnText = new ColumnText(directContent);

            columnText.SetSimpleColumn(coordinates);
            columnText.AddElement(table);
            columnText.Go();
        }
Пример #28
0
        public void CreateColumnText(string Text, float x, float y, float length, float height)
        {
            ColumnText ct = new ColumnText(_pDFWriter.DirectContent);

            ct.SetSimpleColumn(new Rectangle(x, y, length, height));
            ct.AddElement(new Paragraph(Text));
            ct.Go();
        }
Пример #29
0
        private void ProcessStampSolidOutline(ATShape dr, PdfStamper stamper, PdfReader pdfReader, bool isFilled)
        {
            var pageHeight = pdfReader.GetPageSizeWithRotation(dr.Mark.PageIndex).Height;
            var cb         = stamper.GetOverContent(dr.Mark.PageIndex);

            var outer = new Rectangle(dr.PositionX, pageHeight - (dr.PositionY + dr.Height), dr.PositionX + dr.Width, pageHeight - dr.PositionY);
            var color = GetColor(dr.StampColor ?? "#990000");

            cb.SetColorStroke(color);
            var strokeWidth = 4f;

            cb.SetLineWidth(strokeWidth);
            cb.RoundRectangle(
                outer.Left,
                outer.Bottom + strokeWidth,
                outer.Width - strokeWidth,
                outer.Height - strokeWidth,
                5);

            if (isFilled)
            {
                cb.SetColorFill(color);
                cb.FillStroke();
            }
            else
            {
                cb.Stroke();
            }

            var text = dr.LabelText;

            // Create a font to work with
            color = GetColor(dr.LabelTextColor ?? "#000000");
            cb.SetRGBColorFill(color.R, color.G, color.B);

            // Note: The x,y of the Pdf Matrix is from bottom left corner.
            // This command tells iTextSharp to write the text at a certain location with a certain angle.
            // Again, this will angle the text from bottom left corner to top right corner and it will
            // place the text in the middle of the page.
            var size     = 13f;
            var baseFont = BaseFont.CreateFont(BaseFont.TIMES_BOLD, Encoding.ASCII.EncodingName, true);
            var ct       = new ColumnText(cb);
            var p        = new Paragraph(text, new Font(baseFont, size));
            var t        = new PdfPTable(1);
            var c        = new PdfPCell(p);

            c.VerticalAlignment   = Element.ALIGN_MIDDLE;
            c.HorizontalAlignment = Element.ALIGN_CENTER;
            c.FixedHeight         = outer.Height + 10;
            c.BorderWidth         = 0;
            c.SetLeading(0f, 1.2f);
            c.PaddingBottom = c.PaddingLeft = c.PaddingRight = c.PaddingTop = 0;
            t.AddCell(c);
            // TODO: remove this hardcoded adjust, was added to conform client
            ct.SetSimpleColumn(outer.Left - 2, outer.Bottom, outer.Right + 2, outer.Top + 12);
            ct.AddElement(t);
            ct.Go();
        }
Пример #30
0
        public void CreateTaggedPdf8()
        {
            InitializeDocument("8");

            ColumnText columnText = new ColumnText(writer.DirectContent);

            List list = new List(true);

            try {
                list = new List(true);
                ListItem listItem =
                    new ListItem(
                        new Chunk(
                            "Quick brown fox jumped over a lazy dog. A very long line appears here because we need new line."));
                list.Add(listItem);
                Image i = Image.GetInstance(RESOURCES + "img\\fox.bmp");
                Chunk c = new Chunk(i, 0, 0);
                c.SetAccessibleAttribute(PdfName.ALT, new PdfString("Fox image"));
                listItem = new ListItem(c);
                list.Add(listItem);
                listItem = new ListItem(new Chunk("jumped over a lazy"));
                list.Add(listItem);
                i = Image.GetInstance(RESOURCES + "img\\dog.bmp");
                c = new Chunk(i, 0, 0);
                c.SetAccessibleAttribute(PdfName.ALT, new PdfString("Dog image"));
                listItem = new ListItem(c);
                list.Add(listItem);
                listItem = new ListItem(new Paragraph(text));
                list.Add(listItem);
            }
            catch (Exception) {
            }
            columnText.SetSimpleColumn(36, 36, 400, 800);
            columnText.AddElement(h1);
            columnText.AddElement(list);
            columnText.Go();
            document.NewPage();
            columnText.SetSimpleColumn(36, 36, 400, 800);
            columnText.Go();
            document.Close();

            int[] nums = new int[] { 64, 35 };
            CheckNums(nums);
            CompareResults("8");
        }