Okay so I figured it out. I'll post the code in case anyone else needs it, and remember this is a ColdFusion implementation :
public function resetLinks( string source, string destination) { try { // initialize objects Local.reader = createObject("java", "com.lowagie.text.pdf.PdfReader").init( arguments.source ); Local.pdfName = createObject("java", "com.lowagie.text.pdf.PdfName"); Local.annot = createObject("java", "com.lowagie.text.pdf.PdfAnnotation"); Local.out = createObject("java", "java.io.FileOutputStream").init( arguments.destination ); Local.stamper = createObject("java", "com.lowagie.text.pdf.PdfStamper").init(Local.reader, Local.out); Local.PdfAction = createObject("java", "com.lowagie.text.pdf.PdfAction"); Local.PdfRect = createObject("java", "com.lowagie.text.Rectangle"); Local.PdfBorderArray = createObject("java", "com.lowagie.text.pdf.PdfBorderArray").init(javacast("float", "0"), javacast("float", "0"), javacast("float", "0")); Local.newAnnots = []; // check each page for hyperlinks // Save the data to a structure then write it to an array // then delete the hyperlink Annotation for ( Local.i = 1; Local.i <= Local.reader.getNumberOfPages(); Local.i = Local.i + 1) { //Get all of the annotations for the current page Local.page = Local.reader.getPageN( Local.i ); Local.annotations = Local.page.getAsArray( Local.PdfName.ANNOTS ).getArrayList(); // search annotations for links for (Local.x = arrayLen(Local.annotations); !isNull( Local.annotations) && Local.x > 0; Local.x--) { // get current properties Local.current = Local.annotations[ Local.x ]; Local.dictionary = Local.reader.getPdfObject( Local.current ); Local.subType = Local.dictionary.get( Local.PdfName.SUBTYPE ); Local.action = Local.dictionary.get( Local.PdfName.A ); Local.hasLink = true; //Skip this item if it does not have a link AND action if (Local.subType != Local.PdfName.LINK || isNull(Local.action)) { Local.hasLink = false; } //Skip this item if it does not have a URI if ( Local.hasLink && Local.action.get( Local.PdfName.S ) != Local.PdfName.URI ) { Local.hasLink = false; } //If it is a valid URI, update link if (Local.hasLink) { // extract file name from URL Local.oldLink = Local.action.get( Local.pdfName.URI ); Local.newLink = getFileFromPath( Local.oldLink ); Local.Rect = Local.dictionary.Get(PdfName.Rect); arrayStruct = StructNew(); arrayStruct.rectSTR = Local.Rect.toString(); arrayStruct.link = Local.newLink; arrayStruct.page = Local.i; ArrayAppend(Local.newAnnots, arrayStruct); // Delete Local.annotations.remove(Local.current); } } } // Now really remove them! Local.reader.RemoveUnusedObjects(); // Now loop over the saved annotations and put them back!! for ( Local.z = 1; Local.z <= ArrayLen(Local.newAnnots); Local.z++) { // Parse the rect we got save into an Array theRectArray = ListToArray(ReplaceNoCase(ReplaceNoCase(Local.newAnnots[z].rectSTR, "[", ""), "]", "")); // Create the GoToR action theAction = Local.PdfAction.gotoRemotePage(javacast("string", '#Local.newAnnots[z].link#'), javacast("string", '#Local.newAnnots[z].link#'), javacast("boolean", "false"), javacast("boolean", "false")); // Create the Link Annotation with the above Action and the Rect theAnnot = Local.annot.createLink(Local.stamper.getWriter(), Local.PdfRect.init(javacast("int", theRectArray[1]), javacast("int", theRectArray[2]), javacast("int", theRectArray[3]), javacast("int", theRectArray[4])), Local.annot.HIGHLIGHT_INVERT, theAction); // Remove the border the underlying underlined text will flag item as a link theAnnot.setBorder(Local.PdfBorderArray); // Add the Annotation to the Page Local.stamper.addAnnotation(theAnnot, Local.newAnnots[z].page); } } finally { // cleanup if (structKeyExists(Local, "reader")) { Local.reader.close(); } if (structKeyExists(Local, "stamper")) { Local.stamper.close(); } if (structKeyExists(Local, "out")) { Local.out.close(); } } } -- View this message in context: http://itext-general.2136553.n4.nabble.com/Converting-Annotation-Links-from-URI-links-to-GoToR-links-tp4659621p4659666.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ CenturyLink Cloud: The Leader in Enterprise Cloud Services. Learn Why More Businesses Are Choosing CenturyLink Cloud For Critical Workloads, Development Environments & Everything In Between. Get a Quote or Start a Free Trial Today. http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php