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


C# text.Chunk類代碼示例

本文整理匯總了C#中iTextSharp.text.Chunk的典型用法代碼示例。如果您正苦於以下問題:C# Chunk類的具體用法?C# Chunk怎麽用?C# Chunk使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Chunk類屬於iTextSharp.text命名空間,在下文中一共展示了Chunk類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ManipulatePdf

// ---------------------------------------------------------------------------    
    /**
     * Manipulates a PDF file src with the file dest as result
     * @param src the original PDF
     */
    public byte[] ManipulatePdf(byte[] src) {
    // Create a table with named actions
      Font symbol = new Font(Font.FontFamily.SYMBOL, 20);
      PdfPTable table = new PdfPTable(4);
      table.DefaultCell.Border = Rectangle.NO_BORDER;
      table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
      Chunk first = new Chunk( ((char)220).ToString() , symbol);
      first.SetAction(new PdfAction(PdfAction.FIRSTPAGE));
      table.AddCell(new Phrase(first));
      Chunk previous = new Chunk( ((char)172).ToString(), symbol);
      previous.SetAction(new PdfAction(PdfAction.PREVPAGE));
      table.AddCell(new Phrase(previous));
      Chunk next = new Chunk( ((char)174).ToString(), symbol);
      next.SetAction(new PdfAction(PdfAction.NEXTPAGE));
      table.AddCell(new Phrase(next));
      Chunk last = new Chunk( ((char)222).ToString(), symbol);
      last.SetAction(new PdfAction(PdfAction.LASTPAGE));
      table.AddCell(new Phrase(last));
      table.TotalWidth = 120;
      
      // Create a reader
      PdfReader reader = new PdfReader(src);
      using (MemoryStream ms = new MemoryStream()) {
        // Create a stamper
        using (PdfStamper stamper = new PdfStamper(reader, ms)) {
          // Add the table to each page
          PdfContentByte canvas;
          for (int i = 0; i < reader.NumberOfPages; ) {
            canvas = stamper.GetOverContent(++i);
            table.WriteSelectedRows(0, -1, 696, 36, canvas);
          }
        }
        return ms.ToArray();
      }    
    }    
開發者ID:,項目名稱:,代碼行數:40,代碼來源:

示例2: PageEventTest01

        public void PageEventTest01() {
            String fileName = "pageEventTest01.pdf";

            MemoryStream baos = new MemoryStream();
            Document doc = new Document(PageSize.LETTER, 144, 144, 144, 144);
            PdfWriter writer = PdfWriter.GetInstance(doc, baos);
            writer.PageEvent = new MyEventHandler();

            writer.SetTagged();
            doc.Open();

            Chunk c = new Chunk("This is page 1");
            doc.Add(c);

            doc.Close();

            File.WriteAllBytes(OUTPUT_FOLDER + fileName, baos.ToArray());
            baos.Close();

            // compare
            CompareTool compareTool = new CompareTool();
            String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER + fileName, TEST_RESOURCES_PATH + fileName, OUTPUT_FOLDER, "diff");
            if (errorMessage != null) {
                Assert.Fail(errorMessage);
            }
        }
開發者ID:newlysoft,項目名稱:itextsharp,代碼行數:26,代碼來源:PageEventTest.cs

示例3: GeneratePdfElement

        public override iTextSharp.text.IElement GeneratePdfElement()
        {
            ChunkStyle style = (Manifest != null) ? Manifest.Styles.GetMergedFromConfiguration(Style) : Style;

            iTextSharp.text.Chunk chunk = new iTextSharp.text.Chunk(Text, (iText.Font)style.Font);
            return chunk;
        }
開發者ID:onesimoh,項目名稱:Andamio,代碼行數:7,代碼來源:Chunk.cs

示例4: GetFormattedText

        public static IT.Chunk GetFormattedText(Text text)
        {
            IT.Chunk formattedChuck = new IT.Chunk(text.TextContent);
            formattedChuck.Font = GetFormattedFont(text.Font);

            return formattedChuck;
        }
開發者ID:amilasurendra,項目名稱:pdf-generator,代碼行數:7,代碼來源:TextFormatter.cs

示例5: CreatePdf

// ---------------------------------------------------------------------------    
    /**
     * Creates a PDF document.
     * @param stream Stream for the new PDF document
     */
    public void CreatePdf(Stream stream) {
      string RESOURCE = Utility.ResourcePosters;
      // step 1
      using (Document document = new Document()) {
        // step 2
        PdfWriter writer = PdfWriter.GetInstance(document, stream);
        // step 3
        document.Open();
        // step 4
        Phrase phrase;
        Chunk chunk;
        PdfAnnotation annotation;
        foreach (Movie movie in PojoFactory.GetMovies()) {
          phrase = new Phrase(movie.MovieTitle);
          chunk = new Chunk("\u00a0\u00a0");
          annotation = PdfAnnotation.CreateFileAttachment(
            writer, null,
            movie.MovieTitle, null,
            Path.Combine(RESOURCE, movie.Imdb + ".jpg"),
            string.Format("img_{0}.jpg", movie.Imdb)
          );
          annotation.Put(PdfName.NAME, new PdfString("Paperclip"));
          chunk.SetAnnotation(annotation);
          phrase.Add(chunk);
          document.Add(phrase);
          document.Add(PojoToElementFactory.GetDirectorList(movie));
          document.Add(PojoToElementFactory.GetCountryList(movie));
        }
      }
    }
