首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么在Asp.Net中使用pechkin将页面转换为pdf时会话结束?

为什么在Asp.Net中使用pechkin将页面转换为pdf时会话结束?
EN

Stack Overflow用户
提问于 2017-02-02 20:07:06
回答 1查看 230关注 0票数 0

我使用Pechkin将我的页面转换为pdf,每次我尝试转换时,生成的页面总是登录页面。但是,当我直接打开页面时,它会正常打开。这是我用来转换为pdf的代码:

代码语言:javascript
复制
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();
EN

回答 1

Stack Overflow用户

发布于 2017-02-02 20:09:24

听起来您的应用程序需要您登录。由于转换为PDF步骤是在服务器上进行的,因此服务器实际上并未登录。您需要在本地呈现该页面并进行转换,而不是尝试将当前URI传递给Pechkin。

如果要将http URL传递给pechkin,则必须可以在不登录的情况下访问它,或者必须传递足够的信息才能登录。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42001850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档