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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:36:28+00:00 2026-06-17T19:36:28+00:00

This seems to be a common problem but after a lengthy search I have

  • 0

This seems to be a common problem but after a lengthy search I have yet to find a solution that fits my needs. I am using itextsharp to fill out a pdf form from which i create a byte array. (There are multiple pages of the same form with the same information that I combine into a single pdf document). I can do this without issues, the problem is when I display the final pdf document to the user I need to open it in a different window or tab WITHOUT first prompting the user to save or open the file. I also do NOT want to have to save a file on the server and reopen it using filestream. If I change the content-disposition to “inline” the pdf is displayed in the same browser window. This creates problems because the user than has to click the browser back button to navigate back to the site which restarts the form submission process. As it currently sits, my code successfully generates the pdf and prompts them to open or save it. This is the step I need to remove. I seem to remember some java snippet that opened the pdf in a new tab or window but I have been unsuccessful in replicating / finding it. I’ve also played with different headers but I’ve hit a wall. Any help would be greatly appreciated.

(I call the go method of my code below from a button click after necessary data validation.)

private void go()
    {
        List<byte[]> pdfs = new List<byte[]>();

        while (PageNumber <= Convert.ToInt32(PageCountLabel.Text))
        {
            pdfs.Add(PopulatePDF());
        }

        MemoryStream ms = MergePDFs(pdfs);
            //opens pdf in new tab after save/open option
        Response.AddHeader("Content-Disposition", "attachment; filename=TheDocument.pdf");


        Response.ContentType = "application/pdf";            
        Response.BinaryWrite(ms.ToArray());
        Response.End();                             
    }


    //************fills in pdf form****************//

    private byte[] PopulatePDF()
    {         

        MemoryStream ms = new MemoryStream();
        PdfStamper Stamper = null;            
        PdfReader Reader = new PdfReader(Server.MapPath("~/PDFTemplates/template1.pdf"));
        try
        {
            string temp = Profile.ToString().ToUpper();

            PdfCopyFields Copier = new PdfCopyFields(ms);
            Copier.AddDocument(Reader);
            Copier.Close();

            PdfReader docReader = new PdfReader(ms.ToArray());
            ms = new MemoryStream();
            Stamper = new PdfStamper(docReader, ms);
            AcroFields Fields = Stamper.AcroFields;

            //fill form fields here                                         

            PageNumber++;
            Stamper.FormFlattening = true;
        }
        finally
        {
            if (Stamper != null)
            {
                Stamper.Close();
            }
        }
        return ms.ToArray();
    }


    //combines pdf pages into single document
    private MemoryStream MergePDFs(List<byte[]> pdfs)
    {
        MemoryStream ms = new MemoryStream();
        PdfCopyFields Copier = new PdfCopyFields(ms);

        foreach (var pdf in pdfs)
            Copier.AddDocument(new PdfReader(pdf));
        Copier.Close();
        return ms;
    }
  • 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-17T19:36:30+00:00Added an answer on June 17, 2026 at 7:36 pm

    Put your PDF generation code in a new page MyPDFPage.aspx with parameters on the URL, then for example a button on your original page with an onclick event that uses window.open() from javascript:

    <html>
    <head>
    <script>
    function open_win()
    {
        window.open("MyPDFPage.aspx?fileid=0001", "_blank")
    }
    </script>
    </head>
    <body>
    
    <input type="button" value="Open Window" onclick="open_win()">
    
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like a common problem, but I'm unable find an adequate solution. I'm
It seems a very common problem. But I couldn't find any working solution. We
This seems to be a common problem, but I cant seem to fin a
I've looked around for a solution but it seems this is not a common
This seems to be primary Question. but i search it and i couldn't find
This seems like such a simple issue but I cannot find an elegant solution.
This seems like it would be a common issue to be but I don't
This seems like the simplest Git question, but I can't find ANYTHING on it.
I think this seems to be a quite common question, but since I am
This may be something common and trivial, but I seem to be having trouble

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.