当前位置: 首页>>代码示例>>C#>>正文


C# Document.Add方法代码示例

本文整理汇总了C#中iTextSharp.text.Document.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Add方法的具体用法?C# Document.Add怎么用?C# Document.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在iTextSharp.text.Document的用法示例。


在下文中一共展示了Document.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreatePdf

        public override byte[] CreatePdf(List<PdfContentParameter> contents, string[] images, int type)
        {
            var document = new Document();
            float docHeight = document.PageSize.Height - heightOffset;
            document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
            document.SetMargins(50, 50, 10, 40);

            var output = new MemoryStream();
            var writer = PdfWriter.GetInstance(document, output);

            writer.PageEvent = new HeaderFooterHandler(type);

            document.Open();

            document.Add(contents[0].Table);

            for (int i = 0; i < images.Length; i++)
            {
                document.NewPage();
                float subtrahend = document.PageSize.Height - heightOffset;
                iTextSharp.text.Image pool = iTextSharp.text.Image.GetInstance(images[i]);
                pool.Alignment = 3;
                pool.ScaleToFit(document.PageSize.Width - (document.RightMargin * 2), subtrahend);
                //pool.ScaleAbsolute(document.PageSize.Width - (document.RightMargin * 2), subtrahend);
                document.Add(pool);
            }

            document.Close();
            return output.ToArray();
        }
开发者ID:meanprogrammer,项目名称:sawebreports_migrated,代码行数:30,代码来源:GenericPDFBuilderStrategy.cs

示例2: Write

        public void Write(string outputPath, FlowDocument doc)
        {
            Document pdfDoc = new Document(PageSize.A4, 50, 50, 50, 50);
            Font textFont = new Font(baseFont, DEFAULT_FONTSIZE, Font.NORMAL, BaseColor.BLACK);
            Font headingFont = new Font(baseFont, DEFAULT_HEADINGSIZE, Font.BOLD, BaseColor.BLACK);
            using (FileStream stream = new FileStream(outputPath, FileMode.Create))
            {
                PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream);
                pdfDoc.Open();
                foreach (Block i in doc.Blocks) {
                    if (i is System.Windows.Documents.Paragraph)
                    {
                        TextRange range = new TextRange(i.ContentStart, i.ContentEnd);
                        Console.WriteLine(i.Tag);
                        switch (i.Tag as string)
                        {
                            case "Paragraph": iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph(range.Text, textFont);
                                par.Alignment = Element.ALIGN_JUSTIFIED;
                                              pdfDoc.Add(par);
                                              break;
                            case "Heading": iTextSharp.text.Paragraph head = new iTextSharp.text.Paragraph(range.Text, headingFont);
                                              head.Alignment = Element.ALIGN_CENTER;
                                              head.SpacingAfter = 10;
                                              pdfDoc.Add(head);
                                              break;
                            default:          iTextSharp.text.Paragraph def = new iTextSharp.text.Paragraph(range.Text, textFont);
                                              def.Alignment = Element.ALIGN_JUSTIFIED;
                                              pdfDoc.Add(def);
                                              break;

                        }
                    }
                    else if (i is System.Windows.Documents.List)
                    {
                        iTextSharp.text.List list = new iTextSharp.text.List(iTextSharp.text.List.UNORDERED, 10f);
                        list.SetListSymbol("\u2022");
                        list.IndentationLeft = 15f;
                        foreach (var li in (i as System.Windows.Documents.List).ListItems)
                        {
                            iTextSharp.text.ListItem listitem = new iTextSharp.text.ListItem();
                            TextRange range = new TextRange(li.Blocks.ElementAt(0).ContentStart, li.Blocks.ElementAt(0).ContentEnd);
                            string text = range.Text.Substring(1);
                            iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph(text, textFont);
                            listitem.SpacingAfter = 10;
                            listitem.Add(par);
                            list.Add(listitem);
                        }
                        pdfDoc.Add(list);
                    }

               }
                if (pdfDoc.PageNumber == 0)
                {
                    iTextSharp.text.Paragraph par = new iTextSharp.text.Paragraph(" ");
                    par.Alignment = Element.ALIGN_JUSTIFIED;
                    pdfDoc.Add(par);
                }
               pdfDoc.Close();
            }
        }
