views:

91

answers:

2

I've developed a print mechanism for an intranet application running over HTTPS. Using javascript and jQuery I create an iframe in the page and populate it with all the dynamic data that should be printed.

The iframe has a source of /MyController/Print which just returns a blank dummy page. This is then replaced with the dynamic content. I do this to avoid having the page location be "about:blank" on the print outs and to get a popup about some secure content, some insecure content.

This works great locally, but once it's on the https server I get a domain authentication popup when trying to create the iframe. It's asking for my username and password (even though the main application never does --- it uses the internal network to identify users).

Is there some way to suppress the user/pass popup?

A: 

Using iframe in this kind of situation usually creates x domain security issues.

This issues are happening according to Same Origin Policy

Therefore the recommended workaround for this matter would be for you to use

<style media="print">
   css properties to modify the page for print
</style>
XGreen
Thanks... that's what I was trying to avoid. My other option is to define the src as "javascript:false;" and that works. I was just hoping to use a friendlier URL in the printout. Any other ideas?
macca1
While this technically doesn't answer the question, I'm gonna go with "there is no definite answer on this". Furthermore, your response kind of inspired me to code the printing functionality a different way which did include a CSS for print. So even though I couldn't get it working 100% exactly like I wanted, this was good. Thanks!
macca1
A: 

this is actually from another post but i really like the solution.

you can set your action controller to compose your printable data as pdf

public FileStreamResult Print(int id)


{
     var model = _CustomRepository.Get(id);
     this.ConvertToPDF = true;
     return View( "HtmlView" );
 }

 public override OnResultExecuting( ResultExecutingContext context )
 {
      if (this.ConvertToPDF)
      {
          this.PDFStream = new MemoryStream();
          context.HttpContext.Response.Filter = new PDFStreamFilter( this.PDFStream );
      }
 }

 public override OnResultExecuted( ResultExecutedContext context )
 {
      if (this.ConvertToPDF)
      {
          context.HttpContext.Response.Clear();
          this.PDFStream.Seek( 0, SeekOrigin.Begin );
          Stream byteStream = _PrintService.PrintToPDF( this.PDFStream );
          StreamReader reader = new StreamReader( byteStream );
          context.HttpContext.Response.AddHeader( "content-dispostion",
                 "attachemnt; filename=report.pdf" );
          context.HttpContext.Response.AddHeader( "content-type",
                 "application/pdf" );
          context.HttpContext.Response.Write( reader.ReadToEnd() );
      }
}

I am assuming you are using .net mvc. I hope im not wrong

XGreen
This is really cool. While it's not applicable for what I'm doing now, I may come back to this in the future. Thanks!
macca1