I was able to get it to work. I just have to fine tune where the text goes. 
Here's my solution for anyone needing help in the future.
Thank you for your help!
If you have a moment, please let me know if there's a more efficient way to do 
it.

`@SpringBootApplication
public class Pdfbox1Application {

        public static void main(String[] args) throws IOException {
                SpringApplication.run(Pdfbox1Application.class, args);
                
                File file = new File("./i-90.pdf");
                
                PDDocument document = null;
                PDDocument doc = document .load(file);
                PDPage page = doc.getPage(1);
                PDPageContentStream.AppendMode appendContent;
                PDPageContentStream contentStream = new 
PDPageContentStream(doc, page, true, true);
                                
                doc.setAllSecurityToBeRemoved(true);
                
                
                
                try {
                        contentStream.beginText();
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                
                try {
                        contentStream.setFont(PDType1Font.TIMES_ROMAN, 12);
                        contentStream.newLineAtOffset(25, 700);
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                
                String text = "This is sample text";
                
                
                
//              try {
//                      contentStream = new PDPageContentStream(doc, page);
//              } catch (IOException e) {
//                      // TODO Auto-generated catch block
//                      e.printStackTrace();
//              }
                
                
                
                
                
                try {
                        contentStream.showText(text);
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                
                try {
                        contentStream.endText();
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                
                System.out.println("content added");
                
                try {
                        contentStream.close();
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                
                try {
                        doc.save("./newi-90.pdf");
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                
                
                
                try {
                        doc.close();
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }
}
`

On 2018/05/16 22:44:49, A Brand <[email protected]> wrote: 
> I'd like to add text to an existing pdf document. I attempted it and the
> current page was erased and replaced with the text I wanted to add.
> I tried using the Overlay() and didn't see the text added.
> 
> Is this a feature of pdfbox?
> 
> Onward.
> Don't Be Good. Be Great. Be Grateful.
> 
> Please note this message was edited for brevity and clarity.
> 
> Best regards,
> Anthony McDonald
> 
> 
> *602-456-9335*
> http://www.idnkhtw.space
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to