Reputation: 11
I use Pechkin to convert my page to pdf, every time I try to convert, the page that generated is always login page. But, when I open the page directly it opened Normally. this is my code that i used to convert to 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();
Upvotes: 0
Views: 283
Reputation: 30618
It sounds like your application requires you to be logged in. Because the convert to PDF step is happening on the server, the server is not actually logged in. Rather than trying to pass the current URI to Pechkin, you will need to render that page locally and convert THAT.
If you want to pass a http URL to pechkin, then it must be accessible without logging in, or you must pass enough information for it to be able to log in.
Upvotes: 1