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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:20:37+00:00 2026-05-29T15:20:37+00:00

I have to add text to pdf documents where there are many scanned pdf

  • 0

I have to add text to pdf documents where there are many scanned pdf documents so the inserted text is inserted back to the scanned image and not over the image. how to add text over the scanned image inside the pdf.

package editExistingPDF;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

import org.apache.commons.io.FilenameUtils;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfWriter;

public class AddPragraphToPdf {



    public static void main(String[] args) throws IOException, DocumentException, BiffException {

        String tan = "no tan";
        File inputWorkbook = new File("lars.xls");
        Workbook w;

            w = Workbook.getWorkbook(inputWorkbook);
            // Get the first sheet
            Sheet sheet = w.getSheet(0);

            Cell[] tnas =sheet.getColumn(0);


        File ArticleFolder = new File("C:\\Documents and Settings\\sathishkumarkk\\My Documents\\article");
        File[] listOfArticles = ArticleFolder.listFiles();

        for (int ArticleInList = 0; ArticleInList < listOfArticles.length; ArticleInList++)  
        { 
            Document document = new Document(PageSize.A4);

      //  System.out.println(listOfArticles[ArticleInList].toString());
        PdfReader pdfArticle = new PdfReader(listOfArticles[ArticleInList].toString());
        if(listOfArticles[ArticleInList].getName().contains(".si."))
        {continue;}
        int noPgs=pdfArticle.getNumberOfPages();
        String ArticleNoWithOutExt = FilenameUtils.removeExtension(listOfArticles[ArticleInList].getName());
        String TanNo=ArticleNoWithOutExt.substring(0,ArticleNoWithOutExt.indexOf('.'));

     // Create output PDF
        PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream("C:\\Documents and Settings\\sathishkumarkk\\My Documents\\toPrint\\"+ArticleNoWithOutExt+".pdf"));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        //get tan form excel sheet
        System.out.println(TanNo);
        for(Cell content : tnas){
            if(content.getContents().contains(TanNo)){
                tan=content.getContents();
                System.out.println(tan);
            }else{
                continue;
            }
        }
        // Load existing PDF
        //PdfReader reader = new PdfReader(new FileInputStream("1.pdf"));

          for (int i = 1; i <= noPgs; i++) {
        PdfImportedPage page = writer.getImportedPage(pdfArticle, i); 

        // Copy first page of existing PDF into output PDF
        document.newPage();
        cb.addTemplate(page, 0, 0);
        // Add your TAN here
        Paragraph p= new Paragraph(tan);
        Font font = new Font();
        font.setSize(1.0f);
        p.setLeading(12.0f, 1.0f);
        p.setFont(font);

        document.add(p); 
          }
        document.close();
        }
    }

}

NOTE: The problem is that when there is a pdf create with only text I have no problem but when a pdf is with full of scanned document and when I try to add text; it gets added to the back of the scanned document. so while I print those pdf I will not get those text I added.

  • 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-29T15:20:39+00:00Added an answer on May 29, 2026 at 3:20 pm

    From this iText Example (which is the reverse of what you want, but switch getUnderContent with getOverContent and you’ll be fine) :

    Blockquote
    Each PDF page has two extra layers; one that sits on top of all text / graphics and one that goes to the bottom. All user added content gets in-between these two. If we get into this bottommost content, we can write anything under that we want. To get into this bottommost layer, we can use the ” getUnderContent” method of PdfStamper object.
    This is documented in iText API Reference as shown below:

    public PdfContentByte getUnderContent(int pageNum)
        Gets a PdfContentByte to write under the page of the original document.
        Parameters:
           pageNum - the page number where the extra content is written
        Returns:
             a PdfContentByte to write under the page of the original document
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If i have made rectangle then it is possible to add any text inside/onto
I want to add text from my database to a UIWebView, but I have
I have a problem with WPF Toolkit Chart Control. I can't add text values
If I have an empty tag: <tag/> How can I add text so that
I have these Views on which I add UILabels as text, The Views can
Can i add two header text in Datagrid? My Requirement is to have two
I have a System.Windows.Forms.Button control, and I want to add a hover-text explanation of
i have form where i have text box value and link (add). when user
We have an application that allows users to add/edit/replace/delete content (text, images, swfs, mp3s,
So I have a text box, where I add an onchange event of markAsException.

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.