Search code examples
c#canvasitextitext7

iText7 rectangle moves not the correct way


I have rotated paragraph. That paragraph is in rectangle that appears in xy point, but it GROWING DOWN.
HERE

I want this rectangle to GROW UP like here
THIS

Here is my code.

        Canvas canvas = new Canvas(pdfCanvas, new Rectangle(
                 float.Parse(_xJobID, CultureInfo.InvariantCulture) * POINT, //dynamic x in mm
                 float.Parse(_yJobID, CultureInfo.InvariantCulture) * POINT, //dynamic y in mm
                8f,
                0));

        DeviceRgb rgb = new DeviceRgb(0, 0, 0); //black
        Color szin = Color.ConvertRgbToCmyk(rgb);
        DeviceRgb rgbGreen = new DeviceRgb(152, 251, 152); //green
        Color szinGreen = Color.ConvertRgbToCmyk(rgbGreen);

        canvas.Add(new Paragraph($"{_jobID}_{_client}") // dynamic text that goes down not up
            .SetRotationAngle(DegreeConvertation("90"))  //rotaded paragraph.
            .SetFont(ARIAL)
            .SetFontSize(5)
            .SetFontColor(szin).SetBackgroundColor(szinGreen).SetTextAlignment(TextAlignment.LEFT));

What should I change to make the text rise up from the xy bottom left.


Solution

  • Instead of paragraph I used method ShowTextAligned.
    It shows perfect one line.

    canvas.SetFont(ARIAL).SetFontSize(5.0F).SetFontColor(szin); // font
    canvas.ShowTextAligned(
                           $"SomeText",
                           100,
                           100,
                           TextAlignment.LEFT,
                           VerticalAlignment.BOTTOM,
                           (float)Math.PI / 2
                          );
    canvas.Close();