|
Rank: Newbie Groups: Member
Joined: 8/24/2011 Posts: 3
|
Url converts fine on my development machine. When the site is moved to a test server, the 401 error occurs. Site on test server is using ASP.NET Impersonation and Windows Authentication.
Code to convert the url is:
PdfDocument doc = new PdfDocument(); try { // Give the pdf 0.25 inch margins. HtmlToPdf.Options.OutputArea = new RectangleF(0.25f, 0.25f, 8.0f, 10.5f); HtmlToPdf.ConvertUrl(_printUrl, doc); // Exception occurs here. } catch (Exception ex) { //Output the exception message to the PDF file in case the conversion fails. doc = new PdfDocument(); string error = string.Format("<p>Exception:</p><pre>{0}</pre>", HttpUtility.HtmlEncode(ex.ToString())); HtmlToPdf.ConvertHtml(error, doc); }
Thanks.
JohnL
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, That can be normal. The user under which the converter runs on your development machine may have sufficient rights, while the user under which the converter runs on the server may not. The easiest way to work around this issue is to use ASPXToPDF instead of ConvertUrl. ASPXToPDF is a free control that is built on top of the EO.Pdf. The key difference between ASPXToPDF and ConvertUrl is, ASPXToPDF lives "inside" the page, where ConvertUrl pulls the page from "outside". Because the control is already "inside" the page, it should not hit any security issue. You can find more information about ASPXToPDF here: http://doc.essentialobjects.com/library/4/web/aspxtopdf.aspxHope this helps. Please feel free to let us know if you have any more questions. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 8/24/2011 Posts: 3
|
Actually, I wound up using the .NET WebClient and setting it to use default credentials to get around the 401 issue and then ConvertHtml instead of ConvertUrl:
WebClient wc = new WebClient(); wc.UseDefaultCredentials = true; string resultStr = wc.DownloadString(_printUrl); // Set the base url. string[] words = Request.Url.AbsoluteUri.Replace("Downloader", "~Downloader").Split('~'); _baseUrl = words[0]; HtmlToPdf.Options.BaseUrl = _baseUrl; // Give the pdf 0.25 inch margins. HtmlToPdf.Options.OutputArea = new RectangleF(0.25f, 0.25f, 8.0f, 10.5f); //HtmlToPdf.ConvertUrl(_printUrl, doc); HtmlToPdf.ConvertHtml(resultStr, doc);
However, my issue now is that while this produces the .pdf I'm looking for locally, when I move it to the test server, the _baseUrl is not recognized and I lose my images and stylesheet styling.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
There is no reason BaseUrl would not work. It might still be permission issue because the converter will still hit 401 when it tries to pull the images. So you might want to give the images anonymous access.
Thanks
|
|
Rank: Newbie Groups: Member
Joined: 8/24/2011 Posts: 3
|
I enabled anonymous authentication on the css and image folders and that did the trick.
Thanks for your help.
For a future release, it'd be really nice if HtmlToPdf.ConvertUrl() was overloaded to allow the System.Net.CredentialCache.DefaultCredentials to be used.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Glad to hear that it's working for you. Your suggestion makes perfect sense. Thank you very much for your feedback!
|
|