0

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

请在这方面帮助我。

4

1 回答 1

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);

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

PS:我与 Aspose 一起担任开发人员宣传员。

于 2018-01-11T22:04:14.360 回答