Hi,
I am trying to search and replace a "Text/String" from a PDF document (created 
using Acrobat Distiller 8.1.0 (Windows)) with the help of iText code as given 
below.

PdfReader reader = new PdfReader("TestPDFDoc.pdf");
byte[] streamBytes = reader.getPageContent(1);
StringBuffer buf = new StringBuffer();          
String contentStream = new String(streamBytes);
String searchString = "Hello"; 
int pos = contentStream.indexOf(searchString);
buf.append(contentStream.substring(0, pos));
buf.append("XXXX");
buf.append(contentStream.substring(pos + searchString.length() + 1 ));
String modifiedString = buf.toString();  
PdfStamper stamper = new PdfStamper(reader, new 
FileOutputStream("c:/temp/TestOutputDoc.pdf"));
reader.setPageContent(1, modifiedString.getBytes());
stamper.close();

This code doesn't search for the given string always. Can anybody please 
suggest with an alternative to this?

Thanks in advance.
Veer


                

--
This message was sent on behalf of [EMAIL PROTECTED] at openSubscriber.com
http://www.opensubscriber.com/messages/[email protected]/topic.html

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to