I’m trying to batch update all of the T
attributes in a PDF.
I have written the following scala script which runs to completion, but cmp shows that the output PDF is identical to the input PDF.
def run (infile: File): Unit = {
PDFNet.initialize();
var doc = new PDFDoc(“input.pdf”)
var iter = doc.fdfExtract().getFieldIterator
while (iter.hasNext) {
var obj = iter.next.findAttribute(“T”)
if (obj != null && obj.isString() && obj.getAsPDFText()) {
obj.setString(“newtitle”);
}
}
doc.save(new FileOutputStream(“output.pdf”), SDFDoc.SaveMode.INCREMENTAL, null);
}
Viewing the pdf in vim demonstrates that the T
attributes are indeed unchanged:
12 0 obj
<<
/AP <<
/N 553 0 R
/F 4
/FT /Tx
/MK <<
/P 541 0 R
/Rect [
490.54
735.856
554.14
746.416
]
/Subtype /Widget
/T (original value)
/Type /Annot
endobj
What am I doing wrong?