开发者ID:drdaemos,项目名称:ODTCONVERTvs10,代码行数:60,代码来源:PDFWriter.cs

示例3: Write

 // ---------------------------------------------------------------------------
 public void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         BaseFont bf;
         Font font;
         for (int i = 0; i < 3; i++)
         {
             bf = BaseFont.CreateFont(
               MOVIES[i][0], MOVIES[i][1], BaseFont.NOT_EMBEDDED
             );
             font = new Font(bf, 12);
             document.Add(new Paragraph(bf.PostscriptFontName, font));
             for (int j = 2; j < 5; j++)
             {
                 document.Add(new Paragraph(MOVIES[i][j], font));
             }
             document.Add(Chunk.NEWLINE);
         }
     }
 }
开发者ID:kuujinbo,项目名称:iTextInAction2Ed,代码行数:28,代码来源:CJKExample.cs

示例4: Write

 // ===========================================================================
 public void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter.GetInstance(document, stream);
         document.SetPageSize(PageSize.A5);
         document.SetMargins(36, 72, 108, 180);
         document.SetMarginMirroring(true);
         // step 3
         document.Open();
         // step 4
         document.Add(new Paragraph(
           "The left margin of this odd page is 36pt (0.5 inch); " +
           "the right margin 72pt (1 inch); " +
           "the top margin 108pt (1.5 inch); " +
           "the bottom margin 180pt (2.5 inch).")
         );
         Paragraph paragraph = new Paragraph();
         paragraph.Alignment = Element.ALIGN_JUSTIFIED;
         for (int i = 0; i < 20; i++)
         {
             paragraph.Add("Hello World! Hello People! " +
             "Hello Sky! Hello Sun! Hello Moon! Hello Stars!"
             );
         }
         document.Add(paragraph);
         document.Add(new Paragraph(
           "The right margin of this even page is 36pt (0.5 inch); " +
           "the left margin 72pt (1 inch).")
         );
     }
 }
开发者ID:kuujinbo,项目名称:iTextInAction2Ed,代码行数:35,代码来源:HelloWorldMirroredMargins.cs

示例5: VerticalPositionTest0

        public void VerticalPositionTest0() {
            String file = "vertical_position.pdf";

            Document document = new Document();
            PdfWriter writer = PdfWriter.GetInstance(document, File.Create(OUTPUT_FOLDER + file));
            document.Open();

            writer.PageEvent = new CustomPageEvent();

            PdfPTable table = new PdfPTable(2);
            for (int i = 0; i < 100; i++) {
                table.AddCell("Hello " + i);
                table.AddCell("World " + i);
            }

            document.Add(table);

            document.NewPage();

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 1000; i++) {
                sb.Append("some more text ");
            }
            document.Add(new Paragraph(sb.ToString()));

            document.Close();

            // compare
            CompareTool compareTool = new CompareTool();
            String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER + file, TEST_RESOURCES_PATH + file,
                OUTPUT_FOLDER, "diff");
            if (errorMessage != null) {
                Assert.Fail(errorMessage);
            }
        }
开发者ID:newlysoft,项目名称:itextsharp,代码行数:35,代码来源:VerticalPositionTest.cs

示例6: CreatePDF

        private void CreatePDF()
        {
            MemoryStream MStream = new MemoryStream();
            Document document = new Document(PageSize.A4, 80, 50, 30, 65);
            try
            {
                PdfWriter writer = PdfWriter.GetInstance(document, MStream);
                document.Open();
                document.Add(new iTextSharp.text.Paragraph("This is test and must work"));
                string h = "<a>dsfdfsdf</a><br><br><h1>sdfsdfsd</h1>";
                TextReader sReader = new StringReader(h);
                List<IElement> l = HTMLWorker.ParseToList(sReader,new StyleSheet());

                foreach (IElement i  in l)
                {
                    document.Add(i);
                }

                document.Close();
            }
            catch (Exception e)
            {
                throw e;
            }

            //stampo pdf
            Response.Buffer = true;
            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-Disposition", "attachment;filename=myPDFNew.pdf");
            Response.BinaryWrite(MStream.GetBuffer());
            Response.End();
        }
开发者ID:caspandre,项目名称:aptportal,代码行数:34,代码来源:pdfTest.aspx.cs

