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


C# pdf.PdfPTable類代碼示例

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


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

示例1: GenerateRow

        private static void GenerateRow(PdfPTable table, PlayerInfo player, Font font, BaseColor backgroundColor)
        {
            var jpg = Image.GetInstance(player.PictureUrl);
            table.AddCell(jpg);

            PdfPCell cell;

            cell = new PdfPCell(new Phrase(player.JerseyNumber, font)) {BackgroundColor = backgroundColor};
            table.AddCell(cell);

            cell = new PdfPCell(new Phrase(player.Name, font)) {BackgroundColor = backgroundColor};
            table.AddCell(cell);

            if (table.NumberOfColumns == NumberColsWithPosition)
            {
                cell = new PdfPCell(new Phrase(player.Position, font)) {BackgroundColor = backgroundColor};
                table.AddCell(cell);
            }

            cell = new PdfPCell(new Phrase(player.Height, font)) {BackgroundColor = backgroundColor};
            table.AddCell(cell);

            cell = new PdfPCell(new Phrase(player.Weight, font)) {BackgroundColor = backgroundColor};
            table.AddCell(cell);

            cell = new PdfPCell(new Phrase(player.DateOfBirth, font)) {BackgroundColor = backgroundColor};
            table.AddCell(cell);

            cell = new PdfPCell(new Phrase(player.Age, font)) {BackgroundColor = backgroundColor};
            table.AddCell(cell);

            cell = new PdfPCell(new Phrase(player.BirthPlace, font)) {BackgroundColor = backgroundColor};
            table.AddCell(cell);
        }
開發者ID:ColinStranc,項目名稱:MockDraftAnalysis,代碼行數:34,代碼來源:PdfGenerator.cs

示例2: 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,代碼來源:

示例3: Write

// ---------------------------------------------------------------------------
    public void Write(Stream stream) {
      // step 1
      using (Document document = new Document(PageSize.A5.Rotate())) {
        // step 2
        PdfWriter writer = PdfWriter.GetInstance(document, stream);
        writer.PdfVersion = PdfWriter.VERSION_1_5;
        writer.ViewerPreferences = PdfWriter.PageModeFullScreen;
        writer.PageEvent = new TransitionDuration();        
        // step 3
        document.Open();
        // step 4
        IEnumerable<Movie> movies = PojoFactory.GetMovies();
        Image img;
        PdfPCell cell;
        PdfPTable table = new PdfPTable(6);
        string RESOURCE = Utility.ResourcePosters;
        foreach (Movie movie in movies) {
          img = Image.GetInstance(Path.Combine(RESOURCE, movie.Imdb + ".jpg"));
          cell = new PdfPCell(img, true);
          cell.Border = PdfPCell.NO_BORDER;
          table.AddCell(cell);
        }
        document.Add(table);
      }
    }
開發者ID:,項目名稱:,代碼行數:26,代碼來源:

示例4: GeneratePDFReport

        // to generate the report call the GeneratePDFReport static method.
        // The pdf file will be generated in the SupermarketChain.ConsoleClient folder
        // TODO measures are missing
        // TODO code refactoring to limitr repeated chunks
        public static void GeneratePDFReport()
        {
            Document doc = new Document(iTextSharp.text.PageSize.A4, 10, 10, 40, 35);
            string filePath = @"..\..\..\..\Reports\salesReports.pdf";
            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(filePath, FileMode.Create));
            doc.Open();
            PdfPTable table = new PdfPTable(5);

            Font verdana = FontFactory.GetFont("Verdana", 16, Font.BOLD);
            Font verdana2 = FontFactory.GetFont("Verdana", 12, Font.BOLD);

            PdfPCell header = new PdfPCell(new Phrase("Aggregated Sales Report", verdana));
            header.Colspan = 5;
            header.HorizontalAlignment = 1;
            table.AddCell(header);

            double totalSales = PourReportData(table);

            PdfPCell totalSum = new PdfPCell(new Phrase("Grand total:"));
            totalSum.Colspan = 4;
            totalSum.HorizontalAlignment = 2;
            totalSum.BackgroundColor = new BaseColor(161, 212, 224);
            table.AddCell(totalSum);

            PdfPCell totalSumNumber = new PdfPCell(new Phrase(String.Format("{0:0.00}", totalSales), verdana));
            totalSumNumber.BackgroundColor = new BaseColor(161, 212, 224);
            table.AddCell(totalSumNumber);

            doc.Add(table);
            doc.Close();

            DirectoryInfo directoryInfo = new DirectoryInfo(filePath);
            Console.WriteLine("Pdf report generated.");
            Console.WriteLine("File:  {0}", directoryInfo.FullName);
        }
