Rajesh J,

Rajesh J wrote
> I am getting following error when i try to stamp a footer (page x of y -
> where x = current page no & y=total no of pages) on a previously generated
> pdf using itext. Problem could be because I m trying to write to the same
> file that I am reading. But I dont know how to resolve this. I saw a
> couple of posts for the same exception. But there problem was different.
> 
>     PdfCopy copy = new PdfCopy(document1, new
> FileOutputStream(getReportLocation()));
>     document1.open();
>     PdfReader reader1 = new PdfReader(getReportLocation());

In general it is a very bad idea to use the same file name when creating
some update of a document. Thus, you should do something like

    PdfCopy copy = new PdfCopy(document1, new
FileOutputStream(getReportLocation() + ".tmp"));
    [...]
    copy.close();
    new File(getReportLocation()).delete();
    new File(getReportLocation() + ".tmp").renameTo(new
File(getReportLocation()));

assuming that getReportLocation() returns a String. Otherwise adapt
accordingly.

(Actually you should also add some tests whether delete and rename worked as
desired with some treatment in case of failure.)

If that is absolutely impossible, you might win by moving your new
PdfReader(getReportLocation()) call before the new PdfCopy(document1, new
FileOutputStream(getReportLocation())) line. As the PdfReader constructor
you chose reads all of the PDF into memory, that construction might just
work.

Regards,   Michael



--
View this message in context: 
http://itext-general.2136553.n4.nabble.com/Problem-in-stamping-Page-X-Of-Y-Footer-tp4657100p4657114.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
iText-questions mailing list
[email protected]
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

Reply via email to