我使用 Pechkin 将我的页面转换为 pdf,每次尝试转换时,生成的页面始终是登录页面。但是,当我直接打开页面时,它会正常打开。这是我用来转换为pdf的代码:
var client = new WebClient();
String url = Request.Url.AbsoluteUri;
string urlMap = new Uri(HttpContext.Current.Request.Url.AbsoluteUri).OriginalString;
string urll = urlMap.Substring(0, urlMap.LastIndexOf("/"));
string urlpdf = urll+"/PrintPdf.aspx?No=" + txtNo.Text + "&VoyNo=" + txtVoyage.Text + "";
Response.Redirect(urlpdf);
var pechkin = Factory.Create(new GlobalConfig());
var pdf = pechkin.Convert(new ObjectConfig()
.SetLoadImages(true).SetZoomFactor(1.5)
.SetPrintBackground(true)
.SetScreenMediaType(true)
.SetCreateExternalLinks(true)
.SetIntelligentShrinking(true).SetCreateInternalLinks(true)
.SetPageUri(urlpdf));
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", string.Format("attachment;filename=test.pdf; size={0}", pdf.Length));
Response.BinaryWrite(pdf);
Response.Flush();
Response.End();