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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:38:09+00:00 2026-06-09T13:38:09+00:00

I have a PDF file which I need to insert an image on the

  • 0

I have a PDF file which I need to insert an image on the 1st page and then resize the original size from A4 to some other size.

I manage to add an image into the PDF but not resizing it with the following code:

        string pdfFile = @"C:\Temp\a.pdf";

        PdfReader reader = new PdfReader(pdfFile);

        PdfStamper stamper = new PdfStamper(reader, new FileStream(@"C:\Temp\out.pdf", FileMode.Create), PdfWriter.VERSION_1_5);

        PdfContentByte writer = stamper.GetOverContent(1);

        stamper.FormFlattening = true;
        stamper.SetFullCompression();

        Image topImage = Image.GetInstance(@"C:\Temp\c.jpg");
        topImage.ScalePercent(19f);
        topImage.SetAbsolutePosition(142, 700);
        writer.AddImage(topImage);

        Document myPDF = writer.PdfDocument;
        myPDF.SetPageSize(PageSize.A3);

        stamper.Close();
        stamper = null;

Is there anything wrong or missing in my code?

  • 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-09T13:38:11+00:00Added an answer on June 9, 2026 at 1:38 pm

    Below is how a PDF can be resized:

        private string PdfResize(string tmpPdfFilename, string resultRootName)
        {
            try
            {
                string newPdfFilename = resultRootName + ".pdf";
                PdfReader resizeReader = new PdfReader(tmpPdfFilename);
    
                Rectangle newRect = new Rectangle(0, 0, Convert.ToSingle(_pdfNewSizeW), Convert.ToSingle(_pdfNewSizeH));
                Document doc = new Document(newRect);
                Document.Compress = true;
    
                PdfWriter resizeWriter = PdfWriter.GetInstance(doc, new FileStream(newPdfFilename, FileMode.Create));
                doc.Open();
    
                PdfContentByte cb = resizeWriter.DirectContent;
    
                for (int pageNumber = 1; pageNumber <= resizeReader.NumberOfPages; pageNumber++)
                {
                    PdfImportedPage page = resizeWriter.GetImportedPage(resizeReader, pageNumber);
                    cb.AddTemplate(page, newRect.Width / resizeReader.GetPageSize(pageNumber).Width, 0, 0,
                                   newRect.Height / resizeReader.GetPageSize(pageNumber).Height, 0, 0);
                    doc.NewPage();
                }
    
                doc.Close();
                doc = null;
    
                return newPdfFilename;
            }
            catch (Exception exp)
            {
                return String.Empty;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some images and pdf file on my server which I use in
I have an ASP.net application which returns a binary PDF file (stored from the
I have an encrypted word/excel/pdf file locally stored which I need to preview in
I need to create a pdf file from the HTML provided from database which
I have a huge pdf file (20 mb/800 pages) which contains some information. It
I need to create a pdf file which will have series of images, where
I have some binary data in memory (which represents a PDF file). What I’d
I have an xml file which I need to visualize in a pdf file.
I have a PDF file, which contains data that we need to import into
I need to generate a PDF file with some information i get from a

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.