0

Below is the code I am using to modify pdf metadata. The code works fine but I have one issue - instead of modifying the source file, it creates a new file in a different directory. My question is - is there a way to modify source document instead of creating a new document with necessary changes?

If File.Exists(strSource) Then 

       Dim pdfFileReader As New PdfReader(strSource) 

        psStamp = New PdfStamper(pdfFileReader, New FileStream(strDest, FileMode.Create))
        Dim inf As New SortedDictionary(Of String, String)(StringComparer.Ordinal)
        inf.Add("Title", "Modifying metadata")
        inf.Add("Company", "My Company")
        inf.Add("Author", "myself")
        psStamp.MoreInfo = inf
        psStamp.Close()

    End If

I have tried modifying the line below:

psStamp = New PdfStamper(pdfFileReader, New FileStream(strDest, FileMode.Create))

to point to the source file but then I get an error because file is in use. Can anyone help?

I'd like to modify the current document without creating a new one. One way to do that would be create a new doc in a different directory, then delete the source doc and then save the newly created doc with the old doc's name but I wanted to see if there is a more elegant solution. Would appreciate any help

Coding Duchess
  • 6,445
  • 20
  • 113
  • 209
  • possible duplicate of [Get and set metadata for itext pdf document](http://stackoverflow.com/questions/25698460/get-and-set-metadata-for-itext-pdf-document) – Morcilla de Arroz Apr 16 '15 at 21:23
  • possible duplicate of [itextsharp modify existing pdf (no new source pdf) and add watermark](http://stackoverflow.com/questions/18253707/itextsharp-modify-existing-pdf-no-new-source-pdf-and-add-watermark) – Chris Haas Apr 16 '15 at 21:43
  • This question is answered in [The Best iText Questions on StackOverflow](http://pages.itextpdf.com/ebook-stackoverflow-questions.html), a free ebook every developer using iText should read. In this book, you'll find the answer to this question: [How to update a PDF without creating a new PDF?](http://stackoverflow.com/questions/16081831/how-to-update-a-pdf-without-creating-a-new-pdf) – Bruno Lowagie Apr 17 '15 at 07:16

0 Answers0