I am using PDFBox with the following code:
doc = new PDDocument();
page = new PDPage();
doc.addPage(page);
PDFont font = PDType1Font.COURIER;
pdftitle = new PDPageContentStream(doc, page);
pdftitle.beginText();
pdftitle.setFont( font, 12 );
pdftitle.moveTextPositionByAmount( 40, 740 );
pdftitle.drawString("Here I insert a lot of text");
pdftitle.endText();
pdftitle.close();
Does anyone know how I can wrap the text so that it automatically goes to another line?
I don’t think it is possible to wrap text automatically. But you can wrap your text yourself. See How to Insert a Linefeed with PDFBox drawString and How can I create fixed-width paragraphs with PDFbox?.