Hi All: In an ASP.NET 4 project I have a "template" pdf that I open for editing and then save with a different name. Sometimes (not always) I receive an error:
The process cannot access the file 'd:\websites\forms\pdfOutput\xxxx-xxxx.pdf' because it is being used by another process. My codeblock to handle this process is fairly straightforward: Public Shared Function makeTempID(filename As String, name As String, _ outputName As String, userID As Guid) As Boolean Dim reader As PdfReader = New PdfReader(filename) reader.RemoveUnusedObjects() Try Dim stamper As PdfStamper = New PdfStamper(reader, New FileStream(outputName, FileMode.Create)) Dim canvas As PdfContentByte = stamper.GetOverContent(1) REM: add the name ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, New Phrase(name), 414, 427, 0) REM: add the effective date/expiration date ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, New Phrase(Today.ToString("d")), 108, 367, 0) ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, New Phrase(DateAdd(DateInterval.Month, 1, Today).ToString("d")), 270, 367, 0) stamper.Close() Return True Catch ex As Exception logError("", ex.Message, "pdfGen/makeTempID/Createfile", userID) Return False End Try reader.Close() End Function The exception is not always being thrown, so I'm wondering if my code is wrong or if I should just be doing this a different way? ------------------------------------------------------------------------------ Get 100% visibility into Java/.NET code with AppDynamics Lite! It's a free troubleshooting tool designed for production. Get down to code-level detail for bottlenecks, with <2% overhead. Download for free and get started troubleshooting in minutes. http://pubads.g.doubleclick.net/gampad/clk?id=48897031&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