How to change the author name for comments?

Does anyone have a script which will change the name of the author whenever any markup such as underlining, highlighting, etc, is applied? You can do this manually through the properties box, but thi

Does anyone have a script which will change the name of the author whenever any markup such as underlining, highlighting, etc, is applied? You can do this manually through the properties box, but this is time consuming and difficult.

Posted on LinkedIn on Mar 19, 2015 by Paul Tredoux

Take a look at the code below. We take a PDF with annotations created by "iText" and turn it into a PDF with annotations created by "Bruno Lowagie".

The code is really simple: we loop over the annotations of a page and change the title (if it equals to "iText"). We use PdfDocument to persist the changed PDF.

public void manipulatePdf(String src, String dest) throws IOException {
    PdfDocument pdfDoc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
    List annots = pdfDoc.getFirstPage().getAnnotations();
    if (annots != null) {
        for (PdfAnnotation a : annots) {
            if (a.getTitle() != null && a.getTitle().toString().equals("iText"))
                a.setTitle(new PdfString("Bruno Lowagie"));
        }
    }
    pdfDoc.close();
}

Click this link if you want to see how to answer this question in iText 5.



Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now