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

  • Home
  • SEARCH
  • 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 6724371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:40:56+00:00 2026-05-26T09:40:56+00:00

I am trying to do something relatively simple with iTextSharp, but I always find

  • 0

I am trying to do something relatively simple with iTextSharp, but I always find it very confusing and can’t figure out this without asking for some help.

I have a situation where a third party product I use generates a PDF, but doesn’t have the option of setting initial view settings (zoom, fit to width, etc).

I have found some code that will allows me to do this in iTextSharp :-

Developer Barn

The bit I cannot work out is how to apply this to a file that already exists – this seems to be fine for any new files, or something I am creating in iTextSharp, but not an existing PDF. Is there a way of doing this, and how can it be done?

Many thanks in advance,

Adam

PS – Already found the answer to this.. StackOverflow won’t let me close my own question though? Seems a bit daft, but anyway do it like this –

        PdfReader reader = new PdfReader(new FileStream(fileName, FileMode.Open, FileAccess.Read));
        Rectangle size = reader.GetPageSizeWithRotation(1);

        using (Document document = new Document(size))
        {
            using (PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(Path.Combine(Path.GetDirectoryName(fileName), "Zoom" + Path.GetFileName(fileName)), FileMode.Create, FileAccess.ReadWrite)))
            {
                //open our document
                document.Open();

                PdfContentByte cb = writer.DirectContent;

                //this creates a new destination to send the action to when the document is opened.
                PdfDestination pdfDest = new PdfDestination(PdfDestination.FITH, reader.GetPageSize(1).Top);

                //create a new action to send the document to our new destination.
                PdfAction action = PdfAction.GotoLocalPage(1, pdfDest, writer);

                for (int pageNumber = 1; pageNumber <= reader.NumberOfPages; pageNumber++)
                {
                    //need to change page size for landscape / portrait
                    document.SetPageSize(reader.GetPageSizeWithRotation(pageNumber));

                    document.NewPage();
                    PdfImportedPage page = writer.GetImportedPage(reader, pageNumber);
                    cb.AddTemplate(page, 0, 0);
                }

                //set the page mode
                int PageMode = 0;
                PageMode += PdfWriter.PageLayoutOneColumn;


                //set the open action for our writer object
                writer.SetOpenAction(action);
                writer.ViewerPreferences = PageMode;
                writer.SetFullCompression();

                //finally, close our document
                document.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-26T09:40:56+00:00Added an answer on May 26, 2026 at 9:40 am

    I don’t think there is an edit functionnality per se, neither in iTextSharp nor in iText. I think the way to go is to open the existing document, create a new writer, copy the old document into the new writer while adding the enrichments you’d like to see and overwrite the original doc afterwards as decribed here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I'm missing something relatively simple here, but I'm trying to find a
I am trying something very simple, but for some reason it does not work.
I'm trying to do something relatively simple, spit out the column names and respective
I thought this would be a relatively simple task with something like FMOD, but
I'm trying something like this, but this example does not work. jsObj = {};
I am trying to do something I thought would be relatively simple and get
I'm trying to do something relatively simple here. Basically I have a table with
I am trying to make something relatively simple, make a wheel spin 90degrees when
I'm trying to do something I thought would be relatively simple: Upload an image
I'm trying to join two relatively simple tables together, but my query is experiencing

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.