示例7: Write

 // ---------------------------------------------------------------------------
 public void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         document.Add(new Paragraph(
           "Movies featuring River Phoenix", FilmFonts.BOLD
         ));
         document.Add(CreateParagraph(
           "My favorite movie featuring River Phoenix was ", "0092005"
         ));
         document.Add(CreateParagraph(
           "River Phoenix was nominated for an academy award for his role in ", "0096018"
         ));
         document.Add(CreateParagraph(
           "River Phoenix played the young Indiana Jones in ", "0097576"
         ));
         document.Add(CreateParagraph(
           "His best role was probably in ", "0102494"
         ));
     }
 }
开发者ID:kuujinbo,项目名称:iTextInAction2Ed,代码行数:28,代码来源:RiverPhoenix.cs

示例8: Write

 // ===========================================================================
 public void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         PdfPTable table = CreateTable1();
         document.Add(table);
         table = CreateTable2();
         table.SpacingBefore = 5;
         table.SpacingAfter = 5;
         document.Add(table);
         table = CreateTable3();
         document.Add(table);
         table = CreateTable4();
         table.SpacingBefore = 5;
         table.SpacingAfter = 5;
         document.Add(table);
         table = CreateTable5();
         document.Add(table);
     }
 }
开发者ID:kuujinbo,项目名称:iTextInAction2Ed,代码行数:27,代码来源:ColumnWidths.cs

示例9: CreateDocument

		public void CreateDocument( List< ScanDetails > info, string path )
		{
			var doc = new Document( PageSize.A4 );
			PdfWriter.GetInstance( doc, new FileStream( path, FileMode.Create ) );

			doc.Open();
			doc.Add( new Paragraph() );

			PdfPTable table = new PdfPTable( 4 ) { WidthPercentage = 100 };
			//header
			PdfPCell cell = new PdfPCell { BackgroundColor = BaseColor.LIGHT_GRAY, Phrase = new Phrase( "URL" ) };
			table.AddCell( cell );

			cell.Phrase = new Phrase( "Response" );
			table.AddCell( cell );

			cell.Phrase = new Phrase( "Size" );
			table.AddCell( cell );

			cell.Phrase = new Phrase( "Page Title" );
			table.AddCell( cell );

			//rows
			foreach( var item in info )
			{
				table.AddCell( item.Url.ToString() );
				table.AddCell( item.Response );
				table.AddCell( item.Size.ToString() );
				table.AddCell( item.PageTitle );
			}

			doc.Add( table );

			doc.Close();
		}
开发者ID:faisal82,项目名称:swat-web-security-scanner,代码行数:35,代码来源:AgReportBuilder.cs

示例10: TestIncompleteTableAdd

        public virtual void TestIncompleteTableAdd() {
            const String file = "incomplete_add.pdf";

            Document document = new Document(PageSize.LETTER);
            PdfWriter.GetInstance(document, new FileStream(OUTPUT_FOLDER + file, FileMode.OpenOrCreate));

            document.Open();
            PdfPTable table = new PdfPTable(5);
            table.HeaderRows = 1;
            table.SplitRows = false;
            table.Complete = false;

            for (int i = 0; i < 5; i++) {
                table.AddCell("Header " + i);
            }

            for (int i = 0; i < 500; i++) {
                if (i % 5 == 0) {
                    document.Add(table);
                }

                table.AddCell("Test " + i);
            }

            table.Complete = true;
            document.Add(table);
            document.Close();

            CompareTablePdf(file);
        }
开发者ID:Niladri24dutta,项目名称:itextsharp,代码行数:30,代码来源:LargeTableTest.cs

示例11: TestNoChangeInSetSkipFirstHeader

        public virtual void TestNoChangeInSetSkipFirstHeader() {
            Document document = new Document();
            Stream stream = new MemoryStream();
            PdfWriter writer = PdfWriter.GetInstance(document, stream);
            document.Open();

            PdfPTable table = new PdfPTable(5);
            table.HeaderRows = 1;
            table.SplitRows = false;
            table.Complete = false;

            for (int i = 0; i < 5; ++i) {
                table.AddCell("Header " + i);
            }

            table.AddCell("Cell 1");

            document.Add(table);

            Assert.False(table.SkipFirstHeader);

            table.Complete = true;

            for (int i = 1; i < 5; i++) {
                table.AddCell("Cell " + i);
            }

            document.Add(table);

            document.Close();
            stream.Close();
        }
