0

I am working with PdfBox. I have a very long string, i want to write that string to Pdf file. I want to check if the length of the string is greater than page width.

PDPage page = new PDPage();
page.setMediaBox(PDPage.PAGE_SIZE_A4);
PDSimpleFont font = PDType1Font.HELVETICA;
float titleWidth = (font.getStringWidth(pdfLine) ) / 1000 * fontSize;
int width = PDPage.PAGE_SIZE_A4.getWidth();

if(titleWidth > width)
{
 //do something
}

The problem that I am getting is that the width is not correct. When I get the width I divide the string into parts of that length so that it is within the page width. I guess I need to convert the width of the text into the length of the Java string that the page can hold. But I don't know how to do it.

4

0 回答 0