pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gabsaga Tata" <gabsaga.t...@simpaq.com>
Subject Line Break in Page
Date Thu, 30 Jun 2011 14:52:49 GMT
I am trying to create a new PDF document and will like to add line breaks at certain points
in the document. I've looked at the documentation and examples and not sure on how to proceed.
Below is the code. I will like each text string the array to be on a new line in the same
page. I'll greatly appreciate your help.

Thanks.

Gabsaga



String[] messageTokens = new String[3]; 
messageTokens[0] = "This is message 1 on line 1";
messageTokens[1] = "This is message 2 on line 2";
messageTokens[2] = "This is message 3 on line 3";

PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
PDFont font = PDType1Font.HELVETICA_BOLD;
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.beginText();
contentStream.setFont(font, 12);

contentStream.moveTextPositionByAmount(100, 700);
for (String message : messageTokens) {
 contentStream.drawString(message);
}

contentStream.endText();

contentStream.close();
document.save( "Test_Doc.pdf");
document.close();



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message