开发者ID:Niladri24dutta,项目名称:itextsharp,代码行数:32,代码来源:LargeTableTest.cs

示例12: 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

示例13: GeneratePdfReport

        public static void GeneratePdfReport(string filepath)
        {
            FileStream fileStream = new FileStream(filepath, FileMode.Create);
            Document document = new Document();
            PdfWriter writer = PdfWriter.GetInstance(document, fileStream);
            document.SetPageSize(PageSize.A3);
            document.Open();

            var paragraph = new Paragraph("Aggregated Sales Report",
                FontFactory.GetFont("Arial", 19, Font.BOLD));
            paragraph.SpacingAfter = 20.0f;
            paragraph.Alignment = 1;

            document.Add(paragraph);

            PdfPTable mainTable = new PdfPTable(1);
            var reports = GetDayReports();
            foreach (var dayReport in reports)
            {
                var headerCell = new PdfPCell(new Phrase("Date: " + dayReport.FormattedDate));
                headerCell.BackgroundColor = new BaseColor(175, 166, 166);
                mainTable.AddCell(headerCell);
                var table = GenerateReportTable(dayReport);
                mainTable.AddCell(table);
            }

            document.Add(mainTable);
            document.Close();
        }
开发者ID:NikolayKostadinov,项目名称:TelerikAkademy,代码行数:29,代码来源:PdfReportGenerator.cs

示例14: Write

// ===========================================================================
    public void Write(Stream stream) {
      // step 1
      using (Document document = new Document()) {
        // step 2
        PdfWriter.GetInstance(document, stream);
        // step 3
        document.Open();
        // step 4
        // Image in colorspace DeviceGray
        byte[] gradient = new byte[256];
        for (int i = 0; i < 256; i++) {
          gradient[i] = (byte) i;
        }
        Image img1 = Image.GetInstance(256, 1, 1, 8, gradient);
        img1.ScaleAbsolute(256, 50);
        document.Add(img1);
        // Image in colorspace RGB
        byte[] cgradient = new byte[256 * 3];
        for (int i = 0; i < 256; i++) {
          cgradient[i * 3] = (byte) (255 - i);
          cgradient[i * 3 + 1] = (byte) (255 - i);
          cgradient[i * 3 + 2] = (byte) i;
        }
        Image img2 = Image.GetInstance(256, 1, 3, 8, cgradient);
        img2.ScaleAbsolute(256, 50);
        document.Add(img2);
        Image img3 = Image.GetInstance(16, 16, 3, 8, cgradient);
        img3.ScaleAbsolute(64, 64);
        document.Add(img3);
      }
    }
开发者ID:kuujinbo,项目名称:iTextInAction2Ed,代码行数:32,代码来源:RawImage.cs

示例15: buildPDF

    /// <summary>
    /// Costruisce e spedisce PDF con lettera corrente
    /// </summary>
    protected void buildPDF()
    {
        string fileName = "Visita " + DALRuntime.getNomePazienteConSaluto(DALRuntime.IdMQuest) +  ".pdf";
        fileName = fileName.Replace(' ', '_');
        Document pdfDoc = new Document();

        this.Response.Clear();
        this.Response.AddHeader("content-disposition", string.Format("attachment;filename={0}", System.IO.Path.GetFileName(fileName)));
        this.Response.ContentType = "application/pdf";

        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        // Aggiunge l'intestazione dell'utente
        string sIntestazione = DALRuntime.getTestata();
        // Definisce un font piu' piccolo
        BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, true);
        Font ftTimes10Italic = new Font(bfTimes, 10, Font.ITALIC);
        Paragraph pIntestazione = new Paragraph(sIntestazione, ftTimes10Italic);
        pdfDoc.Add(pIntestazione);
        Font ftTimes10Normal = new Font(bfTimes, 10, Font.NORMAL);
        string sLettera = memLettera.Text;
        Paragraph pBody = new Paragraph(sLettera, ftTimes10Normal);
        pdfDoc.Add(pBody);
        pdfDoc.Close();
        this.Response.Flush();
        this.Response.End();
    }
开发者ID:nicofari,项目名称:emma,代码行数:30,代码来源:FmLettera.aspx.cs


注:本文中的iTextSharp.text.Document.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。