我正在使用 EVO PDF 将多个网页组合成一个 PDF。下面的代码显示了它是如何工作的......并且它可以工作。如果我用 注释掉该部分System.Web.HttpResponse
并放置Response.Write(htmlCodeToConvert);
它,它将在一个网页上显示两个网页,并且没有 PDF 下载。
我真正想做的是两者兼有——我希望显示单个组合网页,并显示 PDF 下载提示。我可以让其中一个工作,但不能同时工作。这可能吗?
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();