我使用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();
答案 0 :(得分:1)
听起来你的应用程序要求你登录。因为转换为PDF步骤正在服务器上发生,服务器实际上并没有登录。而不是试图将当前的URI传递给Pechkin,你需要在本地呈现该页面并转换为该页面。
如果您想将http URL传递给pechkin,则必须无需登录即可访问,或者您必须传递足够的信息才能登录。