0

I try reading a text file and then generate a pdf from the text but the resulting PDF does not contain all the text. Sample generated PDF

Here is a snippet of my code:

PDDocument document = new PDDocument();

PDPage page = new PDPage();
document.addPage(page);

PDPageContentStream contentStream = new PDPageContentStream(document,page);
contentStream.beginText();
contentStream.setFont(PDType1Font.HELVETICA, 14);
contentStream.newLineAtOffset(25, 700);
contentStream.setLeading(18f);

while ((line = reader.readLine()) != null) {
    contentStream.showText(line);
    contentStream.newLine();
}

contentStream.endText();
contentStream.close();

document.save(targetPath);
document.close();
mkl
  • 90,588
  • 15
  • 125
  • 265
Lez
  • 161
  • 1
  • 1
  • 13
  • Or look at the source code of the TextToPDF command line tool. (In the source code download or online at https://svn.apache.org/viewvc/pdfbox/branches/2.0/tools/src/main/java/org/apache/pdfbox/tools/TextToPDF.java?view=markup ). That one does wrap and supports proportional fonts. – Tilman Hausherr Dec 03 '18 at 18:03
  • Hm, my closing add duplicate appears to have removed the first comment which pointed to yet another possible duplicate. Sorry. – mkl Dec 03 '18 at 19:03

0 Answers0