EVO PDF Convertor: Can you download to PDF AND open the web page?

523 views Asked by At

I am using EVO PDF to combine multiple web pages into a single PDF. The code below shows how it works...and it works. If I comment out the section with System.Web.HttpResponse and just put Response.Write(htmlCodeToConvert); it will show both web pages on a single web page and there is no PDF download.

What I really want to do is both - I want to have the single, combined web page appear, and have the PDF download prompt appear as well. I can get one or the other to work, but not both at the same time. Is this possible?

  StringWriter htmlStringWriter = new StringWriter();

  Server.Execute("Page1.aspx", htmlStringWriter);
  Server.Execute("Page2.aspx", htmlStringWriter);

  string htmlCodeToConvert = htmlStringWriter.GetStringBuilder().ToString();
  htmlStringWriter.Close();

  // get the pdf bytes from html string
  byte[] pdfBytes = pdfConverter.GetPdfBytesFromHtmlString(htmlCodeToConvert);

  // send the PDF document as a response to the browser for download
  System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
  response.Clear();
  response.AddHeader("Content-Type", "application/pdf");
  response.AddHeader("Content-Disposition", String.Format("attachment; filename=MyFile.pdf; size={0}", pdfBytes.Length.ToString()));
  response.BinaryWrite(pdfBytes);
  response.End();
1

There are 1 answers

1
lavrik On BEST ANSWER

Can you initially open the only page with content, let it be page1.aspx, without download? And when it's loaded, start download with javascript like window.open("page2.aspx");