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 8079513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:07:34+00:00 2026-06-05T16:07:34+00:00

I want to insert given text to existing pdf at X,Y location provided. I

  • 0

I want to insert given text to existing pdf at X,Y location provided.

I am using iTextSharp(4.1.6.0) for it

I am accepting the location(to insert the text at) and the value to be inserted there, in the datagridview control , The text is getting inserted at the specified position only when the location specified has no image.

The contents are not being inserted at the location which has image in the input pdf.

Is there any different way to add text to existing pdf so that the text will be inserted at the location specified irrespective of the existence of image.

Please find my code below:

for (int i = 0; i < reader.NumberOfPages; i++)
        {
            document.NewPage();

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                gridColumn = Convert.ToInt32(row.Cells[2].Value);
                if (gridColumn == i + 1)
                {
                    //document.NewPage();
                    BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                    cb.SetColorFill(iTextSharp.text.Color.BLACK);
                    cb.SetFontAndSize(bf, 8);

                    text = "" + row.Cells[3].Value;
                    cb.BeginText();
                    cb.ShowTextAligned(2, text, Convert.ToSingle(row.Cells[0].Value), Convert.ToSingle(row.Cells[1].Value), 0);
                    cb.EndText();

                    page = writer.GetImportedPage(reader, Convert.ToInt32(row.Cells[2].Value));

                    cb.AddTemplate(page, 0, 0);


                }
                else
                {
                    page = writer.GetImportedPage(reader, i + 1);
                    cb.AddTemplate(page, 0, 0);

                }

           }//end foreach

      }//end for i
  • 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-05T16:07:35+00:00Added an answer on June 5, 2026 at 4:07 pm

    I got that problem solved by using SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL) of PdfContentByte.
    I used writer.DirectContent while inserting my own text on the PDF otherwise I used writer.DirectContentUnder

    Find My modified Code below:

    for (int i = 0; i < reader.NumberOfPages; i++)
    {
         document.NewPage();
         log.Debug("Creating new page in the document..");
         bool wasPageImported = false;
    
         foreach (DataGridViewRow row in dataGridView1.Rows)
         {
               gridColumn = Convert.ToInt32(row.Cells[2].Value);
               if (gridColumn == i + 1)
               {
                   //DirectContent for writing text to PDF
                    PdfContentByte cb = writer.DirectContent;
    
                    if (!wasPageImported)
                   {
                        page = writer.GetImportedPage(reader,       Convert.ToInt32(row.Cells[2].Value));
                        cb.AddTemplate(page, 0, 0);
                        wasPageImported = true;
                    }
                        BaseFont bf = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
                 //The text rendering mode causes entered text to appear above backround
                                     cb.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
    
                   cb.SetColorFill(iTextSharp.text.Color.BLACK);
                   int fontSize = -1;
                   if (row.Cells[4].Value.ToString() == "" || row.Cells[4].Value == null)
                   {
                       fontSize = 12;
                   }
                   else
                  {
                       fontSize = Convert.ToInt32(row.Cells[4].Value);
                   }
    
                   cb.SetFontAndSize(bf, fontSize);
    
                   text = "" + row.Cells[3].Value;
                   cb.BeginText();
                   cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, text, Convert.ToSingle(row.Cells[0].Value), Convert.ToSingle(row.Cells[1].Value), 0);
                   cb.EndText();
    
             }
            else
           {
                //DirectContentUnder if not writing any text to PDF
                  PdfContentByte cb = writer.DirectContentUnder;
                  page = writer.GetImportedPage(reader, i + 1);
                  cb.AddTemplate(page, 0, 0);
            }
    
     }//end foreach
    
    }//end for int i
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to insert the value returning from mapView.userLocation.location.coordinate.longitude into my sqlite3 database. I
I want to insert the following include tag into my webpage using JavaScript. <!--#include
I want to check the given value present in a dataset column. I was
Basically, I want to insert if a given entry (by its primary key id)
I want insert a custom snippet into an XML file from code within an
I want to insert a record into a MySQL database table from a formulaire.
I want to insert a date record to an Access database. Here is my
I want to insert widgets into my ItemsControl and make them resizeable. How do
i want to insert all processes that running into listbox, and also how to
I want to insert some items to mysql db. When I did it in

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.