79488749

Date: 2025-03-06 09:03:11
Score: 2.5
Natty:
Report link

In general if you want to use the layout engine, easily set color borders and stuff like that you should be able to do this with the following example: https://github.com/itext/itext-java/blob/aeb7140b9e026cf949e405b1420d639c896f4618/layout/src/test/java/com/itextpdf/layout/CanvasTest.java#L254

    try (PdfDocument pdf = new PdfDocument(new PdfWriter(out))) {
        pdf.addNewPage();
        Canvas canvas = new Canvas(new PdfCanvas(pdf.getFirstPage()),
                new Rectangle(120, 650, 60, 80));

        Div notFittingDiv = new Div().setWidth(100)
                .add(new Paragraph("Paragraph in Div with Not set position"));
        canvas.add(notFittingDiv);

        Div divWithPosition = new Div().setFixedPosition(120, 300, 80);
        divWithPosition.add(new Paragraph("Paragraph in Div with set position"));
        canvas.add(divWithPosition);

        canvas.close();
    }

Results into:enter image description here

Also you can just use fixed position on the paragraph without the div. but it's nice to have a container in an absolute position and then use the layout engine to take care of the inner content in example Please let me know if this helps your usecase.

Reasons:
  • RegEx Blacklisted phrase (2.5): Please let me know
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Guust