開發者ID:TeamMingFern,項目名稱:DatabaseApplicationsTeamwork,代碼行數:39,代碼來源:PDFGenerator.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: Write

 // ---------------------------------------------------------------------------
 public void Write(Stream stream)
 {
     // Use old example to create PDF
     MovieTemplates mt = new MovieTemplates();
     byte[] pdf = Utility.PdfBytes(mt);
     using (ZipFile zip = new ZipFile())
     {
         using (MemoryStream ms = new MemoryStream())
         {
             // step 1
             using (Document document = new Document())
             {
                 // step 2
                 PdfWriter writer = PdfWriter.GetInstance(document, ms);
                 // step 3
                 document.Open();
                 // step 4
                 PdfPTable table = new PdfPTable(2);
                 PdfReader reader = new PdfReader(pdf);
                 int n = reader.NumberOfPages;
                 PdfImportedPage page;
                 for (int i = 1; i <= n; i++)
                 {
                     page = writer.GetImportedPage(reader, i);
                     table.AddCell(Image.GetInstance(page));
                 }
                 document.Add(table);
             }
             zip.AddEntry(RESULT, ms.ToArray());
         }
         zip.AddEntry(Utility.ResultFileName(mt.ToString() + ".pdf"), pdf);
         zip.Save(stream);
     }
 }
開發者ID:kuujinbo,項目名稱:iTextInAction2Ed,代碼行數:35,代碼來源:ImportingPages1.cs

示例7: GetTable

// ---------------------------------------------------------------------------
    /**
     * Creates a table with film festival screenings.
     * @param day a film festival day
     * @return a table with screenings.
     */
    public PdfPTable GetTable(string day) {
      PdfPTable table = new PdfPTable(new float[] { 2, 1, 2, 5, 1 });
      table.WidthPercentage = 100f;
      table.DefaultCell.Padding = 3;
      table.DefaultCell.UseAscender = true;
      table.DefaultCell.UseDescender = true;
      table.DefaultCell.Colspan = 5;
      table.DefaultCell.BackgroundColor = BaseColor.RED;
      table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
      table.AddCell(day);
      table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
      table.DefaultCell.Colspan = 1;
      table.DefaultCell.BackgroundColor = BaseColor.ORANGE;
      for (int i = 0; i < 2; i++) {
        table.AddCell("Location");
        table.AddCell("Time");
        table.AddCell("Run Length");
        table.AddCell("Title");
        table.AddCell("Year");
      }
      table.DefaultCell.BackgroundColor = null;
      table.HeaderRows = 3;
      table.FooterRows = 1;
      List<Screening> screenings = PojoFactory.GetScreenings(day);
      Movie movie;
      foreach (Screening screening in screenings) {
        movie = screening.movie;
        table.AddCell(screening.Location);
        table.AddCell(screening.Time.Substring(0, 5));
        table.AddCell(movie.Duration.ToString() + " '");
        table.AddCell(movie.MovieTitle);
        table.AddCell(movie.Year.ToString());
      }
      return table;
    }
開發者ID:,項目名稱:,代碼行數:41,代碼來源:

示例8: AddRow

 private void AddRow(PdfPTable table, ExpenseTableRow dataRow)
 {
     table.AddCell(new Paragraph(dataRow.Cost, FontFactory.GetFont(BaseFont.COURIER, BaseFont.CP1257, 10)));
     table.AddCell(new Paragraph(dataRow.Date, FontFactory.GetFont(BaseFont.COURIER, BaseFont.CP1257, 10)));
     table.AddCell(new Paragraph(dataRow.Paid, FontFactory.GetFont(BaseFont.COURIER, BaseFont.CP1257, 10)));
     table.AddCell(new Paragraph(dataRow.ResposiblePerson, FontFactory.GetFont(BaseFont.COURIER, BaseFont.CP1257, 10)));
 }
開發者ID:Quantzo,項目名稱:baudi,代碼行數:7,代碼來源:ExpenseReport.cs

