Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9240305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:09:58+00:00 2026-06-18T08:09:58+00:00

I want to add a text to an existing PDF file using iTextSharp, I

  • 0

I want to add a text to an existing PDF file using iTextSharp, I found different ways but in all of them the writer and reader are separate pdf files.
I want a way so I can open a pdf then write different things in different positions.
right now I have this code, but it makes a new file.

using (FileStream stream1 = File.Open(path, FileMode.OpenOrCreate))
      {
      BaseFont bf = BaseFont.CreateFont(fontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
      PdfReader reader = new PdfReader("C:\\26178DATA\\pdf\\holding.pdf");
      var pageSize = reader.GetPageSize(1);
      PdfStamper stamper = new PdfStamper(reader, stream1);
      iTextSharp.text.Font tmpFont = new iTextSharp.text.Font(bf, fontSize);
      PdfContentByte canvas = stamper.GetOverContent(1);
      Phrase ph = new Phrase(words[1], tmpFont);
      ph.Font = tmpFont;
      canvas.SetFontAndSize(bf, fontSize);
      ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, ph, iTextSharp.text.Utilities.MillimetersToPoints(x * 10), pageSize.GetTop(iTextSharp.text.Utilities.MillimetersToPoints(y * 10)), 0);
      stamper.Close();
            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:09:59+00:00Added an answer on June 18, 2026 at 8:09 am

    You want to add a text to an existing PDF file using iTextSharp, found different ways but in all of them the writer and reader are separate pdf files.

    As the normal way in which iText(Sharp) manipulates a PDF using a PdfStamper, can involve major reorganization of existing PDF elements, iText does not edit a file in place. The other way, using append mode, would allow for editing in place; but such an option is not implemented. A big draw-back of in-place editing is that in case of some program failure, the file in question might remain in an intermediary, unusable state.

    That being said, you can save the new file to the path of the original file by first reading the file into memory completely and then starting to create the output with the same path. In case of your sample code that would imply at least moving the PdfReader constructor use before the creation of the output stream:

    PdfReader reader = new PdfReader(path);
    using (FileStream stream1 = File.Open(path, FileMode.OpenOrCreate))
    {
        BaseFont bf = BaseFont.CreateFont(fontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        ...
    

    Alternatively you could create the result file in memory, i.e. in a MemoryStream instead of a FileStream, and, when finished, write the contents of the memory stream to your source file path.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add a text on an existing PDF using Rails, so I
I have a question to add text in a existing pdf with itextsharp. I
I'm using iTextSharp to load an existing PDF and adding text using the PdfStamper.
The title sums it all. I want to add a text to an existing
I want to add text from my database to a UIWebView, but I have
I am using MenuBar from GWT showcase. I want to add text in the
I want to use echo to add data into a text file progressively. I
Possible Duplicate: How to append text to an existing file in Java I want
I want to add our company's copyright information to all of our EXISTING source
I'm using the nested_form_for in the usual way but I want to add dynamic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.