How to draw a string at a specific position on a pdf page in java using pdfbox?

前端 未结 2 771
执笔经年
执笔经年 2021-01-16 16:06

I have a pdf coordinate (x, y) as input . I need to draw a string at the given input coordinate[Eg :- (x,y)=(200,250)]. I am using pdfbox , When I am using the below method

2条回答
  •  逝去的感伤
    2021-01-16 16:39

    I found that this one worked for me .

    PDPageContentStream contentStream = new PDPageContentStream(document, page,true,true);
    contentStream.beginText();
    contentStream.setFont(PDType1Font.HELVETICA_BOLD, 12);
    contentStream.moveTextPositionByAmount(xindex, yindex);
    contentStream.setNonStrokingColor(color);
    contentStream.drawString(comment);                      
    contentStream.endText();
    

提交回复
热议问题