示例9: TestKeepTogether

 public void TestKeepTogether(bool tagged, bool keepTogether) {
     Document document = new Document();
     String file = "tagged_" + tagged + "-keeptogether_" + keepTogether + ".pdf";
     PdfWriter writer = PdfWriter.GetInstance(document, File.Create(outFolder + file));
     if (tagged)
         writer.SetTagged();
     document.Open();
     int columns = 3;
     int tables = 3;
     for (int tableCount = 0; tableCount < tables; tableCount++) {
         PdfPTable table = new PdfPTable(columns);
         for (int rowCount = 0; rowCount < 50; rowCount++) {
             PdfPCell cell1 = new PdfPCell(new Paragraph("t" + tableCount + " r:" + rowCount));
             PdfPCell cell2 = new PdfPCell(new Paragraph("t" + tableCount + " r:" + rowCount));
             PdfPCell cell3 = new PdfPCell(new Paragraph("t" + tableCount + " r:" + rowCount));
             table.AddCell(cell1);
             table.AddCell(cell2);
             table.AddCell(cell3);
         }
         table.SpacingAfter = 10f;
         table.KeepTogether = keepTogether;
         document.Add(table);
     }
     document.Close();
 }
開發者ID:Niladri24dutta,項目名稱:itextsharp,代碼行數:25,代碼來源:KeepTogetherTest.cs

示例10: CreatePdf

 public void CreatePdf(String dest)
 {
     Document document = new Document();
     PdfWriter.GetInstance(document, new FileStream(dest, FileMode.Create));
     document.Open();
     PdfPTable table = new PdfPTable(5);
     table.SetWidths(new int[] {1, 2, 2, 2, 1});
     PdfPCell cell;
     cell = new PdfPCell(new Phrase("S/N"));
     cell.Rowspan = 2;
     table.AddCell(cell);
     cell = new PdfPCell(new Phrase("Name"));
     cell.Colspan = 3;
     table.AddCell(cell);
     cell = new PdfPCell(new Phrase("Age"));
     cell.Rowspan = 2;
     table.AddCell(cell);
     table.AddCell("SURNAME");
     table.AddCell("FIRST NAME");
     table.AddCell("MIDDLE NAME");
     table.AddCell("1");
     table.AddCell("James");
     table.AddCell("Fish");
     table.AddCell("Stone");
     table.AddCell("17");
     document.Add(table);
     document.Close();
 }
開發者ID:Niladri24dutta,項目名稱:itextsharp,代碼行數:28,代碼來源:SimpleRowColspan.cs

示例11: GenerateReportTable

        private static PdfPTable GenerateReportTable(DayReport report)
        {
            PdfPTable table = new PdfPTable(5);
            
            string[] headerTitles = {"Product", "Quantity", "Unit Price", "Location", "Sum"};
            foreach (var title in headerTitles)
            {
                Phrase phrase = new Phrase(title);
                phrase.Font = FontFactory.GetFont("Arial", 14, Font.BOLD);
                PdfPCell cell = new PdfPCell(phrase);
                cell.BackgroundColor = new BaseColor(175, 166, 166);
                table.AddCell(cell);
                cell.Padding = 0;
            }

            foreach (var sale in report.Sales)
            {
                table.AddCell(sale.ProductName);
                table.AddCell(sale.MeasureFormatted);
                table.AddCell(sale.UnitPrice.ToString());
                table.AddCell(sale.Supermarket);
                table.AddCell(sale.Sum.ToString());
            }

            PdfPCell footerCell = new PdfPCell(new Phrase("Total sum for " + report.FormattedDate + ": "));
            footerCell.Colspan = 4;
            footerCell.HorizontalAlignment = 2;
            table.AddCell(footerCell);
            table.AddCell(new Phrase(report.TotalSum.ToString()));
            return table;
        }
開發者ID:NikolayKostadinov,項目名稱:TelerikAkademy,代碼行數:31,代碼來源:PdfReportGenerator.cs

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