開發者ID:,項目名稱:,代碼行數:35,代碼來源:

示例6: ApplyForText

        public void ApplyForText(PdfContentByte cb, IDictionary<String, String> css, Chunk chunk)
        {
            SetStrokeAndFillColor(cb, css);
            SetStrokeAndFill(cb, css);

            try
            {
                Font font = new Font(Font.FontFamily.COURIER, 6, Font.NORMAL, BaseColor.BLACK);

                Font font2 = chunk.Font;

                BaseFont bf2 = font2.BaseFont;
                //BaseFont bf = ;

                if (bf2 == null)
                {
                    cb.SetFontAndSize(font.GetCalculatedBaseFont(false), font2.Size);
                }
                else
                {
                    cb.SetFontAndSize(bf2, font2.Size);
                }
            } catch { }

        }
開發者ID:,項目名稱:,代碼行數:25,代碼來源:

示例7: Go

        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);
                }
            }
        }
開發者ID:kuujinbo,項目名稱:StackOverflow.iTextSharp,代碼行數:35,代碼來源:ChineseSetSplitCharacter.cs

示例8: OnEndPage

        public override void OnEndPage(PdfWriter writer, Document document)
        {
            PdfPTable footer = new PdfPTable(3);
            footer.SetWidths(new float[] { 88f, 7f, 5f });
            footer.WidthPercentage = 100;
            footer.TotalWidth = document.PageSize.Width - (document.LeftMargin + document.RightMargin);

            PdfPCell emptycell = new PdfPCell();
            emptycell.Border = 0;
            footer.AddCell(emptycell);

            Chunk text = new Chunk(string.Format(GlobalStringResource.PageOfFooter,
                document.PageNumber), FontFactory.GetFont(FontFactory.HELVETICA, 8));

            PdfPCell footerCell = new PdfPCell(new Phrase(text));
            footerCell.Border = 0;
            footerCell.HorizontalAlignment = Element.ALIGN_RIGHT;
            footer.AddCell(footerCell);

            PdfPCell cell = new PdfPCell(iTextSharp.text.Image.GetInstance(total));
            cell.Border = 0;
            cell.HorizontalAlignment = Element.ALIGN_LEFT;
            footer.AddCell(cell);
            footer.WriteSelectedRows(0, -1, 50, (document.BottomMargin - 10), writer.DirectContent);
        }
開發者ID:meanprogrammer,項目名稱:sawebreports_migrated,代碼行數:25,代碼來源:Strategy2020ReportBuilder.cs

示例9: Write

 // ---------------------------------------------------------------------------          
 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
         Phrase phrase;
         Chunk chunk;
         foreach (Movie movie in PojoFactory.GetMovies())
         {
             phrase = new Phrase(movie.MovieTitle);
             chunk = new Chunk("\u00a0");
             chunk.SetAnnotation(PdfAnnotation.CreateText(
               writer, null, movie.MovieTitle,
               string.Format(INFO, movie.Year, movie.Duration),
               false, "Comment"
             ));
             phrase.Add(chunk);
             document.Add(phrase);
             document.Add(PojoToElementFactory.GetDirectorList(movie));
             document.Add(PojoToElementFactory.GetCountryList(movie));
         }
     }
 }
開發者ID:kuujinbo,項目名稱:iTextInAction2Ed,代碼行數:29,代碼來源:MovieAnnotations2.cs

示例10: Write

// ===========================================================================
    public void Write(Stream stream) {
      // step 1
      using (Document document = new Document()) {
        // step 2
        PdfWriter.GetInstance(document, stream).InitialLeading = 16;
        // step 3
        document.Open();
        // add the ID in another font
        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD, BaseColor.WHITE);
        // step 4
        using (var c =  AdoDB.Provider.CreateConnection()) {
          c.ConnectionString = AdoDB.CS;
          using (DbCommand cmd = c.CreateCommand()) {
            cmd.CommandText = 
              "SELECT country,id FROM film_country ORDER BY country";
            c.Open();
            using (var r = cmd.ExecuteReader()) {
              while (r.Read()) {
                var country = r.GetString(0);
                var ID = r.GetString(1);
                document.Add(new Chunk(country));
                document.Add(new Chunk(" "));
                Chunk id = new Chunk(ID, font);
                // with a background color
                id.SetBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f);
                // and a text rise
                id.SetTextRise(6);
                document.Add(id);
                document.Add(Chunk.NEWLINE);
              }
            }
          }
        }
      }
    }
開發者ID:,項目名稱:,代碼行數:36,代碼來源:

