-1

When I'm appending the text in pdf using pdfbox is working fine but the problem is that text append inversely.

Example:

I'm adding some text in (x,y)=(0,0) The text added in last of the page. The text should be added in the first of the page.

PDDocument pDDocument = PDDocument.load(new java.io.File(filePath));
PDPage page = new PDPage();
page = pDDocument.getPages().get(0);
PDPageContentStream pDPageContentStream = new PDPageContentStream(pDDocument,page,PDPageContentStream.AppendMode.APPEND,true,true);
pDPageContentStream.setFont(org.apache.pdfbox.pdmodel.font.PDType1Font.TIMES_BOLD_ITALIC, 12);
pDPageContentStream.beginText();
pDPageContentStream.newLineAtOffset(0, 0);
pDPageContentStream.showText("Welcome!");
pDPageContentStream.endText();
pDPageContentStream.close();
pDDocument.save(newFilePath);
pDDocument.close();

When I'm set the position of the newLineAtOffset(0,0). Expected result, text should be added in the first of the page.

2
  • 1
    (0,0) means the bottom left in PDF coordinates. When you wrote "first" did you mean "top of page"? Commented Sep 9, 2019 at 12:02
  • 1
    What do you mean by "last of the page" and "first of the page"? If you mean "bottom" and "top" respectively, please be aware that the pdf coordinates system has the y increasing upwards and usually (by far not always!) the coordinate system origin in the lower left corner. Thus, your expected result of writing at the top for coordinates 0,0 is unrealistic or at least requires your code to first transform coordinates.
    – mkl
    Commented Sep 9, 2019 at 12:02

0

Browse other questions tagged or ask your own question.