示例13: CreateHardwareReport

 public static void CreateHardwareReport(string fileName, IEnumerable<HardwareCountReport> hardwares)
 {
     try
     {
         Document document = new Document(PageSize.A4, 72, 72, 72, 72);
         PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None));
         document.Open();
         document.Add(new Paragraph(Element.ALIGN_CENTER, "Hardware Report", new Font(iTextSharp.text.Font.FontFamily.HELVETICA, 16, Font.BOLD)));
         document.Add(new Chunk(Chunk.NEWLINE));
         var table = new PdfPTable(3);
         table.SetTotalWidth(new float[] { 25f, 50f, 25f });
         table.WidthPercentage = 100;
         table.AddCell(new Phrase("Category"));
         table.AddCell(new Phrase("Hardware Model/Type"));
         table.AddCell(new Phrase("Total"));
         foreach (var hw in hardwares)
         {
             table.AddCell(new Phrase(hw.Category));
             table.AddCell(new Phrase(hw.Model));
             table.AddCell(new Phrase(hw.Count));
         }
         document.Add(table);
         document.Close();
     }
     catch (Exception x)
     {
         Log.Error("Error when creating report.", x);
     }
 }
開發者ID:rabbicse,項目名稱:WPF-SBMS,代碼行數:29,代碼來源:ReportGenerator.cs

示例14: Button2_Click

    protected void Button2_Click(object sender, EventArgs e)
    {
        int columnsCount = GridView1.HeaderRow.Cells.Count;
        // Create the PDF Table specifying the number of columns
        PdfPTable pdfTable = new PdfPTable(columnsCount);

        // Loop thru each cell in GrdiView header row
        foreach(TableCell gridViewHeaderCell in GridView1.HeaderRow.Cells)
        {
        // Create the Font Object for PDF document
        Font font = new Font();
        // Set the font color to GridView header row font color
        font.Color = new BaseColor(GridView1.HeaderStyle.ForeColor);

        // Create the PDF cell, specifying the text and font
        PdfPCell pdfCell = new PdfPCell(new Phrase(gridViewHeaderCell.Text, font));

        // Set the PDF cell backgroundcolor to GridView header row BackgroundColor color
        pdfCell.BackgroundColor = new BaseColor(GridView1.HeaderStyle.BackColor);

        // Add the cell to PDF table
        pdfTable.AddCell(pdfCell);
        }

        // Loop thru each datarow in GrdiView
        foreach (GridViewRow gridViewRow in GridView1.Rows)
        {
        if (gridViewRow.RowType == DataControlRowType.DataRow)
        {
            // Loop thru each cell in GrdiView data row
            foreach (TableCell gridViewCell in gridViewRow.Cells)
            {
                Font font = new Font();
                font.Color = new BaseColor(GridView1.RowStyle.ForeColor);

                PdfPCell pdfCell = new PdfPCell(new Phrase(gridViewCell.Text, font));

                pdfCell.BackgroundColor = new BaseColor(GridView1.RowStyle.BackColor);

                pdfTable.AddCell(pdfCell);
            }
        }
        }

        // Create the PDF document specifying page size and margins
        Document pdfDocument = new Document(PageSize.A4, 10f, 10f, 10f, 10f);

        PdfWriter.GetInstance(pdfDocument, Response.OutputStream);

        pdfDocument.Open();
        pdfDocument.Add(pdfTable);
        pdfDocument.Close();

        Response.ContentType = "application/pdf";
        Response.AppendHeader("content-disposition",
        "attachment;filename=Employees.pdf");
        Response.Write(pdfDocument);
        Response.Flush();
        Response.End();
    }
開發者ID:wandilediba,項目名稱:Asset-App,代碼行數:60,代碼來源:Default.aspx.cs

示例15: writePdf

        public override void writePdf(bool bBlackAndWhite=false)
        {
            initFile();
            PdfPTable table = new PdfPTable(m_iCount + 1);
            int cellHeight = ((int)m_doc.PageSize.Height - 200) / m_iCount;
            iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance("");
            image.ScaleAbsolute(cellHeight / 2, cellHeight / 2);
            for (int j = 0; j < m_iCount; j++)
            {
                int cnt = s_random.Next(1, m_iMax);

                for (int i = 0; i < m_iMax; i++)
                {
                    if (i < cnt)
                    {
                        table.AddCell(image);
                    }
                    else
                    {
                        table.AddCell(new Phrase(" "));
                    }

                }

                table.AddCell(rectangle);

            }
            m_doc.Add(table);

            printSiteName();
            m_doc.Close();
        }
開發者ID:mangalambigai,項目名稱:WorksheetGen,代碼行數:32,代碼來源:CountingWorksheet.cs


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