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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:02:05+00:00 2026-05-29T04:02:05+00:00

I created a PDF document with images, I am trying to add text under

  • 0

I created a PDF document with images, I am trying to add text under each image keep in mind that the template for the page is different depending on how many images the user wants on the page. My problem is I am having problems adding and position the text.

Code for adding images:

int count = 0;

        imageStartX = (docSize.Width / 100) * marginSizeProcent;

        float imageMaxHeight = 0;
        float imageMaxWidth = 0;

        iTextSharp.text.Image image = null;

        switch (pageLayout)
        {
            case PageLayoutEnum.SingleImage:

                imageMaxWidth = docSize.Width - ((docSize.Width/100) * (2 * (float)marginSizeProcent));
                imageMaxHeight = imageStartY - ((docSize.Width/100) * (float)marginSizeProcent);


                foreach (PDFObject o in pdfObjects)
                {
                    if (count > 0)
                        AddPageWithHeader(false);

                    image = iTextSharp.text.Image.GetInstance(o.File);
                    image.ScaleToFit(imageMaxWidth, imageMaxHeight);
                    image.SetAbsolutePosition(imageStartX + (imageMaxWidth - image.ScaledWidth) / 2, imageStartY - image.ScaledHeight - (imageMaxHeight - image.ScaledHeight) / 2);

                    image.Border = Rectangle.BOX;
                    image.BorderWidth = 2f;
                    image.BorderColor = BaseColor.DARK_GRAY;

                    document.Add(image);

                    count++;
                }

                break;

            case PageLayoutEnum.TwoImages:

code for adding text:

MemoryStream memoryStream = new MemoryStream();

        PdfReader pdfReader = new PdfReader(documentStream.ToArray());
        PdfStamper stamper = new PdfStamper(pdfReader, memoryStream);

        PdfContentByte contentbyte = stamper.GetUnderContent(1);
        ColumnText dispalyIdText = new ColumnText(contentbyte);
        Paragraph idText;

        int counter = 0;

        switch (pageLayout)
        {
            case PageLayoutEnum.SingleImage:
                foreach (PDFObject item in pdfObjects)
                {
                    dispalyIdText.SetSimpleColumn(200, 200, 200, 200, 200, Element.ALIGN_LEFT);
                    idText = new Paragraph(new Chunk(item.DisplayId, FontFactory.GetFont("Arial", 20, Font.BOLD, BaseColor.RED)));
                    dispalyIdText.AddElement(idText);
                }
                break;

            case PageLayoutEnum.TwoImages:
  • 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-05-29T04:02:06+00:00Added an answer on May 29, 2026 at 4:02 am

    You don’t say what your actual problems are, only that you’re having them.

    If I were to guess, one of your problems is that text isn’t actually being displayed on your PDFs. There are three distinct reasons for this. The first is this line:

    dispalyIdText.SetSimpleColumn(200, 200, 200, 200, 200, Element.ALIGN_LEFT);
    

    The first four parameters to this method are the coordinates of the rectangle that you want to constrain your drawing to. The first parameter is the lower left x, the second is the lower left y, the third is the upper right x and the fourth is the upper right y. In your code you are saying to bind your text to a rectangle with lower left coordinates of 200,200 and upper right coordinates of 200,200. This means your rectangle has zero width and height. To fix this you need to give a rectangle that actually works. In a PDF, the lower left corner is 0,0 so to draw text in a rectangle in the lower left corner that’s 20 pixels (not actually pixels but that’s another story) high and 200 wide you’d do:

    dispalyIdText.SetSimpleColumn(0, 0, 200, 20, 200, Element.ALIGN_LEFT);
    

    Your second problem is that you are setting the leading (line-height) to 200. Depending on the object you are creating this may or may not blow text way out. You should set this to something more sane, possibly the font’s height. This doesn’t affect AddElement but it does affect SetText.

    dispalyIdText.SetSimpleColumn(0, 0, 200, 20, 12, Element.ALIGN_LEFT);
    

    The last problem is that when using ColumnText you are now in “text” mode and have to tell the system when you are ready to start processing. You do this by issuing the Go() command:

    dispalyIdText.Go();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add an image to the top of every page on
I would like to create an application that downloads a PDF document from the
I'm using html2fpdf for creating PDF documents. Now once I have created that, I
I'd like to write some (java) code that takes a PDF document, and creates
Any table I define with sidewaystable appears at the last page of created pdf
Is it possible to create a page with formatted text that is stored in
Hi I have created a PDF file with an image in it, I want
I have an Excel template that I use to create PDF specification sheets for
I have created a PNG image that is 200 DPI, and perfectly sized for
Our company using iText to stamp some watermark text (not image) on some pdf

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.