示例11: Add

 /**
 * Adds an <CODE>Object</CODE> to the <CODE>List</CODE>.
 *
 * @param    o    the object to add.
 * @return true if adding the object succeeded
 */
 public override bool Add(Object o) {
     if (o is ListItem) {
         ListItem item = (ListItem) o;
         Chunk chunk = new Chunk(preSymbol, symbol.Font);
         switch (type ) {
             case 0:
                 chunk.Append(((char)(first + list.Count + 171)).ToString());
                 break;
             case 1:
                 chunk.Append(((char)(first + list.Count + 181)).ToString());
                 break;
             case 2:
                 chunk.Append(((char)(first + list.Count + 191)).ToString());
                 break;
             default:
                 chunk.Append(((char)(first + list.Count + 201)).ToString());
                 break;
         }
         chunk.Append(postSymbol);
         item.ListSymbol = chunk;
         item.SetIndentationLeft(symbolIndent, autoindent);
         item.IndentationRight = 0;
         list.Add(item);
         return true;
     } else if (o is List) {
         List nested = (List) o;
         nested.IndentationLeft = nested.IndentationLeft + symbolIndent;
         first--;
         list.Add(nested);
         return true;
     } else if (o is String) {
         return this.Add(new ListItem((string) o));
     }
     return false;
 }
開發者ID:nicecai,項目名稱:iTextSharp-4.1.6,代碼行數:41,代碼來源:ZapfDingbatsNumberList.cs

示例12: MakeReport

        //        public static SimpleAttendanceList GetInstance(Selection selection,
        //                                                       Rectangle pageSize,
        //                                                       string reportFile) {
        //            
        //            if (instance == null)
        //                instance = new SimpleAttendanceList(selection, pageSize, reportFile);
        //            else {
        //                instance.selection = selection;
        //                instance.reportFile = reportFile;
        //            }
        //            
        //            if (!this.doc.IsOpen())
        //                this.doc.Open();
        //            
        //            return instance;
        //        }
        public override void MakeReport()
        {
            // Subtitle = Event name
            Chunk c = new Chunk(this.selection.Events[0].Name,
                                FontFactory.GetFont(FontFactory.HELVETICA, 14, Font.BOLD));
            Paragraph par = new Paragraph(c);
            par.Alignment = Rectangle.ALIGN_CENTER;

            this.doc.Add(par);

            // List
            Table t = new Table(2);
            t.Border = 0;
            t.DefaultCellBorder = 0;

            Cell cell = new Cell();
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            t.DefaultCell = cell; // Default cell

            Font fuenteTitulo = FontFactory.GetFont(FontFactory.HELVETICA_OBLIQUE, 14, Font.UNDERLINE);

            cell = new Cell();
            Chunk texto = new Chunk("Nombre y Apellido", fuenteTitulo);
            cell.Add(texto);
            t.AddCell(cell);

            cell = new Cell();
            texto = new Chunk("¿Asistió?", fuenteTitulo);
            cell.Add(texto);
            t.AddCell(cell);

            Font fuenteDatos = FontFactory.GetFont(FontFactory.HELVETICA, 10);

            Font fuenteSi = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 10);
            fuenteSi.Color = Color.BLUE;

            Font fuenteNo = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 10);
            fuenteNo.Color = Color.RED;

            foreach (Person p in this.selection.Persons) {
                cell = new Cell();
                texto = new Chunk(p.Name + " " + p.Surname, fuenteDatos);
                cell.Add(texto);
                t.AddCell(cell);

                cell = new Cell();

                if (AttendancesManager.Instance.Attended(p, this.selection.Events[0]))
                    texto = new Chunk("Si", fuenteSi);
                else
                    texto = new Chunk("No", fuenteNo);

                cell.Add(texto);
                t.AddCell(cell);
            }

            this.doc.Add(t);
        }
開發者ID:TheProjecter,項目名稱:zaspe-sharp,代碼行數:74,代碼來源:SimpleAttendanceList.cs

示例13: ResolveDoubleQuotedFontFamily

 public void ResolveDoubleQuotedFontFamily() {
     Tag t = new Tag(null);
     t.CSS["color"] = "#000000";
     t.CSS["font-family"] = "\"Helvetica\"";
     t.CSS["font-size"] = "12pt";
     Chunk c = new Chunk("default text for chunk creation");
     applier.Apply(c, t);
     Assert.AreEqual("Helvetica", c.Font.Familyname);
 }
開發者ID:,項目名稱:,代碼行數:9,代碼來源:

示例14: Text

 public Text(Chunk chunk, IDictionary<String, String> css, IList<int> dx, IList<int> dy) : base(css)
 {
     this.chunk = chunk;
     this.x = 0;
     this.y = 0;
     this.relative = true;
     this.dx = dx;
     this.dy = dy;
 }
開發者ID:,項目名稱:,代碼行數:9,代碼來源:

示例15: SetUp

 public void SetUp() {
     LoggerFactory.GetInstance().SetLogger(new SysoLogger(3));
     t = new Tag(null);
     t.CSS["color"] = "#000000";
     t.CSS["font-family"] = "Helvetica";
     t.CSS["font-size"] = "12pt";
     c = new Chunk("default text for chunk creation");
     applier.Apply(c, t);
 }
開發者ID:,項目名稱:,代碼行數:9,代碼來源:


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