SetSplitCharacter() публичный Метод

Sets the split characters.
public SetSplitCharacter ( ISplitCharacter splitCharacter ) : Chunk
splitCharacter ISplitCharacter the SplitCharacter interface
Результат Chunk
        public void Go()
        {
            // GetClassOutputPath() implementation left out for brevity
            var outputFile = Helpers.IO.GetClassOutputPath(this);

            using (FileStream stream = new FileStream(
                outputFile, 
                FileMode.Create, 
                FileAccess.Write))
            {
                Random random = new Random();

                StreamUtil.AddToResourceSearch(("iTextAsian.dll"));
                string chunkText = " 你好世界 你好你好,";
                var font = new Font(BaseFont.CreateFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED), 12);

                using (Document document = new Document())
                {
                    PdfWriter.GetInstance(document, stream);
                    document.Open();
                    Phrase phrase = new Phrase();
                    Chunk chunk = new Chunk("", font);
                    for (var i = 0; i < 1000; ++i)
                    {
                        var asterisk = new String('*', random.Next(1, 20));
                        chunk.Append(
                            string.Format("[{0}] {1} ", asterisk, chunkText) 
                        );
                    }
                    chunk.SetSplitCharacter(new CustomSplitCharacter());
                    phrase.Add(chunk);
                    document.Add(phrase);
                }
            }
        }
Пример #2
0
        // ===========================================================================
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document(
              new Rectangle(240, 240), 10, 10, 10, 10
            ))
            {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                // create a long Stringbuffer with movie titles
                StringBuilder sb = new StringBuilder();
                IEnumerable<Movie> movies = PojoFactory.GetMovies(1);
                foreach (Movie movie in movies)
                {
                    // replace spaces with non-breaking spaces
                    sb.Append(movie.MovieTitle.Replace(' ', '\u00a0'));
                    // use pipe as separator
                    sb.Append('|');
                }
                // Create a first chunk
                Chunk chunk1 = new Chunk(sb.ToString());
                // wrap the chunk in a paragraph and add it to the document
                Paragraph paragraph = new Paragraph("A:\u00a0");
                paragraph.Add(chunk1);
                paragraph.Alignment = Element.ALIGN_JUSTIFIED;
                document.Add(paragraph);
                document.Add(Chunk.NEWLINE);
                // define the pipe character as split character
                chunk1.SetSplitCharacter(new PipeSplitCharacter());
                // wrap the chunk in a second paragraph and add it
                paragraph = new Paragraph("B:\u00a0");
                paragraph.Add(chunk1);
                paragraph.Alignment = Element.ALIGN_JUSTIFIED;
                document.Add(paragraph);
                document.Add(Chunk.NEWLINE);

                // create a new StringBuffer with movie titles
                sb = new StringBuilder();
                foreach (Movie movie in movies)
                {
                    sb.Append(movie.MovieTitle);
                    sb.Append('|');
                }
                // Create a second chunk 
                Chunk chunk2 = new Chunk(sb.ToString());
                // wrap the chunk in a paragraph and add it to the document
                paragraph = new Paragraph("C:\u00a0");
                paragraph.Add(chunk2);
                paragraph.Alignment = Element.ALIGN_JUSTIFIED;
                document.Add(paragraph);
                document.NewPage();
                // define hyphenation for the chunk
                chunk2.SetHyphenation(new HyphenationAuto("en", "US", 2, 2));
                // wrap the second chunk in a second paragraph and add it
                paragraph = new Paragraph("D:\u00a0");
                paragraph.Add(chunk2);
                paragraph.Alignment = Element.ALIGN_JUSTIFIED;
                document.Add(paragraph);

                // go to a new page
                document.NewPage();
                // define a new space/char ratio
                writer.SpaceCharRatio = PdfWriter.NO_SPACE_CHAR_RATIO;
                // wrap the second chunk in a third paragraph and add it
                paragraph = new Paragraph("E:\u00a0");
                paragraph.Add(chunk2);
                paragraph.Alignment = Element.ALIGN_JUSTIFIED;
                document.Add(paragraph);
            }
        }
        public void Go()
        {
            // GetClassOutputPath() implementation left out for brevity
            var outputFile = Helpers.IO.GetClassOutputPath(this);

            using (FileStream stream = new FileStream(
                outputFile, 
                FileMode.Create, 
                FileAccess.Write))
            {
                string chunkText = "FirstName LastName (2016-01-13 11:13)";
                Random random = new Random();
                var font = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD); 
                using (Document document = new Document())
                {
                    PdfWriter.GetInstance(document, stream);
                    document.Open();
                    Phrase phrase = new Phrase();
                    for (var i = 0; i < 1000; ++i)
                    {
                        var asterisk = new String('*', random.Next(1, 20));
                        Chunk chunk = new Chunk(
                            string.Format("[{0}] {1}", asterisk, chunkText), 
                            font
                        );
                        chunk.SetSplitCharacter(new CustomSplitCharacter());
                        phrase.Add(chunk);
                    }
 
                    document.Add(phrase);
                }
            }
        }