As per below link, I followed to call local hosted Website for converting content to PDF, but it failed. I am using Visual studio 2012, .NET 4.5 and added aspose through NuGet. I believe, the version is the latest one.
and throwing error
Input stream for html data must be FileStream
Below is the code I used.
WebRequest request = WebRequest.Create(“[http://localhost](http://localhost/):XXXXX/WebSite1/XXX.html”);
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();
MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(responseFromServer));
HtmlLoadOptions options = new HtmlLoadOptions(“[http://localhost](http://localhost/):XXXX/WebSite1/XXX.html/”);
//options…ExternalResourcesCredentials = CredentialCache.DefaultCredentials;
// load HTML file
Document pdfDocument = new Document(stream, options);
// save resultant file
pdfDocument.Save(“XXXXXXX/resultant.pdf”);
I have tested the scenario using above shared code snippet where I have tired converting google.com page to PDF format and I am unable to notice any exception when referencing Aspose.Pdf.dll version 17.4.0 through NuGet.
Can you please share a sample project, which can help us in replicating the issue in our environment. We are sorry for this inconvenience.
[C#]
System.Net.WebRequest request = System.Net.WebRequest.Create("https://www.google.com.pk/?gws_rd=cr&ei=Y6LvWKOvB8u7aruKr7AL");
// If required by the server, set the credentials.
request.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Get the response.
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();
MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(responseFromServer));
HtmlLoadOptions options = new HtmlLoadOptions("https://www.google.com.pk/?gws_rd=cr&ei=Y6LvWKOvB8u7aruKr7AL");
//options..ExternalResourcesCredentials = CredentialCache.DefaultCredentials;
// load HTML file
Document pdfDocument = new Document(stream, options);
// save resultant file
pdfDocument.Save("c:/pdftest/WebPage.pdf");
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.