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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:31:45+00:00 2026-05-25T23:31:45+00:00

Currently, I have a controller action that outputs a PDF (as a Response.OutputStream.Write() )

  • 0

Currently, I have a controller action that outputs a PDF (as a Response.OutputStream.Write()) and this is working just as it should.

However, I am interested in outputting another script section along with the PDF to “automatically print” (or simply perform a window.print();) on the PDF.

Is this possible, or is there another method to solve this issue that I may not be aware of?

Controller Action:

public ActionResult PrintPDF(string ID)
{
     //Population of Model

     //Output Result
     return PdfResult(model);
}

PDF Result:

var buffer = byteArrayStream.toByteArray();
response.OutputStream.Write(buffer, 0, buffer.Length);

//Is it possible to output something like the following:
response.Output.Write("<script type='text/javascript'>window.print();</script>");
  • 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-25T23:31:46+00:00Added an answer on May 25, 2026 at 11:31 pm

    You will most likely not be able to mix PDF-data with JavaScript, so what you need to is embed the PDF-file using the <embed>-tag and then use javascript to print whatever is inside the <embed>-tag.

    Here’s some information that someone else got working. Basicly this is the code that is outputted (from the previous source but edited a little bit):

    <html>
        <body>
            <embed id="pdfToPrint" src ="@ViewData.PDFUrl" width="550" height="550"
            name="whatever">
            <script>
                var x = document.getElementById("pdfToPrint");
                x.click();
                x.setActive();
                x.focus();
                x.print();              
            </script>
        </body>
    
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I have URLs that look like this: http://www.example.com/user/create http://www.example.com/user/edit/1 But now, I have
I have a controller action that is receiving a complex object via JSON. The
I have an Ajax form that sends input data to a controller. I currently
I'm currently working on a custom module in which I have a controller extending
I have a controller action in my project that has a situation where it
I have a controller action that aggregates data from multiple sources: web service, database,
I currently have a login link on my application that looks something like this:
I currently have this: Hotels Controller class HotelsController extends AppController { var $name =
I have a simple MVC3 Controller Action like this [HttpGet] [OutputCache(Duration = 1200,Location=System.Web.UI.OutputCacheLocation.Server)] public
I have currently the following routes: routes.IgnoreRoute({resource}.axd/{*pathInfo}); routes.IgnoreRoute({resource}.gif/{*pathInfo}); MvcRoute.MappUrl({controller}/{action}/{ID}) .WithDefaults(new { controller = home,

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.