itext7 добавление фигур и текста - PullRequest
0 голосов
/ 16 июня 2020

Можно ли создать комбинацию формы и текста в itext7, как в ссылке ниже:

Я создал таблицу с 3 ячейками и создал горизонтальную линию.

private Table AverageTable()
{
    float[] widths = new float[] { 30f,1.125f,30f };
    Table planTable = new Table(UnitValue.CreatePointArray(widths));

    PdfFont TaubRegular = PdfFontFactory.CreateFont(System.IO.Path.Combine(ConfigurationManager.AppSettings["FontsLocation"], "TaubSans-Regular.ttf"), PdfEncodings.IDENTITY_H, true);

    SolidLine line = new SolidLine(.5f);
    line.SetColor(new DeviceCmyk(59, 66, 0, 0));
    LineSeparator ls = new LineSeparator(line);

    Cell cellPlanInvestmentsHeading = new Cell()
      .Add(new Paragraph("Average Annual Total Returns(NAV)").SetFixedLeading(8))
      .SetFont(PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN))
      .SetFontSize(7.5f)
      .SetFontColor(new DeviceCmyk(59, 66, 0, 0))
      .SetBackgroundColor(DeviceGray.WHITE)
      .SetTextAlignment(TextAlignment.LEFT)
      .SetVerticalAlignment(VerticalAlignment.TOP).SetPaddingRight(0f).SetMarginRight(0f);


    Cell cellIcon = new Cell().Add(ls)
        .SetHorizontalAlignment(HorizontalAlignment.LEFT)
        .SetVerticalAlignment(VerticalAlignment.MIDDLE)
        .SetPaddingTop(5f);

    planTable.AddCell(cellIcon);
    planTable.AddCell(cellPlanInvestmentsHeading);
    planTable.AddCell(cellIcon);
    return planTable;
}

1 Ответ

0 голосов
/ 18 июня 2020

Вы можете достичь желаемого результата следующим образом:

private Table AverageTable()
{
    float[] widths = new float[] { 10, 70, 10 };
    Table planTable = new Table(UnitValue.CreatePointArray(widths));

    SolidLine line = new SolidLine(.5f);
    line.SetColor(new DeviceCmyk(59, 66, 0, 0));

    Cell cell = new Cell().SetBorderLeft(Border.NO_BORDER).SetBorderRight(Border.NO_BORDER)
        .SetBorderTop(Border.NO_BORDER);
    Paragraph p = new Paragraph("Average Annual Total Returns(NAV)").SetFixedLeading(8)
        .SetFont(PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN))
        .SetTextAlignment(TextAlignment.CENTER)
        .SetFontSize(7.5f)
        .SetRelativePosition(0, -10, 0, 0);
    cell.Add(p);

    planTable.AddCell(new Cell().SetBorderRight(Border.NO_BORDER));
    planTable.AddCell(cell);
    planTable.AddCell(new Cell().SetBorderLeft(Border.NO_BORDER));
    return planTable;
}

Основной трюк, который выполняет здесь свою работу, - SetRelativePosition - он применяет дополнительное преобразование на этапе рисования.

Визуальный результат:

result

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...