Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Dec 19, 2024 4:17 pm

Spire.PDF for java v. 10.10.7 - springboot app
this code:

Code: Select all
// Layout the text
    PdfStringLayouter textLayouter = new PdfStringLayouter();
    PdfStringLayoutResult result = textLayouter.layout(getText(), // The text to be laid out
        font, // The font to be used
        format, // The formatting to be applied
        pageSize // Constrain to page width
    );

    // Loop through each line of the laid-out text
    for (LineInfo line : result.getLines()) {
      // Draw each line of text
      wrapper.getPage((float) font.measureString(line.getText()).getHeight()).getCanvas()
          .drawString(line.getText(), // Text of the line
              font, // Font to use
              brush, // Brush for drawing
              getX(wrapper.getPage()), wrapper.getY(), // x, y position
              format, // Formatting
              true);
      if (line.getText().contains(FormUtils.INPUT_BOX_PLACEHOLDER)) {
        FormUtils.addInlineInputBox(line.getText(), wrapper);
      }
      // Update y-coordinate for the next line
      wrapper.incrementY(font.getSize() * PdfConfig.BODY_LINE_SPACING);
    }


wrapper is a my utility class to hold the document.

when the text contain html tag (like in my case the <b>), the lines are break in the wrong way.

For example, a text block like: "<b>This is an example of a very long text just to show you the problem</b>: and the phrase continues without the bold"
is break into lines:

<b>This is an example of a very long text just to show you the
problem</b>: and the phrase continues without the bold

so I loose the bold formatting.

donspa72
 
Posts: 7
Joined: Wed Dec 11, 2024 1:30 pm

Fri Dec 20, 2024 3:42 am

Hello,

Thank you for your inquiry.

We apologize that the PdfTextWidget method you are using to draw content does not yet support HTML-formatted text. I have logged this request in our product upgrade system, and we will work on implementing it. The tracking number for this task is SPIREPDF-7290.

For now, please use the page.getCanvas().drawString(text, font, brush, point, true); method as a temporary workaround, ensuring that the last parameter is set to true.

Once SPIREPDF-7290 is completed, we will provide you with a new version.

If you have any questions, please let us know.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3043
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF

cron