如何使用Aspose.dll在PDF模板中添加Graph占位符和表占位符

时间:2018-01-11 09:10:27

标签: pdf aspose.pdf

如何使用Aspose.dll

在PDF模板中添加Graph占位符和表占位符

请在这方面帮助我。

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码将图表添加到PDF文档:

    // Create Document instance
    Document doc = new Document();

    // Add page to pages collection of PDF file
    Page page = doc.Pages.Add();

    // Create Graph instance
    Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph(100, 400);

    // Add graph object to paragraphs collection of page instance
    page.Paragraphs.Add(graph);

    // Create Rectangle instance
    Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle(100, 100, 200, 120);

    // Specify fill color for Graph object
    rect.GraphInfo.FillColor = Aspose.Pdf.Color.Red;

    // Add rectangle object to shapes collection of Graph object
    graph.Shapes.Add(rect);

    dataDir = dataDir + "CreateFilledRectangle_out.pdf";
    // Save PDF file
    doc.Save(dataDir);

并且,您可以使用以下代码在PDF文档中添加表格:

    // Create Document instance
    Aspose.Pdf.Document doc = new Aspose.Pdf.Document();

    // Add page to pages collection of PDF file
    Page page = doc.Pages.Add();

    // Initializes a new instance of the Table
    Aspose.Pdf.Table table = new Aspose.Pdf.Table();

    // Set the table border color as LightGray
    table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));

    // Set the border for table cells
    table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));

    // Create a loop to add 10 rows
    for (int row_count = 1; row_count < 10; row_count++)
    {
        // Add row to table
        Aspose.Pdf.Row row = table.Rows.Add();

        // Add table cells
        row.Cells.Add("Column (" + row_count + ", 1)");
        row.Cells.Add("Column (" + row_count + ", 2)");
        row.Cells.Add("Column (" + row_count + ", 3)");
    }

    // Add table object to first page of document
    doc.Pages[1].Paragraphs.Add(table);

    dataDir = dataDir + "document_with_table_out.pdf";
    // Save updated document containing table object
    doc.Save(dataDir);

您可以访问以下链接,了解有关这些主题的更多信息。

P.S:我使用Aspose作为开发者布道者。