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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:00:54+00:00 2026-05-27T05:00:54+00:00

Hi I have a pdf I created using itextsharp. Using pdfreader I am reading

  • 0

Hi I have a pdf I created using itextsharp.

Using pdfreader I am reading the created pdf into a pdfstamper.

Now I am trying to use the pdfstamper to add a black rectangle the size of the page on all pages. How do i do this?

Also I cannot use document to add the rectangle because the stream is close!

    MemoryStream stream = new MemoryStream();

    PdfReader pdfReader = new PdfReader(output.ToArray());
    PdfStamper stamper = new PdfStamper(pdfReader, stream);

    for (int x = 0; x < stamper.Reader.NumberOfPages; x++)
    {
        Rectangle rectangle = document.PageSize;
        rectangle.BackgroundColor = new BaseColor(0, 0, 0);
        //stamper.Writer.AcroForm.
        //document.Add(rectangle);
    }

    output.Close();
    pdfReader.Close();
    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-05-27T05:00:54+00:00Added an answer on May 27, 2026 at 5:00 am

    If you want to draw using the PdfStamper then you need to use the PdfContentByte which you can get by calling stamper.GetOverContent(pageNum). There’s a specific command on that object called Rectangle which does exactly what you want it to do. Also, remember that pages within a PDF start numbering at one and not zero.

    Below is a full working C# 2010 WinForm app targeting iTextSharp 5.1.1.0 that should do what you’re looking for, I think. You’ll need to modify it to support the MemoryStream but that should be pretty easy.

    using System;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using iTextSharp.text;
    using iTextSharp.text.pdf;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                string inputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "input.pdf");
                string outputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "output.pdf");
    
                PdfReader pdfReader = new PdfReader(inputFile);
                using (FileStream fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    using (PdfStamper stamper = new PdfStamper(pdfReader, fs))
                    {
                        int PageCount = pdfReader.NumberOfPages;
                        for (int x = 1; x <= PageCount; x++)
                        {
                            PdfContentByte cb = stamper.GetOverContent(x);
                            iTextSharp.text.Rectangle rectangle = pdfReader.GetPageSizeWithRotation(x);
                            rectangle.BackgroundColor = BaseColor.BLACK;
                            cb.Rectangle(rectangle);
                        }
                    }
                }
    
                this.Close();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using html2fpdf for creating PDF documents. Now once I have created that, I
I have a PDF created in memory using iTextSharp and contained in a MemoryStream.
I have generated a pdf using iTextSharp, when its created it saves automatically in
I have created this report using BIRT and phpjavabridge <?php header(Content-type: application/pdf); header(Content-Disposition: inline;
I have created a pdf version of our rails application using the Prawn plugin,
i have saved the pdf file to the database using file upload . now
I have a SQLite database that is created by reading some data in PDF
I am using iTextSharp to generate pdf in my .net application. Now I want
I have created a pdf document using Adobe LiveCycle. The problem I am facing
A have created a pdf file from an .aspx page using the wkhtmltopdf converter.

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.